Пример #1
0
class Institution(db.Model):

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(250), nullable=False)

    photo = db.Column(db.String(250), nullable=True)

    managers = db.relationship('Manager',
                               backref='institution',
                               lazy=True,
                               cascade="all, delete-orphan")

    classes = db.relationship('Class',
                              backref='institution',
                              lazy=True,
                              cascade="all, delete-orphan")

    students = db.relationship(Student,
                               secondary=relation_student_institution,
                               backref='institutions')

    def __repr__(self):
        return self.name
Пример #2
0
class Album(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    userId = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', backref='albums')
    title = db.Column(db.String(40), nullable=False)

    @staticmethod
    def save(user_id, **kwargs):
        album = Album(userId=user_id, **kwargs)
        db.session.add(album)
        db.session.commit()
        return album

    @staticmethod
    def update(id, **kwargs):
        album = Album.query.filter_by(id=id).update(kwargs)
        db.session.commit()
        return Album.query.get(id)

    @staticmethod
    def delete(album):
        db.session.delete(album)
        db.session.commit()
        return True
Пример #3
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(50), unique=True, nullable=False)
    email = db.Column(db.String(70), unique=True, nullable=False)
    password_hash = db.Column(db.String(256), unique=False, nullable=False)
    money = db.Column(db.Integer, nullable=False, default=100)

    frogs = db.relationship('Frog', backref='owner', lazy=True)

    def __init__(self, username, email, password):
        self.username = username
        self.email = email
        self.set_password(password)

    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 __repr__(self):
        return f'<User {self.id}>'
Пример #4
0
class Users(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    email = db.Column(db.String(50))
    username = db.Column(db.String(25))
    password = db.Column(db.String(100))
    mobile = db.Column(db.String(20))
    reg_time = db.Column(db.String, default=datetime.utcnow)
    online = db.Column(db.String(1), default=0)
    activation = db.Column(db.String(3))

    def __init__(self, name, email, username, password, mobile, reg_time, online, activation):
        self.name = name
        self.email = email
        self.username = username
        self.password = password
        self.mobile = mobile
        self.reg_time = reg_time
        self.online = online
        self.activation = activation
Пример #5
0
 class User(db.Model):
     id = db.Column(db.Interger, primary_key=True)
     username  = db.Column(db.String(120),unique=True)
     phone_num = db.Column(db.String(120),unique=True)
     password  = db.Column(db.String(120))
     like      = db.Column(db.String(1200))
     dislike   = db.Column(db.String(1200))
     exiting   = db.Column(db.String)
     def __init__(self,username,password,exiting):
         self.username  =  username
         self.password  =  password
         self.exiting   =  exiting
     def __repr__(self):
         return "<ACCOUNT NAME IS %r>"%self.username
Пример #6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20), nullable=False,
                           default='default_1.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)
    active = db.Column(db.Boolean, unique=False, default=True)
    admin_level = db.Column(db.Integer, unique=False, default=0)


    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}', '{self.admin_level})"
Пример #7
0
class Frog(db.Model):
    __tablename__ = 'frogs'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=False, nullable=False)
    food = db.Column(db.Integer, nullable=False, default=0)
    cleanliness = db.Column(db.Integer, nullable=False, default=0)
    money = db.Column(db.Integer, nullable=False, default=0)
    image_id = db.Column(db.Integer,
                         db.ForeignKey('images.id'),
                         nullable=False)
    owner_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    last_request = db.Column(UtcDateTime(), default=utcnow(), nullable=False)

    image = db.relationship("Image", backref=db.backref("frog", uselist=False))

    def __repr__(self):
        return f'<Frog {self.id}; {self.name}>'
Пример #8
0
class CrewLevel(db.Model):

    __tablename__ = 'crew_level'
    __bind_key__ = 'hrms'
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    id = db.Column(db.BigInteger,
                   primary_key=True,
                   nullable=False,
                   autoincrement=True)
    crew_id = db.Column(db.BigInteger, default=0, nullable=False)  # 员工帐号
    level = db.Column(db.Integer, default=0)  # 员工手机号
    level_name = db.Column(db.String(128), default='', nullable=False)  # 身份证号
    accumulate_work_days = db.Column(db.Integer, default=0)  # 累计工作天数
    meta = db.Column(db.String(512, collation='utf8_unicode_ci'),
                     default='')  # 其他信息
    is_del = db.Column(db.SmallInteger, default=0)  #是否删除:0-未删除;1-删除
    create_time = db.Column(db.Integer, default=0)  #创建时间
