class MomoPaymentRequest(db.Model): __tablename__ = "momo_payment_request" id = db.Column(db.Integer, primary_key=True, nullable=False, autoincrement=True, unique=True) transaction_id = db.Column(db.VARCHAR(60), nullable=False) amount = db.Column(db.Float, default=0) currency = db.Column(db.CHAR(4), nullable=False) payer_party_id = db.Column( db.VARCHAR(30), nullable=False) # Payment method used by the individual payer_party = db.Column( db.VARCHAR(30), nullable=False) # Phone number or credential of the individual status = db.Column( db.CHAR(10), nullable=False) # Status of payment approval transaction end party product_id = db.Column(db.VARCHAR(100), nullable=False) # Expected product id date_added = db.Column(db.DateTime(timezone=True), server_default=func.now()) date_modified = db.Column(db.DateTime(timezone=True), server_default=func.now(), onupdate=datetime.now) def __int__(self, transaction_id: str): self.transaction_id = transaction_id
class customer(db.Model): __tablename__ = 'customer' id = db.Column(db.Integer, primary_key=True) fname = db.Column(db.CHAR(32)) lname = db.Column(db.CHAR(32)) phone = db.Column(db.CHAR(13)) address = db.Column(db.CHAR(256))
class RegisterModel(db.Model): '''注册码''' __tablename__ = 'register' id = db.Column(db.Integer, autoincrement=True, primary_key=True) # code = db.Column(db.CHAR(STRING_MAX), nullable=False) #注册码 Serial_id = db.Column(db.CHAR(STRING_SMALL), nullable=False) #产品序列号 abbreviation = db.Column(db.CHAR(STRING_SMALL), nullable=False) #产品缩写 username = db.Column(db.CHAR(STRING_SMALL), nullable=False) # 注册码 noewdata = db.Column(db.DateTime, nullable=False) # 创建时间 day = db.Column(db.Integer, nullable=False) # 有效天数 def __init__(self, username, noewdata, day, code, Serial_id, abbreviation): self.code = code self.Serial_id = Serial_id self.abbreviation = abbreviation self.username = username self.noewdata = noewdata self.day = day @classmethod def getlist(cls): '''''' return cls.query.all() @classmethod def deletecode(cls, code): '''清除注册码code''' cls.query.filter(cls.code == code).delete()
class UserLogModel(db.Model): ''' 用户日志 ''' __tablename__ = 'user_log' id = db.Column(db.Integer, autoincrement=True, primary_key=True) username = db.Column(db.CHAR(STRING_MEDIUM), nullable=False) ip = db.Column(db.CHAR(STRING_SMALL)) source = db.Column(db.Integer) createtime = db.Column(db.DateTime, default=datetime.now) resourcename = db.Column(db.CHAR(STRING_MEDIUM)) action = db.Column(db.INT) content = db.Column(db.CHAR(STRING_MAX)) result = db.Column(db.CHAR(STRING_MEDIUM)) def __init__(self, username, ip, source, createtime, resourcename, action, content, result): self.username = username self.ip = ip self.source = source if createtime: self.createtime = createtime self.resourcename = resourcename self.action = action self.content = content self.result = result @classmethod def get_by_id(cls, id): return cls.query.get(id)
class Address(db.Model): __tablename__ = 'address' id = db.Column(db.Integer, primary_key=True) street = db.Column(db.CHAR(100)) neighborhood = db.Column(db.CHAR(100)) number = db.Column(db.CHAR(20)) city = db.Column(db.CHAR(100)) state = db.Column(db.CHAR(100)) #user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref='address', uselist=False, lazy=False) group = db.relationship('Group', backref='address', uselist=False, lazy=False) def __init__(self, street, neighborhood, number, city, state, user=None, group=None): self.street = street self.neighborhood = neighborhood self.number = number self.city = city self.state = state self.user = user self.group = group
class Staff(db.Model, UserMixin): __tablename__ = 'staffs' staff_id = db.Column(db.String(64), primary_key=True) first_name = db.Column(db.String(64), nullable=False) last_name = db.Column(db.String(64), nullable=False) school_code = db.Column(db.CHAR(3), nullable=False) department_code = db.Column(db.CHAR(3), nullable=False) role = db.Column(db.String(64), nullable=False) db.ForeignKeyConstraint( [department_code, school_code], [Department.department_code, Department.school_code]) account = db.relationship('StaffAccount', uselist=False, back_populates='owner') announcements = db.relationship('Announcement', backref='sender', lazy=True) events = db.relationship('Activity', backref='creator', lazy=True) def __str__(self): return self.first_name + self.first_name def __repr__(self): return f"<Staff: {self.first_name} {self.last_name}>" def get_id(self): return self.staff_id
class PortalAuth(db.Model): portal = db.Column(db.CHAR(255), primary_key=True) access_token = db.Column(db.CHAR(255)) refresh_token = db.Column(db.CHAR(255)) event_counter = db.Column(db.INTEGER, default=0) def __init__(self, *args, **kwargs): super(PortalAuth, self).__init__(*args, **kwargs)
class ethernet_packet(db.Model): __tablename__ = 'ethernet_packet' packet_id = db.Column(db.BIGINT, db.ForeignKey('raw_packet.packet_id'), primary_key=True) dst_mac_add = db.Column(db.CHAR(6)) src_mac_add = db.Column(db.CHAR(6)) ether_type = db.Column(db.SMALLINT) def __repr__(self): return '<packet_id: {0}, dst_mac_add: {1}, src_mac_add: {2}, ether_type: {3} >'.format(self.packet_id, self.dst_mac_add, self.src_mac_add, self.ether_type)
class Users(db.Model): id = db.Column(db.INTEGER, primary_key=True) username = db.Column(db.CHAR(120), unique=True) pwd = db.Column(db.CHAR(120)) forgeAPI_key = db.Column(db.CHAR(120)) def __init__(self, username, pwd, forgeAPI_key): self.username = username self.pwd = pwd self.forgeAPI_key = forgeAPI_key
class UserOTP(db.Model): __tablename__ = "user_otp" id = db.Column(db.CHAR(36), primary_key=True, default=lambda: str(uuid.uuid4())) type = db.Column(db.String(10), unique=False) code = db.Column(db.String(10), unique=False) sg_message_id = db.Column(db.String(30), unique=False) reg_exp_date = datetime.datetime.utcnow() + datetime.timedelta(hours=3) exp_time = db.Column(db.DateTime, default=reg_exp_date) created = db.Column(db.DateTime, default=datetime.datetime.utcnow) # https://stackoverflow.com/questions/5033547/sqlalchemy-cascade-delete user_id = db.Column(db.CHAR(36), db.ForeignKey('user.id', ondelete='CASCADE'))
class SerialModel(db.Model): __tablename__ = 'serial_number' id = db.Column(db.Integer, autoincrement=True, primary_key=True) #id name = db.Column(db.CHAR(STRING_SMALL), nullable=False) abbreviation = db.Column(db.CHAR(STRING_SMALL), nullable=False) def __init__(self, name, abbreviation): self.name = name self.abbreviation = abbreviation @classmethod def getlist(cls): '''''' return cls.query.all()
class Team(db.Model): __tablename__ = 'team' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(40), unique=True, nullable=False) iso_2 = db.Column(db.CHAR(2), nullable=False) group = db.Column(db.CHAR(1), nullable=False) MP = db.Column(db.Integer(), default=0) W = db.Column(db.Integer(), default=0) D = db.Column(db.Integer(), default=0) L = db.Column(db.Integer(), default=0) GF = db.Column(db.Integer(), default=0) GA = db.Column(db.Integer(), default=0) GD = db.Column(db.Integer(), default=0) Pts = db.Column(db.Integer(), default=0)
class User(UserMixin, db.Model): __tablename__ = 'user' __table_args__ = {'useexisting': True} note = db.Column(db.String(256), nullable=True, default=None) id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(32), nullable=False) level = db.Column(db.SmallInteger, nullable=False, default=0) email = db.Column(db.String(32), unique=True, nullable=False) # probably temp email if address too long password = db.Column(db.String(48), name='password', nullable=False) ss_port = db.Column(db.Integer, nullable=False, unique=True) ss_pwd = db.Column(db.String(16), name='ss_pwd', nullable=False) ss_enabled = db.Column(db.Boolean, nullable=False, default=True) # boolean will convert to tinyint(1) in mysql? ss_method = db.Column(db.String(32), nullable=False, default='aes-128-cfb') traffic_up = db.Column(db.BigInteger, nullable=False, default=0) traffic_down = db.Column(db.BigInteger, nullable=False, default=0) traffic_quota = db.Column(db.BigInteger, nullable=False, default=SsConfig.SS_DEFAULT_TRAFFIC * 1024 * 1024) last_use_time = db.Column(db.DateTime, nullable=False, default=datetime.fromisoformat('1999-01-01 08:00:00')) plan_type = db.Column(db.String(32), nullable=False, default='free') plan_end_time = db.Column(db.DateTime, nullable=False, default=datetime.fromisoformat('2099-12-31 12:00:00')) total_paid = db.Column(db.Integer, nullable=False, default=0) last_gift_time = db.Column(db.DateTime, nullable=False, default=datetime.fromisoformat('1999-01-01 08:00:00')) last_check_in_time = db.Column(db.DateTime, nullable=False, default=datetime.fromisoformat('1999-01-01 08:00:00')) last_reset_pwd_time = db.Column(db.DateTime, nullable=False, default=datetime.fromisoformat('1999-01-01 08:00:00')) reg_time = db.Column(db.DateTime, nullable=False, default=lambda: datetime.utcnow()) reg_ip = db.Column(db.CHAR(39), nullable=False, default='127.0.0.1') referee = db.Column(db.Integer, nullable=False, default=0) invite_quota = db.Column(db.SmallInteger, name='invite_num', nullable=False, default=0) email_verified = db.Column(db.Boolean, nullable=False, default=False) protocol = db.Column(db.CHAR(32), nullable=False, default='origin') obfs = db.Column(db.CHAR(32), nullable=False, default='plain') type = db.Column(db.SmallInteger, nullable=False, default=1) def __init__(self, **kwargs): for k in kwargs: if hasattr(self, k): self.__dict__[k] = kwargs[k] def __repr__(self): return "{id:%s, email:%s, name:%s}" % (self.id, self.email, self.name) def to_dict(self): dct = {} for k, v in vars(self).items(): dct[k] = v dct.pop('_sa_instance_state') dct.pop('password') return dct
class User(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False) username = db.Column(db.String(128), index=True, unique=True, nullable=False) password = db.Column(db.CHAR(40), nullable=False) posts = db.relationship('Post', backref='author', lazy='dynamic') projects = db.relationship('Project', backref='author', lazy='dynamic') people = db.relationship('People', backref='author', lazy='dynamic') papers = db.relationship('Paper', backref='author', lazy='dynamic') def __repr__(self): return "<User %r>" % (self.username) @property def is_authenticated(self): return True @property def is_active(self): return True @property def is_anonymous(self): return False def get_id(self): return str(self.id)
class Transaction(Base): __tablename__ = 'transactions' donor_id = db.Column('donor_id', db.Integer, db.ForeignKey('donors.id'), nullable=False) type = db.Column('transaction_type', db.CHAR(1), nullable=False) bloodtype_id = db.Column('bloodtype_id', db.Integer, db.ForeignKey('bloodtypes.id'), nullable=True) milliliters = db.Column('milliliters', db.Integer, nullable=False) soft_deleted = db.Column('soft_deleted', db.TIMESTAMP(timezone=False), nullable=True) def __init__(self, donor_id, type, bloodtype_id, milliliters, donor): self.donor_id = donor_id self.type = type self.bloodtype_id = bloodtype_id self.milliliters = milliliters self.donor = donor # Update inventory if type == 'D': bloodtype = Bloodtype.query.filter_by(id=bloodtype_id).first() bloodtype.increase(milliliters) donor.donate(milliliters) elif type == 'W': bloodtype = Bloodtype.query.filter_by(id=bloodtype_id).first() bloodtype.decrease(milliliters) donor.withdraw(milliliters) def __repr__(self): return '<ID: %r>' % (self.id)
class PO(db.Model): __tablename__ = "PO" serial_num = db.Column(db.Integer, primary_key=True) po_id = db.Column(db.Integer) project_id = db.Column(db.Integer, db.ForeignKey(PROJECTS.project_id)) r_id = db.Column(db.Integer, db.ForeignKey(RESOURCES.r_id)) quantity = db.Column(db.Integer) status = db.Column(db.CHAR(1)) def __init__(self, serial_num=None, po_id=None, project_id=None, r_id=None, quantity=None, status=None): self.serial_num = serial_num self.po_id = po_id self.project_id = project_id self.r_id = r_id self.quantity = quantity self.status = status def view_details(self): print(self.project_id, self.r_id, self.quantity)
class ShippingInfo(db.Model): __tablename__ = "ShippingInfo" id = db.Column(db.Integer, primary_key=True) u_id = db.Column(db.Integer, db.ForeignKey("User.u_id"), nullable=False) address = db.Column(db.String, nullable=False) city = db.Column(db.String, nullable=False) state = db.Column(db.String, nullable=False) country = db.Column(db.String, nullable=False) postal_code = db.Column(db.String, nullable=False) phone = db.Column(db.CHAR(10), nullable=False) def __init__(self, u_id, address, city, state, country, postal_code, phone): self.u_id = u_id self.address = address, self.city = city, self.state = state, self.country = country, self.postal_code = postal_code, self.phone = phone def __repr__(self): return { "address" : self.address, "city" : self.city, "state": self.state, "country": self.country, "postal_code": self.postal_code, "phone": self.phone }
class Teacher(BaseMixin, NameMixin, ContactMixin, db.Model): teacher_id = db.Column(db.CHAR(StandardLength), unique=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), index=True) user = db.relationship("User", backref=backref("Teacher", uselist=False)) classes = db.relationship('Class', secondary=teachers_classes, cascade="all,delete")
class Customers(db.Model): """ Create a Customers model """ id = db.Column(db.Integer, primary_key=True, nullable=False) phone = db.Column(db.String(45), nullable=False) latitude = db.Column(db.String(45), nullable=False) longitude = db.Column(db.String(45), nullable=False) age = db.Column(db.Integer) gender = db.Column(db.CHAR(1)) family_size = db.Column(db.Integer) def __init__(self, phone, latitude, longitude, age, gender, family_size=1): self.phone = phone self.latitude = latitude self.longitude = longitude self.age = age self.gender = gender self.family_size = family_size def __repr__(self): return '{{ "customer_id": "{}",' \ ' "phone": "{}",' \ ' "latitude": "{}",' \ ' "longitude": "{}",' \ ' "age": {},' \ ' "gender": "{}",' \ ' "family_size": {} }}'.format(self.id, self.phone, self.latitude, self.longitude, self.age, self.gender, self.family_size)
class User(db.Model): id = db.Column(db.Integer, primary_key=True, nullable=False) username = db.Column(db.String(128), index=True, unique=True, nullable=False) password = db.Column(db.CHAR(40), nullable=False) files = db.relationship('File', backref="uploader", lazy='dynamic') logs = db.relationship('Log', backref="user", lazy='dynamic') def __repr__(self): return "<User %r>" % (self.username) @property def is_authenticated(self): return True @property def is_active(self): return True @property def is_anonymous(self): return False def get_id(self): return str(self.id)
class School(db.Model): __tablename__ = 'schools' school_code = db.Column(db.CHAR(3), primary_key=True) name = db.Column(db.String(64), nullable=False) departments = db.relationship('Department', backref='school', lazy=False) @property def staffs(self): _staffs = [] for department in self.departments: for staff in department.staffs: _staffs.append(staff) return _staffs @property def courses(self): _courses = [] for department in self.departments: for course in department.courses: _courses.append(course) return _courses def __str__(self): return self.name def __repr__(self): return f"<School: {self.name}>"
class election_div(db.Model): id = db.Column(db.INTEGER, primary_key=True) name = db.Column(db.VARCHAR(125), nullable=False) phys_addr_addr1 = db.Column(db.VARCHAR(25)) phys_addr_addr2 = db.Column(db.VARCHAR(25)) phys_addr_city = db.Column(db.VARCHAR(25)) phys_addr_state = db.Column(db.CHAR(2)) phys_addr_zip = db.Column(db.CHAR(5)) mail_addr_addr1 = db.Column(db.VARCHAR(25)) mail_addr_addr2 = db.Column(db.VARCHAR(25)) mail_addr_city = db.Column(db.VARCHAR(25)) mail_addr_state = db.Column(db.CHAR(2)) mail_addr_zip = db.Column(db.CHAR(5)) phone = db.Column(db.VARCHAR(15)) fax = db.Column(db.VARCHAR(15)) website = db.Column(db.TEXT) notes = db.Column(db.TEXT)
class Parameter(db.Model): '''系统运行参数''' id = db.Column(db.Integer, autoincrement=True, primary_key=True) object = db.Column(db.CHAR(STRING_SMALL), nullable=False) attrib = db.Column(db.CHAR(STRING_MEDIUM), nullable=False) vtype = db.Column(db.String(STRING_SMALL), nullable=False, default='str') value = db.Column(db.String(STRING_MEDIUM), nullable=False) def __init__(self, obj, attr, val, vtype='str'): self.object = obj self.attrib = attr self.value = val self.vtype = vtype @classmethod def getlist(cls): return cls.query.all() @classmethod def getobj(cls, obj, attr=None): '''获取对象: 无属性时获取全部对象属性''' if attr == None: return cls.query.filter(cls.object == obj).all() return cls.query.filter( \ cls.object == obj, cls.attrib == attr).first() @classmethod def getval(cls, obj, attr): '''获取值''' para = cls.query.filter( \ cls.object == obj, cls.attrib == attr).first() if para == None: return None return eval(para.vtype)(para.value) @classmethod def setval(cls, obj, attr, val): '''设置值''' para = cls.query.filter( \ cls.object == obj, cls.attrib == attr).first() if para == None: para = cls(obj, attr, str(val), type(val).__name__) else: para.value = str(val) db.session.add(para)
class post_comments(db.Model): postid = db.Column(db.Integer, db.ForeignKey('arhpost.postid')) sid = db.Column(db.SmallInteger, primary_key=True, unique=True) text = db.Column(db.Text, index=False, unique=False) userid = db.Column(db.Integer, db.ForeignKey('arhuser.userid')) dateline = db.Column(db.Integer) color = db.Column(db.CHAR(16), index=False, unique=False) user = db.relationship('arhuser', foreign_keys=userid, lazy='joined')
class File(db.Model): userid = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) virtualpath = db.Column(db.String(190), primary_key=True) md5 = db.Column(db.CHAR(32), db.ForeignKey('status.md5'), nullable=True) def __repr__(self): return "<UserID: %r, Virtual Directory: %r>" % (self.userid, self.virtualpath)
class Department(db.Model): __tablename__ = 'departments' school_code = db.Column(db.CHAR(3), db.ForeignKey('schools.school_code'), primary_key=True) department_code = db.Column(db.CHAR(3), primary_key=True) name = db.Column(db.String(64), nullable=False) courses = db.relationship('Course', backref='department', lazy=False) staffs = db.relationship('Staff', backref='department', lazy=False) def __str__(self): return self.name def __repr__(self): return f"<Department: {self.name}>"
class office_holder(db.Model): id = db.Column(db.INTEGER, primary_key=True) first_name = db.Column(db.VARCHAR(25), nullable=False) middle_name = db.Column(db.VARCHAR(25)) last_name = db.Column(db.VARCHAR(25), nullable=False) party_affiliation = db.Column(db.CHAR(1)) address1 = db.Column(db.VARCHAR(25)) address2 = db.Column(db.VARCHAR(25)) city = db.Column(db.VARCHAR(25)) state = db.Column(db.CHAR(2)) zip = db.Column(db.CHAR(5)) phone = db.Column(db.VARCHAR(15)) fax = db.Column(db.VARCHAR(15)) email_address = db.Column(db.TEXT) website = db.Column(db.VARCHAR(50)) photo_link = db.Column(db.TEXT) notes = db.Column(db.TEXT)
class arhinfernoshout(db.Model): sid = db.Column(db.Integer, primary_key = True) s_user = db.Column(db.SmallInteger, db.ForeignKey('arhuser.userid'), index=True, unique=False) s_time = db.Column(db.Integer, index = False, unique = False) s_shout = db.Column(db.Text, index=False, unique=False) s_me = db.Column(db.Enum('0', '1'), default='0') s_private = db.Column(db.SmallInteger, index=True, unique=False) dialog_id = db.Column(db.CHAR(16), index=True, unique=False)
class PaymentModel(db.Model): __tablename__ = "payments" shop_order_id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) amount = db.Column(db.DECIMAL) currency = db.Column(db.CHAR(3)) description = db.Column(db.Text, default="") date_created = db.Column(db.DateTime, default=datetime.utcnow())
class AddressMixin(object): street_address = db.Column("Street Address", db.VARCHAR(StandardLength), index=True) apt = db.Column(db.VARCHAR(32), index=True) city = db.Column(db.VARCHAR(StandardLength), index=True) state = db.Column(db.CHAR(2), index=True) zip_code = db.Column("Zip Code", db.Integer, index=True) neighborhood = db.Column(db.VARCHAR(StandardLength), index=True)