Exemplo n.º 1
0
class User(db.Model, UserMixin):
    """
    User model for reviewers.
    """
    __tablename__ = 'user'
    id = Column(Integer, autoincrement=True, primary_key=True)
    active = Column(Boolean, default=True)
    username = Column(String(20), unique=True)
    email = Column(String(200), unique=True)
    password = Column(String(200), default='')
    job = Column(String(20), default='')
    organizer = Column(Boolean, default=False)
    admin = Column(Boolean, default=False)
    birthdate = Column(String(20), default='')
    about = Column(db.Text(), default='')
    why = Column(db.Text(), default='')
    a = Column(Boolean, default=False)

    def is_active(self):
        """
        Returns if user is active.
        """
        return self.active

    def is_admin(self):
        """
        Returns if user is admin.
        """
        return self.admin
Exemplo n.º 2
0
class Record(db.Model):
    id = db.Column(db.Integer, nullable=False, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False)
    value = db.Column(db.Text(100), nullable=False)
    value_type = db.Column(db.Text(50), nullable=False)
    confirmed_status = db.Column(db.Text(50),
                                 nullable=False,
                                 default='Not Confirmed')
Exemplo n.º 3
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.Text())
    title = db.Column(db.Text())
    comments = db.relationship('Comment', backref='source', lazy='dynamic')
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __repr__(self):
        return '<Post {}>'.format(self.body)
Exemplo n.º 4
0
class User(db.Model):
    __tablename__ = "users"
    id = db.Column(db.Integer, primary_key=True)
    # 是否封禁
    banned = db.Column(db.Boolean, default=False, nullable=False)
    # 用户名
    username = db.Column(db.String(20), unique=True)
    # 密码
    password = db.Column(db.String(64))
    # 个人简介
    description = db.Column(db.Text(), default="")
    # 电子邮件
    email = db.Column(db.String(30))
    # # 是否为管理员
    # is_admin = db.Column(db.Boolean, default=False)
    # # 是否是原始管理员(用于切换管理员模式)
    # raw_admin = db.Column(db.Boolean, nullable=False, default=False)
    # # 重置密码所需token
    # reset_token = db.Column(db.String(128), default="")
    # # 验证账号所需token,留空表示已验证
    # auth_token = db.Column(db.String(128), default="", nullable=False)
    # 注册时间
    register_time = db.Column(db.DateTime, nullable=False)
    # rating历史
    # [{"result":rating变化,"contest_id":"比赛ID"}]
    rating_history = db.Column(JsonPickle, nullable=False, default=[])
    # 所在团队列表
    joined_teams = db.Column(JsonPickle, nullable=False, default=[])
    # rating
    rating = db.Column(db.Integer, nullable=False, default=1500, index=True)
    # 所属权限组ID
    permission_group = db.Column(db.Text(20),
                                 nullable=False,
                                 default="default")
    # 用户特有权限列表
    permissions = db.Column(JsonPickle, nullable=False, default=[])
    # 强制退出登陆时间在此之前的客户端
    # 通常用于用户 退出\修改密码 后强行下线所有客户端
    force_logout_before = db.Column(db.BigInteger, nullable=False, default=0)

    @staticmethod
    def by_id(id):
        return db.session.query(User).filter(User.id == id).one_or_none()

    def get_rating(self) -> int:
        result = 1500
        for x in self.rating_history:
            result += x["result"]
        return result

    def as_dict(self):
        ret = dict(
            filter(lambda x: not x[0].startswith("_"), self.__dict__.items()))
        return ret
Exemplo n.º 5
0
class Users(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.Text(50))
    email = db.Column(db.Text(50))
    password = db.Column(db.Text(50))
    img = db.Column(db.Text(50))

    def __init__(self, nickname, email, password, img):
        self.nickname = nickname
        self.email = email
        self.password = password
        self.img = img
