comparison backend/couchdb/FeedEntry.py @ 189:e5d492595bdb

the view returns feed entries for a feed sorted by update date now, no need to do sorting in-memory
author dirk
date Wed, 14 Sep 2011 00:17:55 +0200
parents ac1de0a467fd
children 9d422fa90096
comparison
equal deleted inserted replaced
188:e26210be221f 189:e5d492595bdb
1 1
2 from backend.couchdb.ListDateTimeField import ListDateTimeField 2 from backend.couchdb.ListDateTimeField import ListDateTimeField
3 from couchdb.mapping import BooleanField, DateTimeField, Document, TextField 3 from couchdb.mapping import BooleanField, Document, TextField
4 from datetime import datetime 4 from datetime import datetime
5 import CouchDb 5 import CouchDb
6 6
7 class FeedEntry(Document): 7 class FeedEntry(Document):
8 doctype = TextField(default="feedEntry") 8 doctype = TextField(default="feedEntry")
9 create_timestamp = ListDateTimeField(default=datetime.now()) 9 create_timestamp = ListDateTimeField(default=datetime.now())
10 read = BooleanField(default=False) 10 read = BooleanField(default=False)
11 link = TextField() 11 link = TextField()
12 title = TextField() 12 title = TextField()
13 summary = TextField() 13 summary = TextField()
14 updated = DateTimeField() 14 updated = ListDateTimeField()
15 feed = TextField() 15 feed = TextField()
16 16
17 @staticmethod 17 @staticmethod
18 def findByLink(link, database): 18 def findByLink(link, database):
19 result = FeedEntry.view(database, CouchDb.feedEntryByLink(), key=link) 19 result = FeedEntry.view(database, CouchDb.feedEntryByLink(), key=link)
27 end = [timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, 27 end = [timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute,
28 timestamp.second] 28 timestamp.second]
29 return FeedEntry.view(database, CouchDb.readFeedEntriesByCreateDate(), endkey=end) 29 return FeedEntry.view(database, CouchDb.readFeedEntriesByCreateDate(), endkey=end)
30 30
31 @staticmethod 31 @staticmethod
32 def compareByUpdateDate(first, second):
33 return cmp(first, second)
34
35 @staticmethod
36 def entriesForFeed(feed, database): 32 def entriesForFeed(feed, database):
37 viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), key=feed.id) 33 ''' the definition of the view makes sure that the entries come out sorted by udpate date '''
34 viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), startkey=[feed.id],
35 endkey=[feed.id, {}])
38 return list(viewResults) 36 return list(viewResults)
39 37
40 def markRead(self, database): 38 def markRead(self, database):
41 self.read = True 39 self.read = True
42 self.store(database) 40 self.store(database)
45 if self.read: 43 if self.read:
46 self.read = False 44 self.read = False
47 else: 45 else:
48 self.read = True 46 self.read = True
49 self.store(database) 47 self.store(database)
50