예제 #1
0
class User(db.Model):
    """Basic user model
    """
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(db.String(255), nullable=False)
    active = db.Column(db.Boolean, default=True)

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        self.password = pwd_context.hash(self.password)

    def __repr__(self):
        return "<User %s>" % self.username
예제 #2
0
class Annotation(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    article_id = db.Column(db.Integer,
                           db.ForeignKey('article.id'),
                           nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    span_start = db.Column(db.Integer, nullable=False)
    span_finish = db.Column(db.Integer, nullable=False)

    tag = db.Column(db.Integer, nullable=False)
    type = db.Column(db.Integer, nullable=False)

    created_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
    updated_at = db.Column(db.DateTime,
                           default=datetime.now,
                           onupdate=datetime.now,
                           nullable=False)

    __table_args__ = (db.UniqueConstraint(article_id, author_id, span_start,
                                          span_finish, type, tag), )
예제 #3
0
class Corpus(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    description = db.Column(db.String(255), nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    articles = db.relation('Article', backref='corpus', lazy='dynamic')

    created_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
    updated_at = db.Column(db.DateTime,
                           default=datetime.now,
                           onupdate=datetime.now,
                           nullable=False)
예제 #4
0
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String, nullable=False)
    corpus_id = db.Column(db.Integer,
                          db.ForeignKey('corpus.id'),
                          nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    annotations = db.relation('Annotation', backref='article', lazy='dynamic')

    created_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
    updated_at = db.Column(db.DateTime,
                           default=datetime.now,
                           onupdate=datetime.now,
                           nullable=False)
예제 #5
0
class TokenBlacklist(db.Model):
    """Blacklist representation
    """
    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(36), nullable=False, unique=True)
    token_type = db.Column(db.String(10), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    revoked = db.Column(db.Boolean, nullable=False)
    expires = db.Column(db.DateTime, nullable=False)

    user = db.relationship('User', lazy='joined')

    def to_dict(self):
        return {
            'token_id': self.id,
            'jti': self.jti,
            'token_type': self.token_type,
            'user_identity': self.user_identity,
            'revoked': self.revoked,
            'expires': self.expires
        }