# Path: web/util/db.py
# def get_db(database=None):


from web.util.db import db
        from feed import Feed
                                              limit=temp)
        for feed in feeds[:500]:
            if not user.has_feed(feed=feed):
                ReadFeed.add(feed=feed,user=user,feedsite=feedsite)
                sub.unread_counter += 1
        sub.save()
        return sub


    @classmethod
    def exist_sub(cls,user=None,feedsite=None):
        return cls.objects(user=user,feedsite=feedsite).first() is not None


    @classmethod
    def refresh_sub(cls, feedsite=None, new_feeds=None):
        subs = cls.objects(feedsite=feedsite)
        for sub in subs:
            sub.unread_counter += len(new_feeds)
            sub.save()

            for feed in new_feeds:
                ReadFeed.add(feed=feed,user=sub.user,feedsite=feedsite)


# all user sub subscript is in uncategoried folder

#user <-> feeds, means use start a feed;
#it is possible that user can star a feed but have not read it
class StarFeed(db.Document):

# Path: web/util/db.py
# def get_db(database=None):


# Path: web/model/user_feed.py
from web.util.db import db
        from feed import Feed

                                              limit=temp)
        for feed in feeds[:500]:
            if not user.has_feed(feed=feed):
                ReadFeed.add(feed=feed,user=user,feedsite=feedsite)
                sub.unread_counter += 1
        sub.save()
        return sub


    @classmethod
    def exist_sub(cls,user=None,feedsite=None):
        return cls.objects(user=user,feedsite=feedsite).first() is not None


    @classmethod
    def refresh_sub(cls, feedsite=None, new_feeds=None):
        subs = cls.objects(feedsite=feedsite)
        for sub in subs:
            sub.unread_counter += len(new_feeds)
            sub.save()

            for feed in new_feeds:
                ReadFeed.add(feed=feed,user=sub.user,feedsite=feedsite)


# all user sub subscript is in uncategoried folder

#user <-> feeds, means use start a feed;
#it is possible that user can star a feed but have not read it
class StarFeed(db.Document):

    feed            = db.ReferenceField("Feed")