changeset 71:228da10cc98b

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.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 11 Aug 2010 03:10:32 +0200
parents 842727971796
children e8c2730eb444
files FeedList.py MainWindow.py
diffstat 2 files changed, 37 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /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)
--- 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()