comparison backend/couchdb/FeedEntry.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 a05719a6175e
comparison
equal deleted inserted replaced
146:8ec20377bcb0 147:b290e29a94b5
1 1
2 class FeedEntry(object): 2 from couchdb.mapping import BooleanField, DateTimeField, Document, TextField
3 from datetime import datetime
4
5 class FeedEntry(Document):
6 doctype = TextField(default="feedEntry")
7 create_timestamp = DateTimeField(default=datetime.now())
8 read = BooleanField(default=False)
9 link = TextField()
10 title = TextField()
11 summary = TextField()
12 updated = DateTimeField()
13 feed = TextField()
14
3 @staticmethod 15 @staticmethod
4 def findByLink(link, database): 16 def findByLink(link, database):
5 viewResults = database.view("feedtest/feedEntry_by_link") 17 # result = FeedEntry.view(database, "feedtest/feedEntry_by_link", { "key" : link })
6 resultsForKey = viewResults[link] 18 # try:
7 try: 19 # row = iter(result).next()
8 row = iter(resultsForKey).next() 20 # return FeedEntry(row)
9 return FeedEntry(row) 21 # except StopIteration:
10 except StopIteration: 22 # return None
11 return None 23 return None
12 24
13 def __init__(self, row):
14 self.row = row
15
16 def __getattr__(self, key):
17 return self.row.value[key]
18