comparison 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
comparison
equal deleted inserted replaced
72:e8c2730eb444 73:5585f3d23541
5 from sqlalchemy.orm import joinedload 5 from sqlalchemy.orm import joinedload
6 6
7 def getFeeds(session): 7 def getFeeds(session):
8 preferences = Preferences(session) 8 preferences = Preferences(session)
9 if preferences.showOnlyUnreadFeeds(): 9 if preferences.showOnlyUnreadFeeds():
10 return UnreadFeeds(session).getFeeds() 10 return _getUnreadFeeds(session)
11 else: 11 else:
12 return AllFeeds(session).getFeeds() 12 return Feed.all(session)
13 13
14 class AllFeeds(object): 14 def _getUnreadFeeds(session):
15 '''A simple feed list that returns all feeds stored in the database''' 15 query = session.query(FeedEntry).filter(FeedEntry.read == 0)
16 queryWithOptions = query.options(joinedload("feed"))
17 result = queryWithOptions.all()
18 return _collectFeeds(result)
16 19
17 def __init__(self, session): 20 def _collectFeeds(feedEntries):
18 self.session = session 21 feeds = [entry.feed for entry in feedEntries]
19 22 uniqueFeeds = set(feeds)
20 def getFeeds(self): 23 return list(uniqueFeeds)
21 return Feed.all(self.session)
22
23 class UnreadFeeds(object):
24 '''A feed list that returns only Feed objects that have unread entries'''
25
26 def __init__(self, session):
27 self.session = session
28
29 def getFeeds(self):
30 query = self.session.query(FeedEntry).filter(FeedEntry.read == 0)
31 queryWithOptions = query.options(joinedload("feed"))
32 result = queryWithOptions.all()
33 return self._collectFeeds(result)
34
35 def _collectFeeds(self, feedEntries):
36 feeds = [entry.feed for entry in feedEntries]
37 uniqueFeeds = set(feeds)
38 return list(uniqueFeeds)