comparison backend/sqlalchemy/SqlAlchemyBackend.py @ 151:bca9341dc67f

move the selected feed into the backend - sqlalchemy backend works, couchdb backend currently broken
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 27 Aug 2011 07:07:50 +0200
parents 8ec20377bcb0
children 65c4bb6d5add
comparison
equal deleted inserted replaced
150:babe14449162 151:bca9341dc67f
19 def __init__(self): 19 def __init__(self):
20 self._initLogging() 20 self._initLogging()
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 = []
25 self.selectedFeed = None
24 26
25 def _initLogging(self): 27 def _initLogging(self):
26 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) 28 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
27 29
28 sqlalchemyLogLevel = logging.ERROR 30 sqlalchemyLogLevel = logging.ERROR
33 def preferences(self): 35 def preferences(self):
34 return self.prefs 36 return self.prefs
35 37
36 def getFeeds(self): 38 def getFeeds(self):
37 if self.preferences().showOnlyUnreadFeeds(): 39 if self.preferences().showOnlyUnreadFeeds():
38 return self._getUnreadFeeds() 40 self.feeds = self._getUnreadFeeds()
39 else: 41 else:
40 return Feed.all(self.session) 42 self.feeds = Feed.all(self.session)
43 return self.feeds
41 44
42 def _getUnreadFeeds(self): 45 def _getUnreadFeeds(self):
43 query = self.session.query(FeedEntry).filter(FeedEntry.read == 0) 46 query = self.session.query(FeedEntry).filter(FeedEntry.read == 0)
44 queryWithOptions = query.options(joinedload("feed")) 47 queryWithOptions = query.options(joinedload("feed"))
45 result = queryWithOptions.all() 48 result = queryWithOptions.all()
48 def _collectFeeds(self, feedEntries): 51 def _collectFeeds(self, feedEntries):
49 feeds = [entry.feed for entry in feedEntries] 52 feeds = [entry.feed for entry in feedEntries]
50 uniqueFeeds = set(feeds) 53 uniqueFeeds = set(feeds)
51 return list(uniqueFeeds) 54 return list(uniqueFeeds)
52 55
56 def selectFeed(self, index):
57 self.selectedFeed = self.feeds[index]
58 return self.selectedFeed
59
60 def entriesForSelectedFeed(self, hideReadEntries):
61 return self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries)
62
63 def markSelectedFeedAsRead(self):
64 self.selectedFeed.markAllEntriesRead()
65 self.session.commit()
66
67 def deleteSelectedFeed(self):
68 self.session.delete(self.selectedFeed)
69 self.session.commit()
70
71
72
53 def toggleRead(self, feedEntry): 73 def toggleRead(self, feedEntry):
54 feedEntry.toggleRead() 74 feedEntry.toggleRead()
55 self.session.commit()
56
57 def markAllEntriesRead(self, feed):
58 feed.markAllEntriesRead()
59 self.session.commit() 75 self.session.commit()
60 76
61 def createFeed(self, url): 77 def createFeed(self, url):
62 try: 78 try:
63 FeedUpdater.createNewFeed(url, self.session) 79 FeedUpdater.createNewFeed(url, self.session)
69 def updateFeed(self, feed, changes): 85 def updateFeed(self, feed, changes):
70 feed.takeChangesFrom(changes) 86 feed.takeChangesFrom(changes)
71 feed.incrementNextUpdateDate() 87 feed.incrementNextUpdateDate()
72 self.session.commit() 88 self.session.commit()
73 89
74 def deleteFeed(self, feed):
75 self.session.delete(feed)
76 self.session.commit()
77
78 def entriesForFeed(self, feed, hideReadEntries):
79 return feed.entriesSortedByUpdateDate(hideReadEntries)
80 90
81 def markFeedEntriesAsRead(self, entries): 91 def markFeedEntriesAsRead(self, entries):
82 for entry in entries: 92 for entry in entries:
83 entry.markRead() 93 entry.markRead()
84 self.session.commit() 94 self.session.commit()