Example #1
0
class Admin(BaseModel):
    __tablename__ = 'admin_users'
    username = Column('username', db.String(40))
    _password = Column('password', db.String(100))
    name = Column('name', db.String(40))
    avatar = Column('avatar', db.String(100))
    operations = relationship('OperationLog', backref='admin', lazy='dynamic')
    default_json_fields = ['id', 'username', 'name', 'avatar', 'updated_at']

    @staticmethod
    def generate_password(password):
        return generate_password_hash(password)

    def verify_password(self, password):
        try:
            result = check_password_hash(self.password, password)
        except:
            return False
        return result

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, value):
        self._password = generate_password_hash(value)

    def __repr__(self):
        return self.name
Example #2
0
class Module(BaseModel):
    __tablename__ = 'modules'
    order = Column('order', db.Integer)
    title = Column('title', db.String(40))
    template_id = Column('template_id', db.String(40))
    child = relationship('Article', backref='module', lazy='dynamic')
    default_json_fields = ['order', 'template_id', 'id', 'child', 'title']

    def __repr__(self):
        return self.title
Example #3
0
class ExpressionOffical(BaseModel):
    __tablename__ = 'expression_offical'
    name = Column('name', db.String(40))
    tel = Column('tel', db.String(40))
    phone_model = Column('phone_model', db.String(40))
    destination = Column('destination', db.String(40))
    departure_time = Column('departure_time', db.String(40))
    return_time = Column('return_time', db.String(40))
    airport = Column('airport', db.String(40))
    terminal = Column('terminal', db.String(40))
Example #4
0
class OperationLog(BaseModel):
    __tablename__ = 'admin_operation_log'
    user_id = Column('user_id', db.Integer, db.ForeignKey('admin_users.id'))
    path = Column('path', db.String(40))
    method = Column('method', db.String(15))
    ip = Column('ip', db.String(15))
    input = Column('input', db.JSON)
    default_json_fields = [
        'id', 'user', 'path', 'method', 'ip', 'input_summary', 'created_at'
    ]

    @hybrid_property
    def user(self):
        return str(self.admin) if self.admin else ''

    @hybrid_property
    def input_summary(self):
        return str(self.input)[:300] if self.input else ''
Example #5
0
class Article(BaseModel):
    __tablename__ = 'articles'
    title = Column('title', db.String(40))
    content = Column('content', db.Text)
    thumb_pic = Column('thumb_pic', db.String(100))
    order = Column('order', db.Integer)
    module_id = Column('module_id', db.Integer, db.ForeignKey('modules.id'))

    default_json_fields = [
        'title', 'order', 'id', 'thumb_pic', 'summary', 'updated_at',
        'module_name', 'module_id'
    ]

    @hybrid_property
    def summary(self):
        return self.content[:100]

    @hybrid_property
    def module_name(self):
        return str(self.module) if self.module else ''