Mercurial > hg > Feedworm
annotate backend/sqlalchemy/Preferences.py @ 125:514e5d7dca98 backend
deleting a feed is now done via the backend
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Mon, 22 Aug 2011 11:22:45 +0200 |
parents | e830fa1cc7a2 |
children | bb3c851b18b1 |
rev | line source |
---|---|
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 from Preference import Preference |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 |
110
43c234c8fe87
store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
87
diff
changeset
|
4 DAYS_TO_KEEP_FEED_ENTRIES = "DAYS_TO_KEEP_FEED_ENTRIES" |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
5 HIDE_READ_ENTRIES = "HIDE_READ_FEED_ENTRIES" |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
6 PROXY_HOST = "PROXY_HOST" |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
7 PROXY_PORT = "PROXY_PORT" |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
8 SHOW_ONLY_UNREAD_FEEDS = "SHOW_ONLY_UNREAD_FEEDS" |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 START_MAXIMIZED = "START_MAXIMIZED" |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
11 def str2bool(string): |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
12 return string.lower() in ["yes", "true", "t", "1"] |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
13 |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
14 def bool2str(bool): |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
15 if bool: |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
16 return "True" |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
17 else: |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
18 return "False" |
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
19 |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 class Preferences(object): |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 def __init__(self, session): |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
22 self.session = session |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
23 self.cache = {} |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
24 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
25 def _cachedPreference(self, key, defaultValue=None, addIfMissing=True): |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
26 if self.cache.has_key(key): |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
27 return self.cache[key] |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
28 else: |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
29 pref = Preference.forKey(key, self.session) |
111
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
30 if pref is not None: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
31 self.cache[key] = pref |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
32 elif pref is None and addIfMissing: |
46
03358c113170
Better preferences handling: the GUI's responsibility is to convert the input from the event into a boolean value
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
44
diff
changeset
|
33 pref = Preference(key, str(defaultValue)) |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
34 self.session.add(pref) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
35 self.cache[key] = pref |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
36 return pref |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
37 |
120
e830fa1cc7a2
re-enabled PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
38 def commit(self): |
e830fa1cc7a2
re-enabled PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
39 self.session.commit() |
e830fa1cc7a2
re-enabled PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
40 |
e830fa1cc7a2
re-enabled PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
41 def rollback(self): |
e830fa1cc7a2
re-enabled PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
42 self.session.rollback() |
e830fa1cc7a2
re-enabled PreferencesDialog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
119
diff
changeset
|
43 |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
44 def startMaximized(self): |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
45 pref = self._cachedPreference(START_MAXIMIZED, False) |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
46 return str2bool(pref.value) |
44
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
47 |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
48 def setStartMaximized(self, flag): |
be990ac6e478
saving the preference "start maximized" from GUI implemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
43
diff
changeset
|
49 pref = self._cachedPreference(START_MAXIMIZED) |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
50 pref.value = bool2str(flag) |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
51 |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
52 def hideReadFeedEntries(self): |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
53 pref = self._cachedPreference(HIDE_READ_ENTRIES, False) |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
54 return str2bool(pref.value) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
55 |
61
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
56 def setHideReadFeedEntries(self, flag): |
db35ab7753f0
add a preference to hide read feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
46
diff
changeset
|
57 pref = self._cachedPreference(HIDE_READ_ENTRIES) |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
58 pref.value = bool2str(flag) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
59 |
72
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
60 def showOnlyUnreadFeeds(self): |
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
61 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS, False) |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
62 return str2bool(pref.value) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
63 |
72
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
64 def setShowOnlyUnreadFeeds(self, flag): |
e8c2730eb444
control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
61
diff
changeset
|
65 pref = self._cachedPreference(SHOW_ONLY_UNREAD_FEEDS) |
119
04a730f9d07d
move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
111
diff
changeset
|
66 pref.value = bool2str(flag) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
67 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
68 def proxyHost(self): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
69 pref = self._cachedPreference(PROXY_HOST) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
70 return pref.value |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
71 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
72 def setProxyHost(self, hostname): |
111
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
73 if hostname is None: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
74 pref = self._cachedPreference(PROXY_HOST, addIfMissing=False) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
75 if pref is not None: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
76 self.session.delete(pref) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
77 del(self.cache[PROXY_HOST]) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
78 else: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
79 pref = self._cachedPreference(PROXY_HOST) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
80 pref.value = str(hostname) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
81 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
82 def proxyPort(self): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
83 pref = self._cachedPreference(PROXY_PORT, 3128) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
84 return int(pref.value) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
85 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
86 def setProxyPort(self, port): |
111
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
87 if port is None: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
88 pref = self._cachedPreference(PROXY_PORT, addIfMissing=False) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
89 if pref is not None: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
90 self.session.delete(pref) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
91 del(self.cache[PROXY_PORT]) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
92 else: |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
93 pref = self._cachedPreference(PROXY_PORT) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
94 pref.value = str(port) |
87
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
95 |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
96 def isProxyConfigured(self): |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
97 pref = self._cachedPreference(PROXY_HOST, addIfMissing=False) |
b8bfd1bd6c55
use a proxy if one is configured. TODO: GUI for configuring the proxy server
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
72
diff
changeset
|
98 return pref is not None |
110
43c234c8fe87
store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
87
diff
changeset
|
99 |
43c234c8fe87
store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
87
diff
changeset
|
100 def daysToKeepFeedEntries(self): |
43c234c8fe87
store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
87
diff
changeset
|
101 pref = self._cachedPreference(DAYS_TO_KEEP_FEED_ENTRIES, 90, addIfMissing=True) |
43c234c8fe87
store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
87
diff
changeset
|
102 return int(pref.value) |
111
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
103 |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
104 def setDaysToKeepFeedEntries(self, dayString): |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
105 pref = self._cachedPreference(DAYS_TO_KEEP_FEED_ENTRIES) |
c17a224bc251
make the keep interval for feeds configurable via the GUI. Fix saving the proxy settings
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
110
diff
changeset
|
106 pref.value = dayString |