Mercurial > hg > Feedworm
diff backend/sqlalchemy/SqlAlchemyBackend.py @ 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
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Sat, 27 Aug 2011 08:52:03 +0200 |
parents | 2682db280be0 |
children | a3c945ce434c |
line wrap: on
line diff
--- a/backend/sqlalchemy/SqlAlchemyBackend.py Sat Aug 27 07:32:01 2011 +0200 +++ b/backend/sqlalchemy/SqlAlchemyBackend.py Sat Aug 27 08:52:03 2011 +0200 @@ -2,6 +2,7 @@ from Feed import Feed from FeedEntry import FeedEntry from Preferences import Preferences +from backend.AbstractBackend import AbstractBackend from datetime import datetime, timedelta from sqlalchemy.orm import joinedload from sqlalchemy.sql import and_ @@ -11,20 +12,17 @@ import logging import util -class SqlAlchemyBackend(object): +class SqlAlchemyBackend(AbstractBackend): ''' Backend that uses sqlalchemy for persistence ''' def __init__(self): + AbstractBackend.__init__(self) self._initLogging() self.session = Database.createSession() self.prefs = Preferences(self.session) self.updater = None - self.feeds = [] - self.selectedFeed = None - self.feedEntries = None - self.selectedFeedEntry = None def _initLogging(self): logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) @@ -64,16 +62,8 @@ uniqueFeeds = set(feeds) return list(uniqueFeeds) - def selectFeed(self, index): - self.selectedFeed = self.feeds[index] - self.feedEntries = None - return self.selectedFeed - - def entriesForSelectedFeed(self): - hideReadEntries = self.prefs.hideReadFeedEntries() - if self.feedEntries is None: - self.feedEntries = self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) - return self.feedEntries + def _retrieveEntriesForSelectedFeed(self, hideReadEntries): + return self.selectedFeed.entriesSortedByUpdateDate(hideReadEntries) def markSelectedFeedAsRead(self): self.selectedFeed.markAllEntriesRead() @@ -103,10 +93,9 @@ # # handling of the selected feed entry # - def selectFeedEntry(self, index): - self.selectedFeedEntry = self.feedEntries[index] + + def _markSelectedFeedEntryRead(self): self.selectedFeedEntry.markRead() - return self.selectedFeedEntry def markFeedEntriesAsRead(self, indices): for index in indices: @@ -117,7 +106,6 @@ self.selectedFeedEntry.toggleRead() self.session.commit() - def expireFeedEntries(self): logger = logging.getLogger("feedupdater") expireDate = self._calculateExpireDate()