annotate backend/sqlalchemy/FeedList.py @ 141:6ea813cfac33

pull out common code for updating a feed into an abstract class, have the sqlalchemy backend use that class.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 24 Aug 2011 10:53:46 +0200
parents 04a730f9d07d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from Feed import Feed
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 from FeedEntry import FeedEntry
72
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 71
diff changeset
4 from Preferences import Preferences
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 from sqlalchemy.orm import joinedload
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7 def getFeeds(session):
72
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 71
diff changeset
8 preferences = Preferences(session)
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 71
diff changeset
9 if preferences.showOnlyUnreadFeeds():
73
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
10 return _getUnreadFeeds(session)
72
e8c2730eb444 control the display of unread feeds/all feeds via Preferences
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 71
diff changeset
11 else:
73
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
12 return Feed.all(session)
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.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13
73
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
14 def _getUnreadFeeds(session):
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
15 query = session.query(FeedEntry).filter(FeedEntry.read == 0)
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
16 queryWithOptions = query.options(joinedload("feed"))
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
17 result = queryWithOptions.all()
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
18 return _collectFeeds(result)
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
19
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
20 def _collectFeeds(feedEntries):
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
21 feeds = [entry.feed for entry in feedEntries]
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
22 uniqueFeeds = set(feeds)
5585f3d23541 Simplify: no classes needed for simple if
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 72
diff changeset
23 return list(uniqueFeeds)