view FeedList.py @ 71:228da10cc98b

MainWindow relies on FeedList to get the feeds to display now. FeedList has two inner/private classes: one for returning all known feeds and one to return only feeds with unread entries.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 11 Aug 2010 03:10:32 +0200
parents
children e8c2730eb444
line wrap: on
line source


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

def getFeeds(session):
#    return AllFeeds(session).getFeeds()
    return UnreadFeeds(session).getFeeds()

class AllFeeds(object):
    '''A simple feed list that returns all feeds stored in the database'''

    def __init__(self, session):
        self.session = session
    
    def getFeeds(self):
        return Feed.all(self.session)
    
class UnreadFeeds(object):
    '''A feed list that returns only Feed objects that have unread entries'''
    
    def __init__(self, session):
        self.session = session
        
    def getFeeds(self):
        query = self.session.query(FeedEntry).filter(FeedEntry.read == 0)
        queryWithOptions = query.options(joinedload("feed"))
        result = queryWithOptions.all()
        return self._collectFeeds(result)
    
    def _collectFeeds(self, feedEntries):
        feeds = [entry.feed for entry in feedEntries]
        uniqueFeeds = set(feeds)
        return list(uniqueFeeds)