Exemplo n.º 6
0
class Address(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    addressLine1 = db.Column(db.Text(100), nullable=False)
    addressLine2 = db.Column(db.Text(100), nullable=False)
    pincode = db.Column(db.Integer, nullable=False)
    city = db.Column(db.String(20), nullable=False)
    state = db.Column(db.String(20), nullable=False)
    mobile = db.Column(db.Integer, nullable=False)

    def __repr__(self):
        return f"Address('{self.addressLine1}', '{self.addressLine2}', '{self.pincode}', '{self.city}', '{self.state}')"
Exemplo n.º 7
0
class Uploads(db.Model):
    __tablename__ = 'uploads'
    __table_args__ = tuple(
        UniqueConstraint('uploader',
                         'ipfs_hash',
                         name='uploader_ipfs_hash_unique_constraint'))

    id = db.Column(db.Integer, primary_key=True)
    uploader = db.Column(db.Integer, db.ForeignKey('credentials.id'))
    ipfs_hash = db.Column(db.Text())
    original_name = db.Column(db.Text())
    parent_hash = db.Column(db.Text())
    is_avatar = db.Column(db.Boolean(), default=False)
    date = db.Column(db.DateTime, server_default=func.now())
Exemplo n.º 8
0
class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text(50), nullable=False)
    category = db.Column(db.Text(20), nullable=False)
    description = db.Column(db.Text(150), nullable=False)
    price = db.Column(db.Integer, nullable=False)
    quantity = db.Column(db.Integer, nullable=True)
    photo_name = db.Column(db.Text, nullable=True)
    seller_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    cart_id = db.Column(db.Integer, db.ForeignKey('cart.id'))
    order_id = db.Column(db.Integer, db.ForeignKey('order.id'))

    def __repr__(self):
        return f"Product('{self.name}','{self.seller_id}', '{self.quantity}')"
Exemplo n.º 9
0
class Credentials(db.Model):
    __tablename__ = 'credentials'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True)
    token_hash = db.Column(db.Text())
    salt = db.Column(db.Text())

    def __init__(self, username, token, salt):
        self.username = username.lower()
        self.salt = salt
        self.token_hash = pbdkdf2_hash_base64(token, salt)

    def __repr__(self):
        return '<Credential %r>' % self.username
Exemplo n.º 10
0
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Text(), index=True, unique=True)
    email = db.Column(db.Text(), index=True, unique=True)
    password_hash = db.Column(db.Text())
    posts = db.relationship('Post', backref='author', lazy='dynamic')
    comments = db.relationship('Comment', backref='author', lazy='dynamic')
    about_me = db.Column(db.Text())
    last_seen = db.Column(db.DateTime, default=datetime.utcnow)
    followed = db.relationship('User',
                               secondary=followers,
                               primaryjoin=(followers.c.follower_id == id),
                               secondaryjoin=(followers.c.followed_id == id),
                               backref=db.backref('followers', lazy='dynamic'),
                               lazy='dynamic')

    def __repr__(self):
        return '<User {}>'.format(self.username)

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)

    def avatar(self, size):
        digest = md5(self.email.lower().encode('utf-8')).hexdigest()
        return 'https://www.gravatar.com/avatar/{}?d=identicon&s={}'.format(
            digest, size)

    def follow(self, user):
        if not self.is_following(user):
            self.followed.append(user)

    def unfollow(self, user):
        if self.is_following(user):
            self.followed.remove(user)

    def is_following(self, user):
        return self.followed.filter(
            followers.c.followed_id == user.id).count() > 0

    def followed_posts(self):
        followed = Post.query.join(
            followers, (followers.c.followed_id == Post.user_id)).filter(
                followers.c.follower_id == self.id)
        own = Post.query.filter_by(user_id=self.id)
        return followed.union(own).order_by(Post.timestamp.desc())
Exemplo n.º 11
0
class Company(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    picture = db.Column(db.String(100))
    name = db.Column(db.String(100), nullable=False, unique=True)
    bio = db.Column(db.Text())
    specialization = db.Column(db.String(100))
    username = db.Column(db.String(10), nullable=False, unique=True)
    email = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(20))

    role_type = db.Column(db.String(20), default="company" )
    updated_at = db.Column(db.DateTime, nullable = False, default=datetime.utcnow )
    created_at = db.Column(db.DateTime, nullable = False, default=datetime.utcnow )

    #Relationship
    comments = db.relationship('Comment', secondary=company_comment, backref='company_review')

    def __init__(self, picture, name, bio, specialization, username, email, password):
        
        self.picture = picture
        self.name = name
        self.bio = bio
        self.specialization = specialization
        self.username = username
        self.email = email
        self.password = password
Exemplo n.º 12
0
class Categories(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text(50))

    def __init__(self, **kwargs):
        super(Categories, self).__init__(**kwargs)
