Mercurial > hg > Feedworm
comparison 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 |
comparison
equal
deleted
inserted
replaced
154:2682db280be0 | 155:a05719a6175e |
---|---|
1 | 1 |
2 from FeedUpdater import FeedUpdater | 2 from FeedUpdater import FeedUpdater |
3 from Preferences import Preferences | 3 from Preferences import Preferences |
4 from backend.AbstractBackend import AbstractBackend | |
4 from backend.couchdb.Feed import Feed | 5 from backend.couchdb.Feed import Feed |
5 from backend.couchdb.FeedEntry import FeedEntry | 6 from backend.couchdb.FeedEntry import FeedEntry |
6 import couchdb | 7 import couchdb |
7 | 8 |
8 | |
9 DATABASE = "feedtest" | 9 DATABASE = "feedtest" |
10 | 10 |
11 class CouchDbBackend(object): | 11 class CouchDbBackend(AbstractBackend): |
12 ''' | 12 ''' |
13 Backend that uses CouchDB for persistence | 13 Backend that uses CouchDB for persistence |
14 ''' | 14 ''' |
15 | 15 |
16 def __init__(self): | 16 def __init__(self): |
18 self.database = server[DATABASE] | 18 self.database = server[DATABASE] |
19 | 19 |
20 def preferences(self): | 20 def preferences(self): |
21 return Preferences(self.database) | 21 return Preferences(self.database) |
22 | 22 |
23 # | |
24 # handling of feeds | |
25 # | |
26 | |
23 def getFeeds(self): | 27 def getFeeds(self): |
24 if self.preferences().showOnlyUnreadFeeds(): | 28 if self.preferences().showOnlyUnreadFeeds(): |
25 return self._getUnreadFeeds() | 29 self.feeds = self._getUnreadFeeds() |
26 else: | 30 else: |
27 # make sure that the results are actually fetched into memory, otherwise we'll pass | 31 # make sure that the results are actually fetched into memory, otherwise we'll pass |
28 # a ViewResults instance around which is not what we want | 32 # a ViewResults instance around which is not what we want |
29 return list(Feed.all(self.database)) | 33 self.feeds = list(Feed.all(self.database)) |
34 return self.feeds | |
30 | 35 |
31 def _getUnreadFeeds(self): | 36 def _getUnreadFeeds(self): |
32 raise Exception("not yet implemented") | 37 raise Exception("not yet implemented") |
38 | |
39 def _retrieveEntriesForSelectedFeed(self, hideReadEntries): | |
40 # TODO how to hide read entries if requested? | |
41 viewResults = FeedEntry.view(self.database, "feedtest/feedEntries_by_feed", | |
42 key=self.selectedFeed.id) | |
43 return list(viewResults) | |
44 | |
45 def markSelectedFeedAsRead(self): | |
46 for feedEntry in self.entriesForSelectedFeed(): | |
47 feedEntry.markRead(self.database) | |
48 | |
49 # | |
50 # handling of the selected feed entry | |
51 # | |
52 | |
53 def _markSelectedFeedEntryRead(self): | |
54 self.selectedFeedEntry.markRead(self.database) | |
55 | |
56 def toggleSelectedFeedEntryRead(self): | |
57 self.selectedFeedEntry.toggleRead(self.database) | |
58 | |
33 | 59 |
34 def toggleRead(self, feedEntry): | 60 def toggleRead(self, feedEntry): |
35 raise Exception("not yet implemented") | 61 raise Exception("not yet implemented") |
36 | 62 |
37 def markAllEntriesRead(self, feed): | 63 def markAllEntriesRead(self, feed): |
50 viewName = "feedtest/feedEntries_by_feed" | 76 viewName = "feedtest/feedEntries_by_feed" |
51 if hideReadEntries: | 77 if hideReadEntries: |
52 viewName = "feedtest/unread_feedEntries_by_feed" | 78 viewName = "feedtest/unread_feedEntries_by_feed" |
53 return list(FeedEntry.view(self.database, viewName)) | 79 return list(FeedEntry.view(self.database, viewName)) |
54 | 80 |
55 def markFeedEntriesAsRead(self, entries): | 81 def markFeedEntriesAsRead(self, indices): |
56 raise Exception("not yet implemented") | 82 for index in indices: |
83 feedEntry = self.entriesForSelectedFeed()[index] | |
84 feedEntry.markRead(self.database) | |
57 | 85 |
58 def updateAllFeeds(self): | 86 def updateAllFeeds(self): |
59 # TODO use a view instead of iterating all feeds | 87 # TODO use a view instead of iterating all feeds |
60 allFeeds = Feed.all(self.database) | 88 allFeeds = Feed.all(self.database) |
61 for feed in allFeeds: | 89 for feed in allFeeds: |
64 | 92 |
65 def expireFeedEntries(self): | 93 def expireFeedEntries(self): |
66 print("Expiring feeds is not yet implemented") | 94 print("Expiring feeds is not yet implemented") |
67 # raise Exception("not yet implemented") | 95 # raise Exception("not yet implemented") |
68 | 96 |
69 def dispose(self): | |
70 # nothing to do here | |
71 pass |