Mercurial > hg > Feedworm
annotate backend/couchdb/CouchDbBackend.py @ 164:3eeda7cec39b
delete a feed via the GUI works now
author | dirk |
---|---|
date | Mon, 29 Aug 2011 03:32:39 +0200 |
parents | ab2b26412b77 |
children | 04c3b9796b89 |
rev | line source |
---|---|
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
144
74217db92993
updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
139
diff
changeset
|
2 from FeedUpdater import FeedUpdater |
133
9e1e6b96d8b0
implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
132
diff
changeset
|
3 from Preferences import Preferences |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
4 from backend.AbstractBackend import AbstractBackend |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
5 from backend.couchdb.Feed import Feed |
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:
144
diff
changeset
|
6 from backend.couchdb.FeedEntry import FeedEntry |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 import couchdb |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 |
133
9e1e6b96d8b0
implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
132
diff
changeset
|
9 DATABASE = "feedtest" |
9e1e6b96d8b0
implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
132
diff
changeset
|
10 |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
11 class CouchDbBackend(AbstractBackend): |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 ''' |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 Backend that uses CouchDB for persistence |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 ''' |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 def __init__(self): |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 server = couchdb.Server() |
133
9e1e6b96d8b0
implement proxyHost/proxyPort in Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
132
diff
changeset
|
18 self.database = server[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:
155
diff
changeset
|
19 self.prefs = None |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 def preferences(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:
155
diff
changeset
|
22 if self.prefs 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:
155
diff
changeset
|
23 self.prefs = Preferences(self.database) |
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:
155
diff
changeset
|
24 return self.prefs |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
25 |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
26 # |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
27 # handling of feeds |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
28 # |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
29 |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
30 def getFeeds(self): |
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:
144
diff
changeset
|
31 if self.preferences().showOnlyUnreadFeeds(): |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
32 self.feeds = self._getUnreadFeeds() |
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:
144
diff
changeset
|
33 else: |
148
c5a427d46703
displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
146
diff
changeset
|
34 # make sure that the results are actually fetched into memory, otherwise we'll pass |
c5a427d46703
displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
146
diff
changeset
|
35 # a ViewResults instance around which is not what we want |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
36 self.feeds = list(Feed.all(self.database)) |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
37 return self.feeds |
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:
144
diff
changeset
|
38 |
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:
144
diff
changeset
|
39 def _getUnreadFeeds(self): |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
40 raise Exception("not yet implemented") |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
41 |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
42 def _retrieveEntriesForSelectedFeed(self, hideReadEntries): |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
43 # TODO how to hide read entries if requested? |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
44 viewResults = FeedEntry.view(self.database, "feedtest/feedEntries_by_feed", |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
45 key=self.selectedFeed.id) |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
46 return list(viewResults) |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
47 |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
48 def markSelectedFeedAsRead(self): |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
49 for feedEntry in self.entriesForSelectedFeed(): |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
50 feedEntry.markRead(self.database) |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
51 |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
52 # |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
53 # handling of the selected feed entry |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
54 # |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
55 |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
56 def _markSelectedFeedEntryRead(self): |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
57 self.selectedFeedEntry.markRead(self.database) |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
58 |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
59 def toggleSelectedFeedEntryRead(self): |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
60 self.selectedFeedEntry.toggleRead(self.database) |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
61 |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
62 |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
63 def toggleRead(self, feedEntry): |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
64 raise Exception("not yet implemented") |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
65 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
66 def markAllEntriesRead(self, feed): |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
67 raise Exception("not yet implemented") |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
68 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
69 def createFeed(self, url): |
161 | 70 FeedUpdater.createFeed(url, self.database) |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
71 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
72 def updateFeed(self, feed, changes): |
162 | 73 for key in changes.keys(): |
74 feed[key] = changes[key] | |
75 feed.store(self.database) | |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
76 |
164 | 77 def deleteSelectedFeed(self): |
78 viewResults = self.database.view("feedtest/feedEntries_by_feed", key=self.selectedFeed.id) | |
79 for row in viewResults: | |
80 del self.database[row.id] | |
81 del self.database[self.selectedFeed.id] | |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
82 |
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:
144
diff
changeset
|
83 def entriesForFeed(self, feed, hideReadEntries): |
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:
144
diff
changeset
|
84 viewName = "feedtest/feedEntries_by_feed" |
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:
144
diff
changeset
|
85 if hideReadEntries: |
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:
144
diff
changeset
|
86 viewName = "feedtest/unread_feedEntries_by_feed" |
148
c5a427d46703
displaying entries for a feed works now with the couchdb backend
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
146
diff
changeset
|
87 return list(FeedEntry.view(self.database, viewName)) |
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:
144
diff
changeset
|
88 |
155
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
89 def markFeedEntriesAsRead(self, indices): |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
90 for index in indices: |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
91 feedEntry = self.entriesForSelectedFeed()[index] |
a05719a6175e
move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
148
diff
changeset
|
92 feedEntry.markRead(self.database) |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
93 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
94 def updateAllFeeds(self): |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
95 # TODO use a view instead of iterating all feeds |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
96 allFeeds = Feed.all(self.database) |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
97 for feed in allFeeds: |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
98 if feed.needsUpdate(): |
144
74217db92993
updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
139
diff
changeset
|
99 FeedUpdater(feed, self.database).update() |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
100 |
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
101 def expireFeedEntries(self): |
139
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
102 print("Expiring feeds is not yet implemented") |
2cd30af937fa
add the required methods for determining if a feed needs to be updated
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
133
diff
changeset
|
103 # raise Exception("not yet implemented") |
132
63d6d60d37ff
new backend for using CouchDB as persistence mechanism ... currently all methods are unimplemented
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
104 |