Mercurial > hg > Feedworm
diff 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 |
line wrap: on
line diff
--- a/backend/sqlalchemy/SqlAlchemyBackend.py Wed Aug 24 11:54:06 2011 +0200 +++ b/backend/sqlalchemy/SqlAlchemyBackend.py Thu Aug 25 05:39:03 2011 +0200 @@ -1,9 +1,11 @@ +from Feed import Feed +from FeedEntry import FeedEntry from Preferences import Preferences from datetime import datetime, timedelta +from sqlalchemy.orm import joinedload from sqlalchemy.sql import and_ import Database -import FeedList import FeedUpdater import Mapping import logging @@ -32,7 +34,21 @@ return self.prefs def getFeeds(self): - return FeedList.getFeeds(self.session) + if self.preferences().showOnlyUnreadFeeds(): + return self._getUnreadFeeds() + else: + return Feed.all(self.session) + + def _getUnreadFeeds(self): + query = self.session.query(FeedEntry).filter(FeedEntry.read == 0) + queryWithOptions = query.options(joinedload("feed")) + result = queryWithOptions.all() + return self._collectFeeds(result) + + def _collectFeeds(self, feedEntries): + feeds = [entry.feed for entry in feedEntries] + uniqueFeeds = set(feeds) + return list(uniqueFeeds) def toggleRead(self, feedEntry): feedEntry.toggleRead()