comparison Feed.py @ 99:e59d722439b5

filter out read entries first before sorting
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 29 Dec 2010 04:27:58 +0100
parents d292ab61ed6f
children
comparison
equal deleted inserted replaced
98:3be484078991 99:e59d722439b5
4 4
5 class Feed(object): 5 class Feed(object):
6 @staticmethod 6 @staticmethod
7 def all(session): 7 def all(session):
8 return session.query(Feed).order_by(Feed.title).all() 8 return session.query(Feed).order_by(Feed.title).all()
9 9
10 def __init__(self, title, rss_url): 10 def __init__(self, title, rss_url):
11 self.title = title 11 self.title = title
12 self.rss_url = rss_url 12 self.rss_url = rss_url
13 # default: update every 60 minutes 13 # default: update every 60 minutes
14 self.update_interval = 60 14 self.update_interval = 60
19 def __repr__(self): 19 def __repr__(self):
20 return "<Feed (%d) %s>" % (self.pk, self.title) 20 return "<Feed (%d) %s>" % (self.pk, self.title)
21 21
22 def userPresentableString(self): 22 def userPresentableString(self):
23 return self.title 23 return self.title
24 24
25 def entriesSortedByUpdateDate(self, hideReadEntries=False): 25 def entriesSortedByUpdateDate(self, hideReadEntries=False):
26 sortedEntries = list(self.entries) 26 if hideReadEntries:
27 sortedEntries = self._unreadEntries()
28 else:
29 sortedEntries = list(self.entries)
27 sortedEntries.sort(FeedEntry.compareByUpdateDate) 30 sortedEntries.sort(FeedEntry.compareByUpdateDate)
28 if hideReadEntries:
29 return self._filterReadEntries(sortedEntries)
30 return sortedEntries 31 return sortedEntries
31 32
32 def _filterReadEntries(self, entries): 33 def _unreadEntries(self):
33 retValue = [] 34 retValue = []
34 for entry in entries: 35 for entry in self.entries:
35 if not entry.read: 36 if not entry.read:
36 retValue.append(entry) 37 retValue.append(entry)
37 return retValue 38 return retValue
38 39
39 def incrementNextUpdateDate(self): 40 def incrementNextUpdateDate(self):