Пример #9
0
class CrewProjMap(db.Model):

    __tablename__ = 'crew_proj_map'
    __bind_key__ = 'hrms'
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    id = db.Column(db.BigInteger,
                   primary_key=True,
                   nullable=False,
                   autoincrement=True)
    crew_id = db.Column(db.BigInteger, default=0, nullable=False)  # 员工帐号
    proj_id = db.Column(db.Integer, default=0)  # 项目编号
    start_time = db.Column(db.Integer, default=0)  # 开工时间
    end_time = db.Column(db.Integer, default=0)  # 结束时间
    entry_status = db.Column(db.SmallInteger,
                             default=0)  #审核状态:0-报名,1-审核通过/已入职,2-审核驳回
    is_del = db.Column(db.SmallInteger, default=0)  #是否删除:0-未删除;1-删除
    create_time = db.Column(db.Integer, default=0)  #创建时间
Пример #10
0
class UserProjRightsMap(db.Model):
    __tablename__ = 'user_proj_rights_map'
    __bind_key__ = 'hrms'
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    manager_id = db.Column(db.Integer, default=0, nullable=False)  # 管理员编号
    company_id = db.Column(db.Integer, default=0, nullable=False)  # 公司编号
    proj_id = db.Column(db.Integer, default=0, nullable=False)  # 项目编号
    is_del = db.Column(db.SmallInteger, default=0)  # 是否删除:0-未删除;1-删除
    create_time = db.Column(db.Integer, default=0)  # 创建时间
Пример #11
0
class Supplier(db.Model):
    __tablename__ = 'supplier'
    __bind_key__ = 'hrms'
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    org_id = db.Column(db.Integer, default=0)  # 所属公司编号
    supplier_name = db.Column(db.String(64), default='', nullable=False)  # 项目名称
    parent_id = db.Column(db.Integer, default=0)  # 所属公司编号
    is_del = db.Column(db.SmallInteger, default=0)  # 是否删除:0-未删除;1-删除
    create_time = db.Column(db.Integer, default=0)  # 创建时间
Пример #12
0
class Admin(db.Model):
    __tablename__ = 'admin'
    id = db.Column(db.Integer, primary_key=True)
    firstname = db.Column(db.String(125))
    lastname = db.Column(db.String(125))
    email = db.Column(db.String(100))
    mobile = db.Column(db.String(25))
    address = db.Column(db.String)
    password = db.Column(db.String(100))
    type = db.Column(db.String(20))
    confirmcode = db.Column(db.String(10))

    def __init__(self, firstname, lastname, email, mobile, address,
                 password, type, confirmcode):
        self.firstname = firstname
        self.lastname = lastname
        self.email = email
        self.mobile = mobile
        self.address = address
        self.password = password
        self.type = type
        self.confirmcode = confirmcode
Пример #13
0
class DwBillboardPoints(db.Model):
    __tablename__ = 'dw_billboard_points'
    __bind_key__ = 'hrms'
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    dataset_id = db.Column(db.Integer, default=0)  # 所属公司编号
    rank_table = db.Column(db.TEXT)  # 项目名称
    rank_time = db.Column(db.Integer, default=0)  # 所属公司编号
    is_del = db.Column(db.SmallInteger, default=0)  # 是否删除:0-未删除;1-删除
    create_time = db.Column(db.Integer, default=0)  # 创建时间
Пример #14
0
class Transaction(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    symbol = db.Column(db.String(10), nullable=False)
    price = db.Column(db.Numeric, nullable=False)
    quantity = db.Column(db.Integer, nullable=False)
    transacted = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)

    def __repr__(self):
        return f"Transaction('{self.user_id}', '{self.symbol}', '{self.transacted}')"
