comparison backend/sqlalchemy/SqlAlchemyBackend.py @ 145:71c5dc02ff87

move the code from FeedList into the backend class
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 25 Aug 2011 05:39:03 +0200
parents 32a173cb081c
children 8ec20377bcb0
comparison
equal deleted inserted replaced
144:74217db92993 145:71c5dc02ff87
1 1
2 from Feed import Feed
3 from FeedEntry import FeedEntry
2 from Preferences import Preferences 4 from Preferences import Preferences
3 from datetime import datetime, timedelta 5 from datetime import datetime, timedelta
6 from sqlalchemy.orm import joinedload
4 from sqlalchemy.sql import and_ 7 from sqlalchemy.sql import and_
5 import Database 8 import Database
6 import FeedList
7 import FeedUpdater 9 import FeedUpdater
8 import Mapping 10 import Mapping
9 import logging 11 import logging
10 import util 12 import util
11 13
30 32
31 def preferences(self): 33 def preferences(self):
32 return self.prefs 34 return self.prefs
33 35
34 def getFeeds(self): 36 def getFeeds(self):
35 return FeedList.getFeeds(self.session) 37 if self.preferences().showOnlyUnreadFeeds():
38 return self._getUnreadFeeds()
39 else:
40 return Feed.all(self.session)
41
42 def _getUnreadFeeds(self):
43 query = self.session.query(FeedEntry).filter(FeedEntry.read == 0)
44 queryWithOptions = query.options(joinedload("feed"))
45 result = queryWithOptions.all()
46 return self._collectFeeds(result)
47
48 def _collectFeeds(self, feedEntries):
49 feeds = [entry.feed for entry in feedEntries]
50 uniqueFeeds = set(feeds)
51 return list(uniqueFeeds)
36 52
37 def toggleRead(self, feedEntry): 53 def toggleRead(self, feedEntry):
38 feedEntry.toggleRead() 54 feedEntry.toggleRead()
39 self.session.commit() 55 self.session.commit()
40 56