class Quotes(db.Model): id = db.Column(db.Integer, primary_key=True) quote = db.Column(db.String, nullable=False) quote_by = db.Column(db.String, nullable=False) def __repr__(self): return f'<Quotes {self.quote} --{self.quote_by}>'
class Usuario(UserMixin, db.Model): __tablename__ = 'usuario' id_user = db.Column(db.Integer, primary_key=True, nullable=False) login = db.Column(db.String(64), index=True, nullable=False, unique=True) nome = db.Column(db.String(64), index=True, nullable=False, unique=True) senha = db.Column(db.String(128), nullable=False) def __init__(self, login, nome, senha): self.login = login self.senha = senha self.nome = nome def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return self.id_user def __repr__(self): return '<User %r>' % (self.nome)
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name
class Services(ResourceMixin, db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, unique=True, server_default='') product_code = db.Column(db.String, server_default='') category = db.Column(db.String, server_default='') description = db.Column(db.String, server_default='') sales_price = db.Column(db.DECIMAL(precision=20, scale=2), server_default='0') purchase_price = db.Column(db.DECIMAL(precision=20, scale=2), server_default='0') profit = db.Column(db.DECIMAL(precision=20, scale=2), server_default='0') basis = db.Column(db.String, server_default='') cycles = db.Column(db.Integer, server_default='0')
class Subscribers(db.Model): __tablename__ = 'subscribers' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True) first_name = db.Column(db.String(64), nullable=False) is_active = db.Column(db.Boolean, nullable=False, default=True) def __repr__(self): return "{}".format(self.email) def unsubscribe(self): self.is_active = False def subscribe(self): self.is_active = True
class BlogInfo(db.Model): __tablename__ = 'blog_info' id = db.Column(db.String(32), default=gen_id, primary_key=True, unique=True) sex = db.Column(db.Integer, nullable=False, unique=False) phone = db.Column(db.String(100), nullable=True, unique=False) qq = db.Column(db.String(100), nullable=True, unique=False) wx = db.Column(db.String(100), nullable=True, unique=False) speciality = db.Column(db.String(100), nullable=False, unique=False) personal_signature = db.Column(db.String(100), nullable=False, unique=False) personal_profile = db.Column(db.String(100), nullable=False, unique=False) personal_expectation = db.Column(db.String(100), nullable=False, unique=False) status = db.Column(db.Integer, nullable=False, comment='0:审核通过, 1:删除, 2:未审核, 3:审核未通过')
class Complaints(db.Model): """docstring for Complaints""" @staticmethod def delete(ID): temp = Complaints.query.filter(Complaints.orderID == ID).first() # temp = Complaints(orderID = ID,orderName = Name,buyer = buyer2,seller= seller2,orderItems=Items,orderStatus = "Booking",orderTime = datetime.utcnow()) db.session.delete(temp) db.session.commit() @staticmethod def insertComplaints(newComplaint): newComplaint.complaintTime db.session.add(newComplaint) db.session.commit() @staticmethod def selectByOrderID(ID): temp = Complaints.query.filter(Complaints.orderID == ID).first() result = {} result['orderID'] = Complaints.orderID result['content'] = Complaints.content result['buyer'] = Complaints.buyer result['complaintTime'] = Complaints.orderTime.strftime("%A, %d. %B %Y %I:%M%p") return result def __repr__(self): return '<Count %r>' % (self.orderID) complaintID = db.Column(db.Integer, primary_key = True, autoincrement=True) orderID = db.Column(db.Integer) content = db.Column(db.String(200)) buyer = db.Column(db.Integer) status = db.Column(db.Integer) complaintTime = db.Column(db.DateTime)
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(100), unique=True, nullable=False) password = db.Column(db.String(1000), nullable=False) passwords = db.relationship('Password', backref='user', lazy=True) def get_reset_token(self, expires_sec=600): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}','{self.email}')"
class Manager(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_managers, backref=db.backref('managers', lazy='dynamic')) def __str__(self): return self.email
class Password(db.Model): id = db.Column(db.Integer, primary_key=True) site = db.Column(db.String(100), nullable=False) username = db.Column(db.String(50), nullable=False) password = db.Column(db.String(60), nullable=False) image_file = db.Column(db.String(20), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) users = db.relationship(User) def __repr__(self): return f"Password('{self.id}','{self.site}','{self.username}','{self.password}','{self.image_file})"
class UserInfo(db.Model): __tablename__ = 'user_info' id = db.Column(db.String(32), default=gen_id, primary_key=True) user = db.Column(db.String(100), nullable=False, unique=True) pwd = db.Column(db.CHAR(50), nullable=False, unique=False) net_name = db.Column(db.String(100), nullable=False, unique=True)
class Aluno(db.Model): __tablename__ = 'aluno' MATRICULA = db.Column(db.String(64), index=True, nullable=False, unique=True, primary_key=True) SIT_MATRICULA = db.Column(db.Integer, nullable=False) RENDA_FAMILIAR = db.Column(db.Float, nullable=False) RENDA_PER_CAPITA = db.Column(db.Float, nullable=False) ANO_CONCLUSAO_2_GRAU = db.Column(db.Integer, nullable=False) ANO_INGRESSO = db.Column(db.Integer, nullable=False) TIPO_ESCOLA_ORIGEM = db.Column(db.Integer, nullable=False) COD_ESTADO_CIVIL = db.Column(db.Integer, nullable=False) N_FILHOS = db.Column(db.Integer, nullable=False) SEXO = db.Column(db.Integer, nullable=False) PROFISSAO = db.Column(db.Integer, nullable=False) DESC_CIDADE = db.Column(db.Integer, nullable=False) DT_NASCIMENTO = db.Column(db.String(64), nullable=False) NIVEL_FALA_INGLES = db.Column(db.Integer, nullable=False) NIVEL_COMPREENSAO_INGLES = db.Column(db.Integer, nullable=False) NIVEL_ESCRITA_INGLES = db.Column(db.Integer, nullable=False) NIVEL_LEITURA_INGLES = db.Column(db.Integer, nullable=False) CURSO = db.Column(db.String(64), nullable=False) IDADE_INGRESSO = db.Column(db.Integer, nullable=False) def __init__(self, matricula, sit_matricula, renda_familiar, tipo_escola, ano_conclusao_2_grau, ano_ingresso, renda_per_capita, estado_civil, numero_filhos, sexo, profissao, cidade, dt_nascimento, nivel_fala, nivel_compreensao, nivel_escrita, nivel_leitura, curso, idade_ingresso): self.MATRICULA = matricula self.SIT_MATRICULA = sit_matricula self.RENDA_FAMILIAR = renda_familiar self.TIPO_ESCOLA_ORIGEM = tipo_escola self.ANO_CONCLUSAO_2_GRAU = ano_conclusao_2_grau self.ANO_INGRESSO = ano_ingresso self.RENDA_PER_CAPITA = renda_per_capita self.COD_ESTADO_CIVIL = estado_civil self.N_FILHOS = numero_filhos self.SEXO = sexo self.PROFISSAO = profissao self.DESC_CIDADE = cidade self.DT_NASCIMENTO = dt_nascimento self.NIVEL_FALA_INGLES = nivel_fala self.NIVEL_COMPREENSAO_INGLES = nivel_compreensao self.NIVEL_ESCRITA_INGLES = nivel_escrita self.NIVEL_LEITURA_INGLES = nivel_leitura self.CURSO = curso self.IDADE_INGRESSO = idade_ingresso def saveAluno(aluno): db.session.add(aluno) db.session.commit() def removeAluno(aluno): db.session.delete(aluno) db.session.commit() def listAlunos(self): return self.query.all() def saveAlunoCSV(self): if (self.CURSO == 'si'): writer = csv.writer( open("../back-end/dados/si_clean_com_matricula.csv", 'a')) writer.writerow(self.toCSV()) else: writer = csv.writer( open("../back-end/dados/eca_clean_com_matricula.csv", 'a')) writer.writerow(self.toCSV()) def editAlunoCSV(self): if self.CURSO == 'si': dados = pd.read_csv('../back-end/dados/si_clean_com_matricula.csv') dados.loc[dados['MATRICULA'] == int(self.MATRICULA), dados.columns.values] = self.toCSV() dados.to_csv('../back-end/dados/si_clean_com_matricula.csv', index=False) elif self.CURSO == 'eca': dados = pd.read_csv( '../back-end/dados/eca_clean_com_matricula.csv') dados.loc[dados['MATRICULA'] == int(self.MATRICULA), dados.columns.values] = self.toCSV() dados.to_csv('../back-end/dados/eca_clean_com_matricula.csv', index=False) def removeAlunoCSV(self): if self.CURSO == 'si': print('aq') dados = pd.read_csv('../back-end/dados/si_clean_com_matricula.csv') new = dados[dados['MATRICULA'] != int(self.MATRICULA)] new.to_csv('../back-end/dados/si_clean_com_matricula.csv', index=False) elif self.CURSO == 'eca': dados = pd.read_csv( '../back-end/dados/eca_clean_com_matricula.csv') new = dados[dados['MATRICULA'] != int(self.MATRICULA)] new.to_csv('../back-end/dados/eca_clean_com_matricula.csv', index=False) def __repr__(self): return self def serialize(self): """Return object data in easily serializeable format""" return { 'matricula': self.MATRICULA, 'sit_matricula': self.SIT_MATRICULA, 'renda_familiar': self.RENDA_FAMILIAR, 'renda_per_capita': self.RENDA_PER_CAPITA, 'ano_2_grau': self.ANO_CONCLUSAO_2_GRAU, 'ano_ingresso': self.ANO_INGRESSO, 'tipo_escola': self.TIPO_ESCOLA_ORIGEM, 'estado_civil': self.COD_ESTADO_CIVIL, 'n_filhos': self.N_FILHOS, 'sexo': self.SEXO, 'profissao': self.PROFISSAO, 'cidade': self.DESC_CIDADE, 'nascimento': self.DT_NASCIMENTO, 'fala': self.NIVEL_FALA_INGLES, 'compreensao': self.NIVEL_COMPREENSAO_INGLES, 'escrita': self.NIVEL_ESCRITA_INGLES, 'leitura': self.NIVEL_LEITURA_INGLES, 'curso': self.CURSO } def toCSV(self): """Return object data in easily serializeable format""" return [ self.MATRICULA, self.SIT_MATRICULA, float(self.RENDA_FAMILIAR), float(self.TIPO_ESCOLA_ORIGEM), self.ANO_CONCLUSAO_2_GRAU, float(self.RENDA_PER_CAPITA), float(self.COD_ESTADO_CIVIL), float(self.N_FILHOS), float(self.SEXO), float(self.PROFISSAO), float(self.DESC_CIDADE), float(self.NIVEL_FALA_INGLES), float(self.NIVEL_COMPREENSAO_INGLES), float(self.NIVEL_ESCRITA_INGLES), float(self.NIVEL_LEITURA_INGLES), '0.0', '0.0', '0', self.ANO_INGRESSO, '', self.IDADE_INGRESSO ]
class OrderManager(db.Model): """docstring for OrderManager""" def __init__(self): super(OrderManager, self).__init__() # @staticmethod # def delete(ID): # temp = OrderManager.query.filter(OrderManager.orderID == ID).first() # db.session.delete(temp) # db.session.commit() # @staticmethod def insertOrder(newOrder): db.session.add(newOrder) db.session.commit() @staticmethod def UpdateOrderState(ID, status): db.session.query(OrderManager).filter(OrderManager.orderID == ID).update({OrderManager.orderStatus: status}) db.session.commit() @staticmethod def selectOrderByID(ID): line = db.session.query(OrderManager).filter(OrderManager.orderID == ID).one() temp = {} temp['orderAmount'] = line.orderAmount temp['buyer'] = line.buyer temp['seller'] = line.seller temp['orderStatus'] = line.orderStatus temp['orderItems'] = line.orderItems temp['orderTime'] = line.orderTime.strftime("%Y %m %d %H %M %S") return temp # @staticmethod # def printTable(): # table = OrderManager.query.all() # result = [] # for line in table: # temp = {} # temp['orderID'] = line.orderID # temp['orderName'] = line.orderName # temp['buyer'] = line.buyer # temp['seller'] = line.seller # temp['orderStatus'] = line.orderStatus # temp['orderItems'] = line.orderItems # temp['orderTime'] = line.orderTime.strftime("%A, %d. %B %Y %I:%M%p") # result.append(temp) # # print result # return result def __repr__(self): return '<Count %r>' % (self.orderID) orderID = db.Column(db.Integer, primary_key = True, autoincrement=True) buyer = db.Column(db.Integer) seller = db.Column(db.Integer) orderAmount = db.Column(db.Float) orderItems = db.Column(db.String(200)) orderStatus = db.Column(db.Integer) orderTime = db.Column(db.DateTime)
class Category(db.Model): id = db.Column(db.Integer, primary_key=True) # Genral Info name = db.Column(db.String(50), nullable=False)
from flask_security import UserMixin, RoleMixin from manager import db roles_managers = db.Table( 'roles_managers', db.Column('manager_id', db.Integer(), db.ForeignKey('manager.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name class Manager(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_managers, backref=db.backref('managers', lazy='dynamic')) def __str__(self):