Exemplo n.º 13
0
class User(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String(255), nullable=True)
    email = db.Column(db.String(255), nullable=False)
    password = db.Column(db.Text())

    def __repr__(self):
        return "{username}'s account"

    def set_password(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def delete_account(self):
        db.session.delete(self)
        db.session.commit()

    def reset_password(self, old_password, new_password):
        if check_password_hash(self.password, old_password) and new_password:
            self.password = new_password
            db.session.commit()

    def save(self):
        db.session.add(self)
        db.session.commit()
Exemplo n.º 14
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    picture = db.Column(db.String(100))
    fname = db.Column(db.String(100))
    lname = db.Column(db.String(100))
    bio = db.Column(db.Text())
    username = db.Column(db.String(10), nullable=False, unique=True)
    email = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(20))

    # username = db.Column(db.String(10))
    role_type = db.Column(db.String(20), default="user" )
    comments = db.relationship( "Comment", backref="user", lazy=True )
    updated_at = db.Column(db.DateTime, nullable = False, default=datetime.utcnow )
    created_at = db.Column(db.DateTime, nullable = False, default=datetime.utcnow )

 
   
    def __init__(self, picture, fname, lname, bio, username, email, password):
        
        self.picture = picture
        self.fname = fname
        self.lname = lname
        self.bio = bio
        self.username = username
        self.email = email
        self.password = password
         
    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.bio}')"   
Exemplo n.º 15
0
class Reviews(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    id_user = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    id_cat = db.Column(db.Integer,
                       db.ForeignKey('categories.id'),
                       nullable=False)
    title = db.Column(db.Text(50))
    img = db.Column(db.Text(50))
    content = db.Column(db.Text(50))
    created_at = db.Column(db.Text(50))

    def __init__(self, id_user, id_cat, title, img, content, created_at):
        self.id_user = id_user
        self.id_cat = id_cat
        self.title = title
        self.img = img
        self.content = content
        self.created_at = created_at
Exemplo n.º 16
0
class Page(db.Model):
    __tablename__ = "pages"

    id = db.Column(db.Integer, primary_key=True)
    page_number = db.Column(db.Integer, nullable=False)
    page_content = db.Column(db.Text())
    book_id = db.Column(db.Integer, db.ForeignKey("books.id"), nullable=False)

    def __repr__(self):
        return f"<Page {self.page_number}, Book: {self.book_id}>"
Exemplo n.º 17
0
class User(db.Model):
    __tablename__ = "session"
    session_id = db.Column(db.Text(), primary_key=True)
    created_date = Column(DateTime, default=datetime.datetime.utcnow)

    def __init__(self, id):
        self.session_id = id

    def __repr__(self):
        return "%s" % (self.session_id)
Exemplo n.º 18
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.Text())
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    in_response_to = db.Column(db.Integer, db.ForeignKey('post.id'))
    dummy = db.Column(db.Integer)

    def __repr__(self):
        return '<Comment {}>'.format(self.body)
Exemplo n.º 19
0
class Project(db.Model):
    __tablename__ = 'Project'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    image = db.Column(db.String())
    description = db.Column(db.Text())
    category = db.Column(db.Integer)

    genre = db.relationship('Genre',
                            secondary=Project_Genre,
                            back_populates='project')
Exemplo n.º 20
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(15), unique=True, nullable=False)
    email = db.Column(db.String(50), unique=True, nullable=False)
    password = db.Column(db.Text(15), nullable=False)
    role = db.Column(db.String(10), nullable=False)
    products = db.relationship('Product', backref='seller', lazy=True)
    addressess = db.relationship('Address', backref='customer', lazy=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}')"
Exemplo n.º 21
0
class Message(db.Model):
    """
    Message model
    """
    __tablename__ = 'message'
    id = Column(Integer, autoincrement=True, primary_key=True)
    title = Column(String(200))
    adresser = Column(String(20), default='')
    author = Column(String(20), default='')
    created = Column(db.DateTime(), nullable=False)
    content = Column(db.Text())
    new = Column(Boolean, default=True)
