diff FeedList.py @ 73:5585f3d23541

Simplify: no classes needed for simple if
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 11 Aug 2010 03:26:21 +0200
parents e8c2730eb444
children
line wrap: on
line diff
--- a/FeedList.py	Wed Aug 11 03:23:02 2010 +0200
+++ b/FeedList.py	Wed Aug 11 03:26:21 2010 +0200
@@ -7,32 +7,17 @@
 def getFeeds(session):
     preferences = Preferences(session)
     if preferences.showOnlyUnreadFeeds():
-        return UnreadFeeds(session).getFeeds()
+        return _getUnreadFeeds(session)
     else:
-        return AllFeeds(session).getFeeds()
-
-class AllFeeds(object):
-    '''A simple feed list that returns all feeds stored in the database'''
+        return Feed.all(session)
 
-    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)
+def _getUnreadFeeds(session):
+    query = session.query(FeedEntry).filter(FeedEntry.read == 0)
+    queryWithOptions = query.options(joinedload("feed"))
+    result = queryWithOptions.all()
+    return _collectFeeds(result)
+
+def _collectFeeds(feedEntries):
+    feeds = [entry.feed for entry in feedEntries]
+    uniqueFeeds = set(feeds)
+    return list(uniqueFeeds)