Пример #15
0
class DwChartPoints(db.Model):
    __tablename__ = 'dw_chart_points'
    __bind_key__ = 'hrms'
    __table_args__ = {"mysql_engine": "InnoDB", "mysql_charset": "utf8"}

    id = db.Column(db.Integer, primary_key=True, nullable=False)
    dataset_id = db.Column(db.Integer, default=0)  # 所属公司编号
    x_time = db.Column(db.Integer, default=0)  # 所属公司编号
    y_value = db.Column(db.DECIMAL(precision=10, scale=2),
                        default=0.00)  # 所属公司编号
    is_del = db.Column(db.SmallInteger, default=0)  # 是否删除:0-未删除;1-删除
    create_time = db.Column(db.Integer, default=0)  # 创建时间
Пример #16
0
class ContactUs(db.Model):

    __tablename__ = 'contactus'

    id = db.Column(db.Integer, primary_key=True)
    sender = db.Column(db.String(120))
    email = db.Column(db.String(245))
    phone = db.Column(db.String(120))
    note = db.Column(db.String(255))
    sent_at = db.Column(db.DateTime, default=db.func.now())
    sender_ip = db.Column(db.String(15))
    last_browser = db.Column(db.String(254))
    read = db.Column(db.Boolean, nullable=False, default=False)

    def __init__(self, sender, email, note, sender_ip):
        self.sender = sender
        self.email = email
        #self.phone=phone
        self.note = note
        self.sender_ip = sender_ip

    def __repr__(self):
        return '<Contact Us %r>' % (self.sender)
Пример #17
0
class Content(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    json = db.Column(JsonEncodedDict)
    contentType = db.Column(EnumType(ContentTypeEnum))
    update_date = db.Column(db.DateTime)
    watched = db.Column(db.Boolean)
    plays = db.Column(db.Integer)

    uniqueIds = db.relationship('UniqueId',
                                secondary=uniqueid_to_content,
                                backref='uniqueId',
                                lazy=True)

    show_id = db.Column(db.Integer, db.ForeignKey('content.id'), nullable=True)
    episodes = db.relationship('Content',
                               remote_side=[show_id],
                               lazy='dynamic')

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __init__(self, json, contentType, user_id, watched=False, show=None):
        self.json = json
        self.contentType = contentType
        self.user_id = user_id
        self.watched = watched
        self.plays = 1 if watched else 0
        self.show = show

    def __repr__(self):
        return '<Content %d, type=%s>' % (self.id, self.contentType)

    def to_json(self):
        result = copy.copy(self.json)
        result.update({
            'ids':
            dict((uniqueId.source, uniqueId.value)
                 for uniqueId in list(self.uniqueIds))
        })
        result.update({'show_id': self.show_id})
        result.update({'id': self.id})
        result.update({'watched': self.watched})
        return result
Пример #18
0
class Event(db.Model):

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(250), nullable=False)

    description = db.Column(db.String(500), nullable=True)

    photo = db.Column(db.String(250), nullable=True)

    class_id = db.Column(db.Integer, db.ForeignKey('class.id'), nullable=False)

    date = db.Column(db.String(250), nullable=True)
Пример #19
0
class Category(db.Model):
    __tablename__ = 'categories'
    id = db.Column(db.Integer, primary_key=True)
    c_name = db.Column(db.String(50), nullable=False)
    c_description = db.Column(db.String(100))
    c_thumbnail = db.Column(db.String(50))
    created_at = db.Column(db.DateTime, server_default=db.func.now())
    updated_at = db.Column(db.DateTime,
                           server_default=db.func.now(),
                           server_onupdate=db.func.now())

    def __repr__(self):
        return f"Category({self.id}, '{self.c_name}', '{self.c_description}','{self.c_thumbnail}', {self.created_at}, {self.updated_at} '{self.c_thumbnail}')"
Пример #20
0
class TicketItemModel(db.Model):
    __tablename__ = 'ticket_item'

    order_item_id = db.Column(db.Integer, primary_key=True)
    ticket_id = db.Column(db.Integer)
    menu_id = db.Column(db.Integer)
    ingredients_added = db.Column(db.String)
    ingredients_removed = db.Column(db.String)
    remark = db.Column(db.String)
    item_status = db.Column(db.String)
    quantity = db.Column(db.Integer)

    def __init__(self, ticket_id, menu_id, ingredients_added, ingredients_removed, remark, quantity):
        self.ticket_id = ticket_id
        self.menu_id = menu_id
        self.ingredients_added = ingredients_added
        self.ingredients_removed = ingredients_removed
        self.remark = remark
        self.item_status = 'Order Sent'
        self.quantity = quantity
