コード例 #1
0
class Bookmark(db.Model, RightMixin):
    """
    Represent a bookmark.
    """

    id = db.Column(db.Integer(), primary_key=True)
    href = db.Column(db.String(), default="")
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="")
    shared = db.Column(db.Boolean(), default=False)
    to_read = db.Column(db.Boolean(), default=False)
    time = db.Column(db.DateTime(), default=datetime.utcnow)
    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))

    # relationships
    tags = db.relationship(
        BookmarkTag,
        backref="of_bookmark",
        lazy="dynamic",
        cascade="all,delete-orphan",
        order_by=desc(BookmarkTag.text),
    )
    tags_proxy = association_proxy("tags", "text")

    @validates("description")
    def validates_title(self, key, value):
        return str(value).strip()

    @validates("extended")
    def validates_description(self, key, value):
        return str(value).strip()

    def __repr__(self):
        return "<Bookmark %r>" % (self.href)
コード例 #2
0
ファイル: article.py プロジェクト: samosky123/newspipe
class Article(db.Model, RightMixin):
    "Represent an article from a feed."
    id = db.Column(db.Integer(), primary_key=True)
    entry_id = db.Column(db.String(), nullable=False)
    link = db.Column(db.String())
    title = db.Column(db.String())
    content = db.Column(db.String())
    readed = db.Column(db.Boolean(), default=False)
    like = db.Column(db.Boolean(), default=False)
    date = db.Column(db.DateTime(), default=datetime.utcnow)
    updated_date = db.Column(db.DateTime(), default=datetime.utcnow)
    retrieved_date = db.Column(db.DateTime(), default=datetime.utcnow)

    # foreign keys
    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))
    feed_id = db.Column(db.Integer(), db.ForeignKey("feed.id"))
    category_id = db.Column(db.Integer(), db.ForeignKey("category.id"))

    # relationships
    tag_objs = db.relationship(
        "ArticleTag",
        back_populates="article",
        cascade="all,delete-orphan",
        lazy=False,
        foreign_keys="[ArticleTag.article_id]",
    )
    tags = association_proxy("tag_objs", "text")

    __table_args__ = (ForeignKeyConstraint([user_id], ['user.id'],
                                           ondelete='CASCADE'),
                      ForeignKeyConstraint([feed_id], ['feed.id'],
                                           ondelete='CASCADE'),
                      ForeignKeyConstraint([category_id], ['category.id'],
                                           ondelete='CASCADE'),
                      Index('ix_article_eid_cid_uid', user_id, category_id,
                            entry_id),
                      Index('ix_article_retrdate',
                            retrieved_date), Index('user_id'),
                      Index('user_id',
                            'category_id'), Index('user_id', 'feed_id'),
                      Index('ix_article_uid_fid_eid', user_id, feed_id,
                            entry_id))

    # api whitelists
    @staticmethod
    def _fields_base_write():
        return {"readed", "like", "feed_id", "category_id"}

    @staticmethod
    def _fields_base_read():
        return {
            "id",
            "entry_id",
            "link",
            "title",
            "content",
            "date",
            "retrieved_date",
            "user_id",
            "tags",
        }

    @staticmethod
    def _fields_api_write():
        return {"tags"}

    def __repr__(self):
        return ("<Article(id=%d, entry_id=%s, title=%r, "
                "date=%r, retrieved_date=%r)>" %
                (self.id, self.entry_id, self.title, self.date,
                 self.retrieved_date))
コード例 #3
0
ファイル: feed.py プロジェクト: stephengathambiri/newspipe
class Feed(db.Model, RightMixin):
    """
    Represent a feed.
    """

    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="FR")
    link = db.Column(db.String(), nullable=False)
    site_link = db.Column(db.String(), default="")
    enabled = db.Column(db.Boolean(), default=True)
    created_date = db.Column(db.DateTime(), default=datetime.utcnow)
    filters = db.Column(db.PickleType, default=[])
    private = db.Column(db.Boolean(), default=False)

    # cache handling
    etag = db.Column(db.String(), default="")
    last_modified = db.Column(db.String(), default="")
    last_retrieved = db.Column(db.DateTime(), default=datetime(1970, 1, 1))

    # error logging
    last_error = db.Column(db.String(), default="")
    error_count = db.Column(db.Integer(), default=0)

    # relationship
    icon_url = db.Column(db.String(), db.ForeignKey("icon.url"), default=None)
    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))
    category_id = db.Column(db.Integer(), db.ForeignKey("category.id"))
    articles = db.relationship(
        Article,
        backref="source",
        lazy="dynamic",
        cascade="all,delete-orphan",
        order_by=desc(Article.date),
    )

    # index
    idx_feed_uid_cid = Index("user_id", "category_id")
    idx_feed_uid = Index("user_id")

    # api whitelists
    @staticmethod
    def _fields_base_write():
        return {
            "title",
            "description",
            "link",
            "site_link",
            "enabled",
            "filters",
            "last_error",
            "error_count",
            "category_id",
        }

    @staticmethod
    def _fields_base_read():
        return {"id", "user_id", "icon_url", "last_retrieved"}

    @validates("title")
    def validates_title(self, key, value):
        return str(value).strip()

    @validates("description")
    def validates_description(self, key, value):
        return str(value).strip()

    def __repr__(self):
        return "<Feed %r>" % (self.title)
コード例 #4
0
ファイル: user.py プロジェクト: moser/newspipe
class User(db.Model, UserMixin, RightMixin):
    """
    Represent a user.
    """

    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(), unique=True)
    pwdhash = db.Column(db.String())

    automatic_crawling = db.Column(db.Boolean(), default=True)

    is_public_profile = db.Column(db.Boolean(), default=False)
    bio = db.Column(db.String(5000), default="")
    webpage = db.Column(db.String(), default="")
    twitter = db.Column(db.String(), default="")

    date_created = db.Column(db.DateTime(), default=datetime.utcnow)
    last_seen = db.Column(db.DateTime(), default=datetime.utcnow)

    # user rights
    is_active = db.Column(db.Boolean(), default=False)
    is_admin = db.Column(db.Boolean(), default=False)
    is_api = db.Column(db.Boolean(), default=False)

    # relationships
    categories = db.relationship(
        "Category",
        backref="user",
        cascade="all, delete-orphan",
        foreign_keys=[Category.user_id],
    )
    feeds = db.relationship(
        "Feed",
        backref="user",
        cascade="all, delete-orphan",
        foreign_keys=[Feed.user_id],
    )

    @staticmethod
    def _fields_base_write():
        return {"login", "password"}

    @staticmethod
    def _fields_base_read():
        return {"date_created", "last_connection"}

    @staticmethod
    def make_valid_nickname(nickname):
        return re.sub("[^a-zA-Z0-9_\.]", "", nickname)

    @validates("bio")
    def validates_bio(self, key, value):
        assert len(value) <= 5000, AssertionError("maximum length for bio: 5000")
        return value.strip()

    def get_id(self):
        """
        Return the id of the user.
        """
        return self.id

    def check_password(self, password):
        """
        Check the password of the user.
        """
        return check_password_hash(self.pwdhash, password)

    def __eq__(self, other):
        return self.id == other.id

    def __repr__(self):
        return "<User %r>" % (self.nickname)