Mercurial > hg > Feedworm
comparison FeedList.py @ 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 | |
children | e8c2730eb444 |
comparison
equal
deleted
inserted
replaced
70:842727971796 | 71:228da10cc98b |
---|---|
1 | |
2 from Feed import Feed | |
3 from FeedEntry import FeedEntry | |
4 from sqlalchemy.orm import joinedload | |
5 | |
6 def getFeeds(session): | |
7 # return AllFeeds(session).getFeeds() | |
8 return UnreadFeeds(session).getFeeds() | |
9 | |
10 class AllFeeds(object): | |
11 '''A simple feed list that returns all feeds stored in the database''' | |
12 | |
13 def __init__(self, session): | |
14 self.session = session | |
15 | |
16 def getFeeds(self): | |
17 return Feed.all(self.session) | |
18 | |
19 class UnreadFeeds(object): | |
20 '''A feed list that returns only Feed objects that have unread entries''' | |
21 | |
22 def __init__(self, session): | |
23 self.session = session | |
24 | |
25 def getFeeds(self): | |
26 query = self.session.query(FeedEntry).filter(FeedEntry.read == 0) | |
27 queryWithOptions = query.options(joinedload("feed")) | |
28 result = queryWithOptions.all() | |
29 return self._collectFeeds(result) | |
30 | |
31 def _collectFeeds(self, feedEntries): | |
32 feeds = [entry.feed for entry in feedEntries] | |
33 uniqueFeeds = set(feeds) | |
34 return list(uniqueFeeds) |