Пример #21
0
class Manager(db.Model):

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(250), nullable=False)

    cpf = db.Column(db.String(50), nullable=False)

    phone = db.Column(db.String(50), nullable=False)

    email = db.Column(db.String(250), unique=True, nullable=False)

    password = db.Column(db.String(250), nullable=False)

    active = db.Column(db.Boolean, nullable=False, default=False)

    institution_id = db.Column(db.Integer,
                               db.ForeignKey('institution.id'),
                               nullable=False)

    photo = db.Column(db.String(250), nullable=True)

    def __repr__(self):
        return self.email
Пример #22
0
class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    price = db.Column(db.Integer, nullable=False)
    quantity = db.Column(db.Integer, nullable=False)
    description = db.Column(db.String(100), default="No description")
    image_url = db.Column(db.String(50), default="default.jpg")
    restaurant_id = db.Column(db.Integer, db.ForeignKey("vendor.id"))
    orders = db.relationship("Order", backref="products", lazy=True)
    category = db.relationship("Category",
                               secondary="categories",
                               lazy="subquery",
                               backref=db.backref("items", lazy=True))
    rating = db.relationship("Review",
                             secondary="ratings",
                             lazy="subquery",
                             backref=db.backref("product", lazy=True))
Пример #23
0
class Message(db.Model):
    __tablename__ = 'messages'
    # nonvolatile data stored in the db
    id = db.Column(db.Integer, primary_key=True)
    recipient_email = db.Column(db.String, db.ForeignKey('users.email'))
    recipient = db.relationship("User",
                                backref=db.backref("messages", uselist=True))
    sender_name = db.Column(db.String(120), default="")
    subject = db.Column(db.String(120), default="")
    message_html = db.Column(db.UnicodeText(), default="")
    message_send_date = db.Column(ArrowType, default=arrow.utcnow)
    message_read = db.Column(db.Boolean, default=False)

    def __repr__(self):
        return '<Message from {} to {} with subject "{}" [{}] >'.format(
            self.sender_name, self.recipient_name, self.subject,
            self.message_send_date)
Пример #24
0
class Token(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    client_id = db.Column(db.String(40),
                          db.ForeignKey('client.client_id'),
                          nullable=False)
    client = db.relationship('Client')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User')
    token_type = db.Column(db.String(40))
    access_token = db.Column(db.String(255), unique=True)
    refresh_token = db.Column(db.String(255), unique=True)
    expires = db.Column(db.DateTime)
    scopes = ['']

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

    @staticmethod
    def find(access_token=None, refresh_token=None):
        if access_token:
            return Token.query.filter_by(access_token=access_token).first()
        elif refresh_token:
            return Token.query.filter_by(refresh_token=refresh_token).first()

    @staticmethod
    def save(token, request, *args, **kwargs):
        toks = Token.query.filter_by(client_id=request.client.client_id,
                                     user_id=request.user.id)

        [db.session.delete(t) for t in toks]

        expires_in = token.pop('expires_in')
        expires = datetime.utcnow() + timedelta(seconds=expires_in)

        tok = Token(
            access_token=token['access_token'],
            refresh_token=token['refresh_token'],
            token_type=token['token_type'],
            expires=expires,
            client_id=request.client.client_id,
            user_id=request.user.id,
        )
        db.session.add(tok)
        db.session.commit()
Пример #25
0
class Orders(db.Model):
    __tablename__ = 'orders'
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer)
    ofname = db.Column(db.String)
    quantity = db.Column(db.Integer)
    mobile = db.Column(db.String(15))
    email = db.Column(db.String(100))
    # mpesacode = db.Column(db.String(10))
    odate = db.Column(db.String, nullable=False, default=datetime.now)

    def __init__(self, uid, ofname, quantity, mobile, email, odate):
        self.uid = uid
        self.ofname = ofname
        self.quantity = quantity
        self.mobile = mobile
        self.email = email
        self.odate = odate
