class Problems(db.Model): __tablename__ = 'problems' id = db.Column(db.Integer(), primary_key=True) assignment_id = db.Column(db.Integer(), db.ForeignKey('assignment.id')) assignment = db.relationship("Assignment", backref=db.backref('problems', order_by=id)) acid = db.Column(db.String(255))
class UserGrades(db.Model): __tablename__ = 'user_grades' id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) user = db.relationship("User", backref=db.backref('grades', order_by=id)) assignment_id = db.Column(db.Integer(), db.ForeignKey('assignment.id')) assignment = db.relationship("Assignment", backref=db.backref('grades', order_by=id)) score = db.Column(db.Numeric())
class Place(db.Model): __tablename__ = 'place' id = db.Column(db.Integer(), primary_key=True) camera_id = db.Column(db.Integer(), db.ForeignKey('%s.id' % Camera.__tablename__)) status = db.Column(db.Boolean(), server_default='false') label = db.Column(db.String(), nullable=False) x = db.Column(db.Integer(), nullable=False) y = db.Column(db.Integer(), nullable=False) _idx = db.Index('camera_label_idx', 'camera_id', 'label', unique=True)
class Deadlines(db.Model): __tablename__ = 'deadlines' id = db.Column(db.Integer(), primary_key=True) assignment_id = db.Column(db.Integer(), db.ForeignKey('assignment.id')) assignment = db.relationship("Assignment", backref=db.backref('deadlines', order_by=id)) section_id = db.Column(db.Integer(), db.ForeignKey('section.id')) section = db.relationship("Section", backref=db.backref('deadlines', order_by=id)) deadline = db.Column(db.DateTime()) acid = db.Column(db.String(255))
class AssignmentType(db.Model): __tablename__ = 'assignment_type' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(255)) grade_type = db.Column(db.Enum('additive', 'checkmark', 'use'), default='additive') weight = db.Column(db.Numeric(), default=1.0) points_possible = db.Column(db.Integer(), default=0) assignments_count = db.Column(db.Integer(), default=0) assignments_dropped = db.Column(db.Integer(), default=0) def __repr__(self): return self.name
class Account(db.Model): __tablename__ = 'account' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(), nullable=False) places = db.Column(JSONB(), nullable=False, server_default='{}') @staticmethod async def redis_get_id(redis, access_token): id = await redis.get('%s_id' % access_token) return int(id) if id is not None else id @staticmethod async def redis_set_id(redis, access_token, id): await redis.set('%s_id' % access_token, str(id)) @staticmethod async def redis_get_username(redis, access_token): username = await redis.get('%s_username' % access_token) return username.decode('utf-8') if username is not None else username @staticmethod async def redis_set_username(redis, access_token, username): await redis.set('%s_username' % access_token, username) @staticmethod async def redis_delete(redis, access_token): await redis.delete('%s_id' % access_token) await redis.delete('%s_username' % access_token)
class Assignment(db.Model): __tablename__ = 'assignment' id = db.Column(db.Integer(), primary_key=True) course_id = db.Column(db.Integer(), db.ForeignKey('course.id')) course = db.relationship("Course", backref=db.backref('assignments', order_by=id)) type_id = db.Column(db.Integer(), db.ForeignKey('assignment_type.id')) type = db.relationship("AssignmentType", backref=db.backref('assignments', order_by=id)) name = db.Column(db.String(255)) points = db.Column(db.Integer()) threshold = db.Column(db.Integer(), default=1) released = db.Column(db.Boolean()) def __repr__(self): return self.name
class Post(db.Model, SerializerMixin): __tablename__ = 'post' id = db.Column(db.Integer(), primary_key=True) content = db.Column(db.String(200), nullable=True) created_time = db.Column(db.DateTime, default=datetime.datetime.utcnow) def __init__(self, content): self.content = content
class query_data(db.Model): __tablename__ = 'query_data' id = db.Column(db.Integer(), primary_key=True) query = db.Column(db.String(255)) user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete="CASCADE")) user = db.relationship('User', back_populates="queries") def __str__(self): return self.query
class Pet(db.Model): __tablename__ = 'pets' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(64)) breed = db.Column(db.String(10)) def __init(self, name, breed): self.name = name self.breed = breed def __repr__(self): return {'name': self.name, 'breed': self.breed} def json(self): return {'name': self.name, 'breed': self.breed}
class TaskAssignment(db.Model): __tablename__ = 'taskAssignments' id = db.Column(db.Integer, primary_key=True) start_date = db.Column('start_date', db.DateTime(), default=datetime.datetime.now) end_date = db.Column(db.DateTime, nullable=True) user_id = db.Column(db.Integer()) task_id = db.Column(db.Integer, db.ForeignKey('tasks.id')) task = db.relationship("Task", back_populates="assignments") def __init__(self, task_id, user_id): self.task_id = task_id self.user_id = user_id
class FlaskTable(db.Model): __tablename__ = 'fadfsd' id = db.Column(db.Integer(), primary_key=True) dafef = db.Column(db.DATETIME()) # class OneTable(db.Model): # __bind_key__ = 'db_one' # __tablename__ = 'fadfsd' # id = db.Column(db.Integer(),primary_key=True) # dafef = db.Column(db.DATETIME()) # # class TwoTable(db.Model): # __bind_key__ = 'db_two' # __tablename__ = 'fadfsd' # id = db.Column(db.Integer(),primary_key=True) # dafef = db.Column(db.DATETIME())
class Owner(db.Model,UserMixin): __tablename__ = 'owners' id = db.Column(db.Integer(),primary_key=True) email = db.Column(db.String(60)) name = db.Column(db.String(64)) password = db.Column(db.String(128)) def __init(self,name,email,password): self.name = name self.email = email self.password = generate_password_hash(password) def __repr__(self): return {'name': self.name, 'email' : self.email} def __str__(self): return f"User {self.name} has Email {self.email}" def json(self): return {'name': self.name, 'email' : self.email } def check_password(self,password): return check_password_hash(self.password, password)
class User(db.Model, Base, EntityBase): __tablename__ = 'user' id = db.Column(guid(), primary_key=True) username = db.Column(db.String(255), unique=True, nullable=False) facebook = db.Column(db.String(255)) skype = db.Column(db.String(255)) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) dob = db.Column(db.Integer()) email = db.Column(db.String(255), unique=True, nullable=False) photo = db.Column(db.String(255)) _password = db.Column(db.String(4000), name='password') about = db.Column(db.String(4000)) @property def entity_type(self): return EntityBase.TYPE_USER @property def resource_type(self): from models.acl import AclResource return AclResource.USER @property def password(self): # No one should be able to find user's password return None @password.setter def password(self, password): from werkzeug.security import generate_password_hash self._password = generate_password_hash(password) def check_password(self, password): from werkzeug.security import check_password_hash return check_password_hash(self._password, password) def is_allowed(self, resource, privilege): from models.acl import acl_manager return acl_manager.is_allowed(self, resource, privilege)
class User(UserMixin, db.Model): """ 用户表 """ __tablename__ = 'user' id = db.Column(db.Integer(), primary_key=True) # 小程序 user_info openId = db.Column(db.String(128), unique=True) nickName = db.Column(db.String(50)) gender = db.Column(db.Integer(), server_default='0') # 1 男 0 女 city = db.Column(db.String(120)) province = db.Column(db.String(120)) country = db.Column(db.String(120)) avatarUrl = db.Column(db.String(200)) # 阅读器配置 preference = db.Column(db.Integer(), server_default='0') # 0 女 1 男 brightness = db.Column(db.Integer(), server_default='30') # 10~100 亮度 fontSize = db.Column(db.Integer(), server_default='14') # 字号 background = db.Column(db.String(10), default='B1') # B1 ~ B6 内置背景 turn = db.Column(db.String(10), default='T1') # T1 仿真 T2 平滑 T3 无 翻页模式 last_read = db.Column(db.Integer()) # 最后阅读一本书 last_read_chapter_id = db.Column(db.Integer()) # 最后阅读一本书的章节id modified = db.Column(db.DateTime(), server_default=func.now()) created = db.Column(db.DateTime(), server_default=func.now()) def __init__(self, data): self.openId = data['openId'] self.update_info(data) def update_info(self, data): self.nickName = data['nickName'] self.gender = data['gender'] self.city = data['city'] self.province = data['province'] self.country = data['country'] self.avatarUrl = data['avatarUrl']