# HG changeset patch # User Dirk Olmes # Date 1281489032 -7200 # Node ID 228da10cc98b1717510a38bdb47b8b8f4b2a1d1f # Parent 842727971796dd9fb14d1792ee89db860840e55b MainWindow relies on FeedList to get the feeds to display now. FeedList has two inner/private classes: one for returning all known feeds and one to return only feeds with unread entries. diff -r 842727971796 -r 228da10cc98b FeedList.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FeedList.py Wed Aug 11 03:10:32 2010 +0200 @@ -0,0 +1,34 @@ + +from Feed import Feed +from FeedEntry import FeedEntry +from sqlalchemy.orm import joinedload + +def getFeeds(session): +# return AllFeeds(session).getFeeds() + return UnreadFeeds(session).getFeeds() + +class AllFeeds(object): + '''A simple feed list that returns all feeds stored in the database''' + + def __init__(self, session): + self.session = session + + def getFeeds(self): + return Feed.all(self.session) + +class UnreadFeeds(object): + '''A feed list that returns only Feed objects that have unread entries''' + + def __init__(self, session): + self.session = session + + def getFeeds(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) diff -r 842727971796 -r 228da10cc98b MainWindow.py --- a/MainWindow.py Wed Aug 11 02:30:47 2010 +0200 +++ b/MainWindow.py Wed Aug 11 03:10:32 2010 +0200 @@ -10,6 +10,7 @@ from PyQt4 import QtGui from PyQt4.QtCore import QUrl from Ui_MainWindow import Ui_MainWindow +import FeedList import subprocess STATUS_MESSAGE_DISPLAY_MILLIS = 20000 @@ -24,8 +25,8 @@ self.updateFeedList() self.initFeedEntryList() - def updateFeedList(self): - self.allFeeds = Feed.all(self.session) + def updateFeedList(self): + self.allFeeds = FeedList.getFeeds(self.session) feedModel = DisplayModel(self, self.allFeeds, Feed.userPresentableString) self.ui.feedList.setModel(feedModel) self.ui.feedList.update()