Пример #26
0
class TokenBlacklist(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(36), nullable=False)
    token_type = db.Column(db.String(10), nullable=False)
    user_identity = db.Column(db.String(50), nullable=False)
    revoked = db.Column(db.Boolean, nullable=False)
    expires = db.Column(db.DateTime, nullable=False)
    created_at = db.Column(db.DateTime, server_default=db.func.now())
    updated_at = db.Column(db.DateTime, server_default=db.func.now(), server_onupdate=db.func.now())

    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
        }

    def __repr__(self):
        return f"TokenBlacklist('jti : {self.jti}', 'token_type: {self.token_type}','user_identity: {self.user_identity}', 'revoked: {self.revoked}', 'expires: {self.expires}', 'created_at: {self.created_at}')"
Пример #27
0
class FinancialEvent(db.Model, PolymorphicMixin, SearchMixin):
    """Represents a financial event, like a debit or credit."""
    id = db.Column(db.Integer, primary_key=True)
    account_id = db.Column(db.Integer, db.ForeignKey('financial_account.id', ondelete='CASCADE'), nullable=False)
    originator_id = db.Column(db.Integer, db.ForeignKey('entity.id'))

    date = db.Column(db.DateTime, default=lambda: datetime.utcnow())
    net = db.Column(CURRENCY)
    description = db.Column(db.Text)

    account = db.relationship('FinancialAccount', back_populates='events')
    originator = db.relationship('Entity', back_populates='financials')

    def __repr__(self):
        return f'<{type(self).__name__} {self.net} {self.description}>'
Пример #28
0
class Request(db.Model):
    __tablename__ = 'request'
    id = db.Column(db.Integer,primary_key=True)
    category = db.Column(db.String(20))
    title = db.Column(db.String(50))
    pubmonth = db.Column(db.String(20))
    description = db.Column(db.String)
    status = db.Column(db.String(15))

    def __init__(self, category, title, pubmonth, description, status):
        self.category = category
        self.title = title
        self.pubmonth = pubmonth
        self.description = description
        self.status = status
Пример #29
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(45))
    last_name = db.Column(db.String(45))
    email = db.Column(db.String(45))
    created_at = db.Column(db.DateTime, server_default=func.now())
    updated_at = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())

    # c stands for column 
    right_users = db.relationship("User",
                        secondary="user_to_user",
                        primaryjoin="User.id==user_to_user.c.left_user_id",
                        secondaryjoin="User.id==user_to_user.c.right_user_id",
                        backref="left_users")

    tweets_this_user_likes = db.relationship('Tweet', secondary=likes_table)
Пример #30
0
class DriveModel(db.Model):
    __tablename__ = 'drives'

    id = db.Column(db.String(), primary_key=True)
    game_id = db.Column(db.String(), db.ForeignKey('games.id'))
    drive_index = db.Column(db.Integer(), nullable=False)
    team_name = db.Column(db.String(), nullable=False)
    drive_result = db.Column(db.String())
    points_gained = db.Column(db.Integer())
    drive_total_time_sec = db.Column(db.Integer())

    series = db.relationship('SeriesModel')
    plays = db.relationship('PlayModel')


    def __init__(self, id, game_id, drive_index, team_name, drive_result=None, points_gained=None, drive_total_time_sec=None):
        self.id = id
        self.game_id = game_id
        self.team_name = team_name
        self.drive_result = drive_result
        self.points_gained = points_gained
        self.drive_total_time_sec = drive_total_time_sec
        self.drive_index = drive_index

    def get_description(self):
        if (self.drive_result is None):
            return 'Drive in progress.'
        return f'Drive complete for {self.team_name}. The drive ended in a {self.drive_result} and took {self.drive_total_time_sec} seconds. '

    def toJSON(self):
        return {
            'type': 'drive',
            'id': self.id,
            'game_id': self.game_id,
            'team_name': self.team_name,
            'drive_result': self.drive_result,
            'points_gained': self.points_gained,
            'drive_total_time_sec': self.drive_total_time_sec,
            'drive_index': self.drive_index,
            'desc': self.get_description()
        }