Mercurial > hg > Feedworm
annotate Feed.py @ 34:5813e3c10f14
move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 05 May 2010 02:14:05 +0200 |
parents | 5bb57caa8f66 |
children | aaec263f07ca |
rev | line source |
---|---|
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
1 |
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
2 import FeedEntry |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
4 class Feed(object): |
16
3ffecc709da9
move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
7
diff
changeset
|
5 @staticmethod |
3ffecc709da9
move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
7
diff
changeset
|
6 def all(session): |
3ffecc709da9
move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
7
diff
changeset
|
7 return session.query(Feed).order_by(Feed.title).all() |
3ffecc709da9
move fetch logic into Feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
7
diff
changeset
|
8 |
7 | 9 def __init__(self, title, rss_url): |
10 self.title = title | |
11 self.rss_url = rss_url | |
2
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 |
8a624ee48a74
First skeleton for sqlalchemy: define the mapping and create the first feed
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 def __repr__(self): |
7 | 14 return "<Feed (%d) %s>" % (self.pk, self.title) |
17
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
15 |
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
16 def userPresentableString(self): |
5fda8bd94fa8
make the model used to display feeds generic (so it can be used to display FeedEntries, too)
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
16
diff
changeset
|
17 return self.title |
31
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
18 |
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
19 def entriesSortedByUpdateDate(self): |
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
20 sortedEntries = list(self.entries) |
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
21 sortedEntries.sort(FeedEntry.compareByUpdateDate) |
5bb57caa8f66
display a feed's entries sorted by their update date
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
17
diff
changeset
|
22 return sortedEntries |