Mercurial > hg > Feedworm
comparison backend/couchdb/CouchDbBackend.py @ 169:91a24f499318
introdue an abstraction for the name of the database so it can be changed via commandline parameter
author | dirk |
---|---|
date | Fri, 09 Sep 2011 14:52:54 +0200 |
parents | 04c3b9796b89 |
children | d0ced79b5030 |
comparison
equal
deleted
inserted
replaced
168:f4708d38419c | 169:91a24f499318 |
---|---|
3 from Preferences import Preferences | 3 from Preferences import Preferences |
4 from backend.AbstractBackend import AbstractBackend | 4 from backend.AbstractBackend import AbstractBackend |
5 from backend.couchdb.Feed import Feed | 5 from backend.couchdb.Feed import Feed |
6 from backend.couchdb.FeedEntry import FeedEntry | 6 from backend.couchdb.FeedEntry import FeedEntry |
7 import couchdb | 7 import couchdb |
8 | 8 from backend.couchdb import CouchDb |
9 DATABASE = "feedtest" | |
10 | 9 |
11 class CouchDbBackend(AbstractBackend): | 10 class CouchDbBackend(AbstractBackend): |
12 ''' | 11 ''' |
13 Backend that uses CouchDB for persistence | 12 Backend that uses CouchDB for persistence |
14 ''' | 13 ''' |
15 | 14 |
16 def __init__(self): | 15 def __init__(self): |
16 CouchDb.init() | |
17 server = couchdb.Server() | 17 server = couchdb.Server() |
18 self.database = server[DATABASE] | 18 self.database = server[CouchDb.database] |
19 self.prefs = None | 19 self.prefs = None |
20 | 20 |
21 def preferences(self): | 21 def preferences(self): |
22 if self.prefs is None: | 22 if self.prefs is None: |
23 self.prefs = Preferences(self.database) | 23 self.prefs = Preferences(self.database) |
39 def _getUnreadFeeds(self): | 39 def _getUnreadFeeds(self): |
40 raise Exception("not yet implemented") | 40 raise Exception("not yet implemented") |
41 | 41 |
42 def _retrieveEntriesForSelectedFeed(self, hideReadEntries): | 42 def _retrieveEntriesForSelectedFeed(self, hideReadEntries): |
43 # TODO how to hide read entries if requested? | 43 # TODO how to hide read entries if requested? |
44 viewResults = FeedEntry.view(self.database, "feedtest/feedEntries_by_feed", | 44 viewResults = FeedEntry.view(self.database, CouchDb.feedEntriesByFeed(), |
45 key=self.selectedFeed.id) | 45 key=self.selectedFeed.id) |
46 return list(viewResults) | 46 return list(viewResults) |
47 | 47 |
48 def markSelectedFeedAsRead(self): | 48 def markSelectedFeedAsRead(self): |
49 for feedEntry in self.entriesForSelectedFeed(): | 49 for feedEntry in self.entriesForSelectedFeed(): |
75 for key in changes.keys(): | 75 for key in changes.keys(): |
76 feed[key] = changes[key] | 76 feed[key] = changes[key] |
77 feed.store(self.database) | 77 feed.store(self.database) |
78 | 78 |
79 def deleteSelectedFeed(self): | 79 def deleteSelectedFeed(self): |
80 viewResults = self.database.view("feedtest/feedEntries_by_feed", key=self.selectedFeed.id) | 80 viewResults = self.database.view(CouchDb.feedEntriesByFeed(), key=self.selectedFeed.id) |
81 for row in viewResults: | 81 for row in viewResults: |
82 del self.database[row.id] | 82 del self.database[row.id] |
83 del self.database[self.selectedFeed.id] | 83 del self.database[self.selectedFeed.id] |
84 | 84 |
85 def entriesForFeed(self, feed, hideReadEntries): | 85 def entriesForFeed(self, feed, hideReadEntries): |
86 viewName = "feedtest/feedEntries_by_feed" | 86 viewName = CouchDb.feedEntriesByFeed() |
87 if hideReadEntries: | 87 if hideReadEntries: |
88 viewName = "feedtest/unread_feedEntries_by_feed" | 88 viewName = CouchDb.unreadFeedEntriesByFeed() |
89 return list(FeedEntry.view(self.database, viewName)) | 89 return list(FeedEntry.view(self.database, viewName)) |
90 | 90 |
91 def markFeedEntriesAsRead(self, indices): | 91 def markFeedEntriesAsRead(self, indices): |
92 for index in indices: | 92 for index in indices: |
93 feedEntry = self.entriesForSelectedFeed()[index] | 93 feedEntry = self.entriesForSelectedFeed()[index] |