Exemplo n.º 22
0
class Usercontent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.Integer,
                         db.ForeignKey('user.username', ondelete='CASCADE'))
    user = db.relationship('User', backref=db.backref('usercontent_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    filename = db.Column(db.String(200), nullable=False)
    voter = db.relationship('User',
                            secondary=usercontent_like_voter,
                            backref=db.backref('usercontent_voter_set'))
Exemplo n.º 23
0
class Message(db.Model, TimestampMixin):
    __tablename__ = 'messages'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    user = db.relationship('User')
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'))
    room = db.relationship('Room')
    content = db.Column(db.Text(collation='utf8mb4_unicode_ci'))
    status = db.Column(db.String(50))

    def __init__(self, *args, **kwargs):
        super(Message, self).__init__(*args, **kwargs)
Exemplo n.º 24
0
class Article(db.Model):
    __tablename__ = 'articles'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text(), nullable=False)
    post_date = db.Column(db.DateTime(), nullable=False)

    def __repr__(self):
        return '<Article %r>' % self.title

    @classmethod
    def __declare_last__(cls):
        ValidateString(Article.title, False, False, "Aww")
Exemplo n.º 25
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    subject = db.Column(db.String(200), nullable=False)
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False)
    # user 속성은 Post모델에서 계정모델(User)을 참조하기 위해서 추가된 속성으로 post.user.username과 같이 사용된다.
    user = db.relationship('User', backref=db.backref('post_set'))
    voter = db.relationship('User',
                            secondary=post_voter,
                            backref=db.backref('post_voter_set'))
Exemplo n.º 26
0
class ScopusAbstract(db.Model):
    __tablename__ = 'scopus_abstracts'
    id = db.Column(db.Integer(), primary_key=True)
    url = db.Column(db.Text())
    identifier = db.Column(db.UnicodeText())
    pii = db.Column(db.UnicodeText())
    doi = db.Column(db.UnicodeText())
    eid = db.Column(db.UnicodeText())
    title = db.Column(db.Text())
    publication_name = db.Column(db.UnicodeText())
    citedby_count = db.Column(db.Integer())
    cover_date = db.Column(db.DateTime())
    description = db.Column(db.UnicodeText())
    authors = db.relationship('ScopusAuthor',
                              secondary=author_abstracts,
                              backref=db.backref('abstracts', lazy='dynamic'))
    fundings = db.relationship('Funding',
                               secondary=funding_abstracts,
                               backref=db.backref('abstracts', lazy='dynamic'))

    def __repr__(self):
        return "<ScopusAbstract title=%s, doi=%s>" % \
                                (self.title[:20], self.doi)
Exemplo n.º 27
0
class Jam(db.Model):
    """

    Jam model
    """
    __tablename__ = 'jam'
    id = Column(Integer, autoincrement=True, primary_key=True)
    title = Column(String(20), unique=True)
    theme = Column(String(100))
    description = Column(db.Text())
    master_email = Column(String(200))
    master = Column(String(200))
    teams = Column(PickleType())
    active = Column(Boolean, default=True)
Exemplo n.º 28
0
class Reply(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id',
                                                  ondelete='CASCADE'))
    post = db.relationship('Post', backref=db.backref('reply_set'))
    content = db.Column(db.Text(), nullable=False)
    create_date = db.Column(db.DateTime(), nullable=False)
    modify_date = db.Column(db.DateTime(), nullable=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False)
    user = db.relationship('User', backref=db.backref('reply_set'))
    voter = db.relationship('User',
                            secondary=reply_voter,
                            backref=db.backref('reply_voter_set'))
Exemplo n.º 29
0
class ScopusAuthor(db.Model):
    __tablename__ = 'scopus_authors'
    id = db.Column(db.Integer(), primary_key=True)
    affil_id = db.Column(db.Integer(), db.ForeignKey('scopus_affiliations.id'))
    initials = db.Column(db.String(8))
    #indexed_name = db.Column(db.String(255))
    surname = db.Column(db.UnicodeText())
    given_name = db.Column(db.UnicodeText())
    preferred_name = db.Column(db.UnicodeText())
    url = db.Column(db.Text())
    affiliation = db.relationship('ScopusAffiliation',
                                  backref=db.backref('authors',
                                                     lazy='dynamic'))

    def __repr__(self):
        return "<ScopusAuthor name=%s>" % \
                (self.indexed_name.encode('utf8'))
Exemplo n.º 30
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True, nullable=False)
    image_file = db.Column(db.String(100),
                           nullable=False,
                           default='default.jpg')
    email = db.Column(db.String(30), unique=True, nullable=False)
    mobile = db.Column(db.Integer, unique=True, nullable=False)
    password = db.Column(db.Text(20), nullable=False)
    address = db.Column(db.String(100), unique=False, nullable=False)
    city = db.Column(db.String(20), unique=False, nullable=False)
    state = db.Column(db.String(20), unique=False, nullable=False)
    zip = db.Column(db.Integer, unique=False, nullable=False)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)

        return s.dumps({'user_id': self.id}).decode('utf-8')