Mercurial > hg > Feedworm
diff backend/couchdb/CouchDbBackend.py @ 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
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 27 Aug 2011 08:52:03 +0200 |
parents | c5a427d46703 |
children | e8bb107a74e1 |
line wrap: on
line diff
--- a/backend/couchdb/CouchDbBackend.py Sat Aug 27 07:32:01 2011 +0200 +++ b/backend/couchdb/CouchDbBackend.py Sat Aug 27 08:52:03 2011 +0200 @@ -1,14 +1,14 @@ from FeedUpdater import FeedUpdater from Preferences import Preferences +from backend.AbstractBackend import AbstractBackend from backend.couchdb.Feed import Feed from backend.couchdb.FeedEntry import FeedEntry import couchdb - DATABASE = "feedtest" -class CouchDbBackend(object): +class CouchDbBackend(AbstractBackend): ''' Backend that uses CouchDB for persistence ''' @@ -20,17 +20,43 @@ def preferences(self): return Preferences(self.database) + # + # handling of feeds + # + def getFeeds(self): if self.preferences().showOnlyUnreadFeeds(): - return self._getUnreadFeeds() + self.feeds = self._getUnreadFeeds() else: # make sure that the results are actually fetched into memory, otherwise we'll pass # a ViewResults instance around which is not what we want - return list(Feed.all(self.database)) + self.feeds = list(Feed.all(self.database)) + return self.feeds def _getUnreadFeeds(self): raise Exception("not yet implemented") + def _retrieveEntriesForSelectedFeed(self, hideReadEntries): + # TODO how to hide read entries if requested? + viewResults = FeedEntry.view(self.database, "feedtest/feedEntries_by_feed", + key=self.selectedFeed.id) + return list(viewResults) + + def markSelectedFeedAsRead(self): + for feedEntry in self.entriesForSelectedFeed(): + feedEntry.markRead(self.database) + + # + # handling of the selected feed entry + # + + def _markSelectedFeedEntryRead(self): + self.selectedFeedEntry.markRead(self.database) + + def toggleSelectedFeedEntryRead(self): + self.selectedFeedEntry.toggleRead(self.database) + + def toggleRead(self, feedEntry): raise Exception("not yet implemented") @@ -52,8 +78,10 @@ viewName = "feedtest/unread_feedEntries_by_feed" return list(FeedEntry.view(self.database, viewName)) - def markFeedEntriesAsRead(self, entries): - raise Exception("not yet implemented") + def markFeedEntriesAsRead(self, indices): + for index in indices: + feedEntry = self.entriesForSelectedFeed()[index] + feedEntry.markRead(self.database) def updateAllFeeds(self): # TODO use a view instead of iterating all feeds @@ -66,6 +94,3 @@ print("Expiring feeds is not yet implemented") # raise Exception("not yet implemented") - def dispose(self): - # nothing to do here - pass