diff backend/couchdb/Feed.py @ 147:b290e29a94b5

use couchdb's mapping API instead of manually coding around Rows - much leaner code :-)
author Dirk Olmes <dirk@xanthippe.ping.de>
date Thu, 25 Aug 2011 11:05:05 +0200
parents 74217db92993
children 7d724cf2dcf7
line wrap: on
line diff
--- a/backend/couchdb/Feed.py	Thu Aug 25 07:01:45 2011 +0200
+++ b/backend/couchdb/Feed.py	Thu Aug 25 11:05:05 2011 +0200
@@ -1,34 +1,28 @@
 
+from couchdb.mapping import BooleanField, DateTimeField, Document, IntegerField, TextField
 from datetime import datetime, timedelta
 
-DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
+class Feed(Document):
+    doctype = TextField(default="feed")
+    title = TextField()
+    rss_url = TextField()
+    update_interval = IntegerField(default=60)
+    next_update = DateTimeField()
+    auto_load_entry_link = BooleanField(default=False)
+    always_open_in_browser = BooleanField(default=False)
 
-class Feed(object):
     @staticmethod
     def all(database):
-        viewResults = database.view("feedtest/feeds")
-        return [Feed(row) for row in viewResults]
-
-    def __init__(self, row):
-        self.row = row
-
-    def __getattr__(self, key):
-        return self.row.value[key]
+        return Feed.view(database, "feedtest/feeds")
 
     def needsUpdate(self):
-        updateDate = self._nextUpdateDate()
-        delta = datetime.now() - updateDate
+        delta = datetime.now() - self.next_update
         return delta.total_seconds() > self._updateIntervalInSeconds()
 
-    def incrementedUpdateDate(self):
-        updateDate = self._nextUpdateDate()
+    def incrementNextUpdateDate(self):
         updateInterval = self._updateIntervalInSeconds()
         delta = timedelta(seconds=updateInterval)
-        return updateDate + delta
-
-    def _nextUpdateDate(self):
-        nextUpdateString = self.next_update
-        return datetime.strptime(nextUpdateString, DATE_FORMAT)
+        self.next_update = self.next_update + delta
 
     def _updateIntervalInSeconds(self):
         return self.update_interval * 60