view backend/couchdb/FeedEntry.py @ 186:6cbd4420c187

when replicating, also compact the database
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 13 Sep 2011 17:43:22 +0200
parents ac1de0a467fd
children e5d492595bdb
line wrap: on
line source


from backend.couchdb.ListDateTimeField import ListDateTimeField
from couchdb.mapping import BooleanField, DateTimeField, Document, TextField
from datetime import datetime
import CouchDb

class FeedEntry(Document):
    doctype = TextField(default="feedEntry")
    create_timestamp = ListDateTimeField(default=datetime.now())
    read = BooleanField(default=False)
    link = TextField()
    title = TextField()
    summary = TextField()
    updated = DateTimeField()
    feed = TextField()

    @staticmethod
    def findByLink(link, database):
        result = FeedEntry.view(database, CouchDb.feedEntryByLink(), key=link)
        try:
            return iter(result).next()
        except StopIteration:
            return None

    @staticmethod
    def getReadFeedEntriesOlderThan(timestamp, database):
        end = [timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute,
               timestamp.second]
        return FeedEntry.view(database, CouchDb.readFeedEntriesByCreateDate(), endkey=end)

    @staticmethod
    def compareByUpdateDate(first, second):
        return cmp(first, second)

    @staticmethod
    def entriesForFeed(feed, database):
        viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), key=feed.id)
        return list(viewResults)

    def markRead(self, database):
        self.read = True
        self.store(database)

    def toggleRead(self, database):
        if self.read:
            self.read = False
        else:
            self.read = True
        self.store(database)