view backend/couchdb/FeedEntry.py @ 236:c5250fcc3881

remove a workaround along with its wrong explanation
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 26 Jan 2015 13:43:38 +0100
parents bb3c851b18b1
children 8e73a8ae863f
line wrap: on
line source

# -*- coding: utf-8 -*-
from backend.couchdb.ListDateTimeField import ListDateTimeField
from couchdb.mapping import BooleanField, 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 = ListDateTimeField()
    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 entriesForFeed(feed, database):
        ''' the definition of the view makes sure that the entries come out sorted by udpate date '''
        viewResults = FeedEntry.view(database, CouchDb.feedEntriesByFeed(), startkey=[feed.id],
            endkey=[feed.id, {}])
        return list(viewResults)

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

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