Mercurial > hg > Feedworm
comparison backend/sqlalchemy/SqlAlchemyBackend.py @ 153:65c4bb6d5add
move management of the selected feed entry into the backend - sqlachemy backend works, couchdb backend currently broken
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 27 Aug 2011 07:29:33 +0200 |
parents | bca9341dc67f |
children | 2682db280be0 |
comparison
equal
deleted
inserted
replaced
152:a1c0459e1eeb | 153:65c4bb6d5add |
---|---|
21 self.session = Database.createSession() | 21 self.session = Database.createSession() |
22 self.prefs = Preferences(self.session) | 22 self.prefs = Preferences(self.session) |
23 self.updater = None | 23 self.updater = None |
24 self.feeds = [] | 24 self.feeds = [] |
25 self.selectedFeed = None | 25 self.selectedFeed = None |
26 self.feedEntries = None | |
27 self.selectedFeedEntry = None | |
26 | 28 |
27 def _initLogging(self): | 29 def _initLogging(self): |
28 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) | 30 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) |
29 | 31 |
30 sqlalchemyLogLevel = logging.ERROR | 32 sqlalchemyLogLevel = logging.ERROR |
32 sqlalchemyLogLevel = logging.INFO | 34 sqlalchemyLogLevel = logging.INFO |
33 logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel) | 35 logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel) |
34 | 36 |
35 def preferences(self): | 37 def preferences(self): |
36 return self.prefs | 38 return self.prefs |
39 | |
40 # | |
41 # handling of feeds | |
42 # | |
37 | 43 |
38 def getFeeds(self): | 44 def getFeeds(self): |
39 if self.preferences().showOnlyUnreadFeeds(): | 45 if self.preferences().showOnlyUnreadFeeds(): |
40 self.feeds = self._getUnreadFeeds() | 46 self.feeds = self._getUnreadFeeds() |
41 else: | 47 else: |
53 uniqueFeeds = set(feeds) | 59 uniqueFeeds = set(feeds) |
54 return list(uniqueFeeds) | 60 return list(uniqueFeeds) |
55 | 61 |
56 def selectFeed(self, index): | 62 def selectFeed(self, index): |
57 self.selectedFeed = self.feeds[index] | 63 self.selectedFeed = self.feeds[index] |
64 self.feedEntries = None | |
58 return self.selectedFeed | 65 return self.selectedFeed |
59 | 66 |
60 def entriesForSelectedFeed(self, hideReadEntries): | 67 def entriesForSelectedFeed(self): |
61 return self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) | 68 hideReadEntries = self.prefs.hideReadFeedEntries() |
69 if self.feedEntries is None: | |
70 self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) | |
71 return self.feedEntries | |
62 | 72 |
63 def markSelectedFeedAsRead(self): | 73 def markSelectedFeedAsRead(self): |
64 self.selectedFeed.markAllEntriesRead() | 74 self.selectedFeed.markAllEntriesRead() |
65 self.session.commit() | 75 self.session.commit() |
66 | 76 |
67 def deleteSelectedFeed(self): | 77 def deleteSelectedFeed(self): |
68 self.session.delete(self.selectedFeed) | 78 self.session.delete(self.selectedFeed) |
69 self.session.commit() | 79 self.session.commit() |
70 | 80 |
81 # | |
82 # handling of the selected feed entry | |
83 # | |
84 def selectFeedEntry(self, index): | |
85 self.selectedFeedEntry = self.feedEntries[index] | |
86 self.selectedFeedEntry.markRead() | |
87 return self.selectedFeedEntry | |
88 | |
89 def markFeedEntriesAsRead(self, indices): | |
90 for index in indices: | |
91 self.feedEntries[index].markRead() | |
92 self.session.commit() | |
93 | |
94 def toggleSelectedFeedEntryRead(self): | |
95 self.selectedFeedEntry.toggleRead() | |
96 self.session.commit() | |
71 | 97 |
72 | 98 |
73 def toggleRead(self, feedEntry): | |
74 feedEntry.toggleRead() | |
75 self.session.commit() | |
76 | 99 |
77 def createFeed(self, url): | 100 def createFeed(self, url): |
78 try: | 101 try: |
79 FeedUpdater.createNewFeed(url, self.session) | 102 FeedUpdater.createNewFeed(url, self.session) |
80 self.session.commit() | 103 self.session.commit() |
86 feed.takeChangesFrom(changes) | 109 feed.takeChangesFrom(changes) |
87 feed.incrementNextUpdateDate() | 110 feed.incrementNextUpdateDate() |
88 self.session.commit() | 111 self.session.commit() |
89 | 112 |
90 | 113 |
91 def markFeedEntriesAsRead(self, entries): | |
92 for entry in entries: | |
93 entry.markRead() | |
94 self.session.commit() | |
95 | 114 |
96 def updateAllFeeds(self): | 115 def updateAllFeeds(self): |
97 FeedUpdater.updateAllFeeds(self.session) | 116 FeedUpdater.updateAllFeeds(self.session) |
98 self.session.commit() | 117 self.session.commit() |
99 | 118 |