annotate backend/couchdb/Preferences.py @ 258:4ca1fac32dde

Pull the constant of days to keep feed entries into the abstract class
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 12 Mar 2019 02:39:18 +0100
parents f79be01821c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
217
bb3c851b18b1 add source file endcoding header
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 194
diff changeset
1 # -*- coding: utf-8 -*-
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
2 from ..AbstractPreferences import AbstractPreferences
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents: 158
diff changeset
3 import CouchDb
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
4
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
5 PROXY_PORT = "proxyPort"
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
7 class Preferences(AbstractPreferences):
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 def __init__(self, database):
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9 self.database = database
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
10 self._initDocument()
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
11 self.documentIsDirty = False
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
13 def _initDocument(self):
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents: 158
diff changeset
14 viewResults = self.database.view(CouchDb.preference())
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 try:
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
16 row = iter(viewResults).next()
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
17 self.document = self.database[row.id]
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 except StopIteration:
233
e34c53a3e407 fixes from eric's style check
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 217
diff changeset
19 empty = {"doctype": "preferences"}
246
7c719c4f5655 Fix all remaining code style bugs
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 233
diff changeset
20 doc_id, doc_rev = self.database.save(empty)
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
21 self.document = self.database[doc_id]
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
23 def _documentValue(self, key, defaultValue=None):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
24 if key in self.document.keys():
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
25 return self.document[key]
156
2d159eb2a91b displaying the preferences dialog works, saving prefs doesn't yet
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 146
diff changeset
26 else:
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
27 return defaultValue
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
28
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
29 def _setDocumentValue(self, key, value):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
30 self.document[key] = value
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
31 self.documentIsDirty = True
156
2d159eb2a91b displaying the preferences dialog works, saving prefs doesn't yet
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 146
diff changeset
32
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
33 def proxyHost(self):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
34 return self._documentValue(self.PROXY_HOST)
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
35
194
2c91b5653878 enable/disable using the proxy via a preference setting
dirk
parents: 172
diff changeset
36 def useProxy(self):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
37 return self._documentValue(self.USE_PROXY, True)
194
2c91b5653878 enable/disable using the proxy via a preference setting
dirk
parents: 172
diff changeset
38
2c91b5653878 enable/disable using the proxy via a preference setting
dirk
parents: 172
diff changeset
39 def setUseProxy(self, value):
2c91b5653878 enable/disable using the proxy via a preference setting
dirk
parents: 172
diff changeset
40 self._setDocumentValue(USE_PROXY, value)
2c91b5653878 enable/disable using the proxy via a preference setting
dirk
parents: 172
diff changeset
41
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
42 def setProxyHost(self, hostname):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
43 if hostname is None:
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
44 if PROXY_HOST in self.document.keys():
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
45 del self.document[PROXY_HOST]
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
46 self.documentIsDirty = True
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
47 else:
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
48 self._setDocumentValue(PROXY_HOST, hostname)
133
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
49
9e1e6b96d8b0 implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
50 def proxyPort(self):
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
51 return self._documentValue(PROXY_PORT)
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
52
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
53 def setProxyPort(self, port):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
54 if port is None:
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
55 if PROXY_PORT in self.document.keys():
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
56 del self.document[PROXY_PORT]
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
57 self.documenIsDirty = True
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
58 else:
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
59 self._setDocumentValue(PROXY_PORT, port)
146
8ec20377bcb0 move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 133
diff changeset
60
8ec20377bcb0 move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 133
diff changeset
61 def showOnlyUnreadFeeds(self):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
62 return self._documentValue(self.SHOW_ONLY_UNREAD_FEEDS, False)
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
63
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
64 def setShowOnlyUnreadFeeds(self, flag):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
65 self._setDocumentValue(self.SHOW_ONLY_UNREAD_FEEDS, flag)
146
8ec20377bcb0 move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 133
diff changeset
66
8ec20377bcb0 move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 133
diff changeset
67 def startMaximized(self):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
68 return self._documentValue(self.START_MAXIMIZED, False)
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
69
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
70 def setStartMaximized(self, flag):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
71 self._setDocumentValue(START_MAXIMIZED, flag)
146
8ec20377bcb0 move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 133
diff changeset
72
8ec20377bcb0 move getting the entries for a feed to the backend so that the couchdb backend can use a custom view for feed entries
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 133
diff changeset
73 def hideReadFeedEntries(self):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
74 return self._documentValue(self.HIDE_READ_FEED_ENTRIES, False)
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
75
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
76 def setHideReadFeedEntries(self, flag):
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 246
diff changeset
77 self._setDocumentValue(self.HIDE_READ_FEED_ENTRIES, flag)
156
2d159eb2a91b displaying the preferences dialog works, saving prefs doesn't yet
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 146
diff changeset
78
2d159eb2a91b displaying the preferences dialog works, saving prefs doesn't yet
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 146
diff changeset
79 def daysToKeepFeedEntries(self):
258
4ca1fac32dde Pull the constant of days to keep feed entries into the abstract class
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 256
diff changeset
80 value = self._documentValue(self.DAYS_TO_KEEP_FEED_ENTRIES, 90)
172
214addba1f93 always return an int value for daysToKeepFeedEntries
dirk
parents: 169
diff changeset
81 return int(value)
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
82
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
83 def setDaysToKeepFeedEntries(self, days):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
84 self._setDocumentValue(DAYS_TO_KEEP_FEED_ENTRIES, days)
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
85
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
86 def commit(self):
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
87 if self.documentIsDirty:
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
88 self.database.save(self.document)
156
2d159eb2a91b displaying the preferences dialog works, saving prefs doesn't yet
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 146
diff changeset
89
2d159eb2a91b displaying the preferences dialog works, saving prefs doesn't yet
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 146
diff changeset
90 def rollback(self):
158
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
91 if self.documentIsDirty:
e8bb107a74e1 all preferences are stored in a single JSON document in the couchdb backend. PreferencesDialog converts QString to a proper Python datatybe before sending it to the backend.
dirk
parents: 156
diff changeset
92 self._initDocument()