view backend/sqlalchemy/FeedList.py @ 141:6ea813cfac33

pull out common code for updating a feed into an abstract class, have the sqlalchemy backend use that class.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 24 Aug 2011 10:53:46 +0200
parents 04a730f9d07d
children
line wrap: on
line source


from Feed import Feed
from FeedEntry import FeedEntry
from Preferences import Preferences
from sqlalchemy.orm import joinedload

def getFeeds(session):
    preferences = Preferences(session)
    if preferences.showOnlyUnreadFeeds():
        return _getUnreadFeeds(session)
    else:
        return Feed.all(session)

def _getUnreadFeeds(session):
    query = session.query(FeedEntry).filter(FeedEntry.read == 0)
    queryWithOptions = query.options(joinedload("feed"))
    result = queryWithOptions.all()
    return _collectFeeds(result)

def _collectFeeds(feedEntries):
    feeds = [entry.feed for entry in feedEntries]
    uniqueFeeds = set(feeds)
    return list(uniqueFeeds)