annotate backend/couchdb/FeedEntry.py @ 185:0b4c8dc13b7c

when replicating pull from remote first
author dirk
date Mon, 12 Sep 2011 11:07:58 +0200
parents ac1de0a467fd
children e5d492595bdb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
144
74217db92993 updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
171
27be2a5f9c10 use the new ListDateTimeField in FeedEntries to store their creation date
dirk
parents: 169
diff changeset
2 from backend.couchdb.ListDateTimeField import ListDateTimeField
147
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
3 from couchdb.mapping import BooleanField, DateTimeField, Document, TextField
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
4 from datetime import datetime
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents: 163
diff changeset
5 import CouchDb
147
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
6
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
7 class FeedEntry(Document):
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
8 doctype = TextField(default="feedEntry")
171
27be2a5f9c10 use the new ListDateTimeField in FeedEntries to store their creation date
dirk
parents: 169
diff changeset
9 create_timestamp = ListDateTimeField(default=datetime.now())
147
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
10 read = BooleanField(default=False)
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
11 link = TextField()
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
12 title = TextField()
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
13 summary = TextField()
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
14 updated = DateTimeField()
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
15 feed = TextField()
b290e29a94b5 use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 144
diff changeset
16
144
74217db92993 updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 @staticmethod
74217db92993 updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 def findByLink(link, database):
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents: 163
diff changeset
19 result = FeedEntry.view(database, CouchDb.feedEntryByLink(), key=link)
163
e284a37df1d9 re-enable finding a FeedEntry by its link
dirk
parents: 155
diff changeset
20 try:
e284a37df1d9 re-enable finding a FeedEntry by its link
dirk
parents: 155
diff changeset
21 return iter(result).next()
e284a37df1d9 re-enable finding a FeedEntry by its link
dirk
parents: 155
diff changeset
22 except StopIteration:
e284a37df1d9 re-enable finding a FeedEntry by its link
dirk
parents: 155
diff changeset
23 return None
144
74217db92993 updating feeds on the couchdb backend works now
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24
174
d0ced79b5030 implement expiring read feed entries
dirk
parents: 171
diff changeset
25 @staticmethod
d0ced79b5030 implement expiring read feed entries
dirk
parents: 171
diff changeset
26 def getReadFeedEntriesOlderThan(timestamp, database):
d0ced79b5030 implement expiring read feed entries
dirk
parents: 171
diff changeset
27 end = [timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute,
d0ced79b5030 implement expiring read feed entries
dirk
parents: 171
diff changeset
28 timestamp.second]
d0ced79b5030 implement expiring read feed entries
dirk
parents: 171
diff changeset
29 return FeedEntry.view(database, CouchDb.readFeedEntriesByCreateDate(), endkey=end)
d0ced79b5030 implement expiring read feed entries
dirk
parents: 171
diff changeset
30
181
1ab48428e2f9 sort the feed entries
dirk
parents: 174
diff changeset
31 @staticmethod
1ab48428e2f9 sort the feed entries
dirk
parents: 174
diff changeset
32 def compareByUpdateDate(first, second):
1ab48428e2f9 sort the feed entries
dirk
parents: 174
diff changeset
33 return cmp(first, second)
1ab48428e2f9 sort the feed entries
dirk
parents: 174
diff changeset
34
183
ac1de0a467fd clean up
dirk
parents: 181
diff changeset
35 @staticmethod
ac1de0a467fd clean up
dirk
parents: 181
diff changeset
36 def entriesForFeed(feed, database):
ac1de0a467fd clean up
dirk
parents: 181
diff changeset
37 viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), key=feed.id)
ac1de0a467fd clean up
dirk
parents: 181
diff changeset
38 return list(viewResults)
ac1de0a467fd clean up
dirk
parents: 181
diff changeset
39
155
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
40 def markRead(self, database):
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
41 self.read = True
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
42 self.store(database)
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
43
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
44 def toggleRead(self, database):
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
45 if self.read:
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
46 self.read = False
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
47 else:
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
48 self.read = True
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
49 self.store(database)
a05719a6175e move common functionality into an abstract backend class, have both backends inherit from it. Implement enough of the couchdb backend that reading feeds (and marking feed entries as read) is possible
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 147
diff changeset
50