class Equipement(db.Model): ''' Mapping d'un équipement réseau ''' __tablename__ = 'sup_equipement' id = db.Column(db.Integer, primary_key=True) ip_addr = db.Column(db.Unicode(length=20)) label = db.Column(db.Unicode(length=50)) equip_type = db.Column(db.Integer) status = db.Column(db.Integer) stats = db.Column(db.UnicodeText) last_up = db.Column(db.DateTime) commentaires = db.Column(db.UnicodeText) evts = db.relationship(EvtEquipement, lazy='joined', cascade='delete')
class Gasto(db.Model): id = db.Column(db.Integer, primary_key=True) valor = db.Column(db.Numeric(precision=2)) __data = db.Column("data", db.Date, default=db.func.today()) motivo = db.Column(db.Unicode) tipo_id = db.Column(db.Integer, db.ForeignKey('tipo_do_gasto.id')) tipo = db.relationship('TipoDoGasto', backref=db.backref('gastos', lazy='dynamic')) pessoa_id = db.Column(db.Integer, db.ForeignKey('pessoa.id')) pessoa = db.relationship('Pessoa', backref=db.backref('gastos', lazy='dynamic')) def __init__(self, valor, data, motivo, cod_tipo, cod_pessoa): self.valor = valor self.data = data self.motivo = motivo self.tipo_id = cod_tipo self.pessoa_id = cod_pessoa @property def data(self): return self.__data @data.setter def data(self, valor): import datetime print valor dia = int(valor.split("/")[0]) mes = int(valor.split("/")[1]) ano = int(valor.split("/")[2]) self.__data = datetime.date(ano, mes, dia)
class LoanContribution(db.Model): id = db.Column(db.Integer, primary_key=True) lender_id = db.Column(db.Integer, db.ForeignKey('user.id')) loan_id = db.Column(db.Integer, db.ForeignKey('loan_application.id')) amount= db.Column(db.Integer, unique=False) submitted = db.Column(db.DateTime, default=func.now()) updated = db.Column(db.DateTime, onupdate=func.now())
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(120), nullable=False) body = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) created_at = db.Column(db.DateTime, default=db.func.now()) image = db.Column(db.String(300)) def __init__(self, user_id, title, body, time): self.user_id = user_id self.title = title self.body = body self.created_at = time def __repr__(self): return '<Post %r>' % self.title def as_dict(self): jsondata = dict() for c in self.__table__.columns: if c.name == "created_at": value = datetime.strftime(getattr(self, c.name), '%b %d %Y, %H:%M') jsondata.update({c.name: value}) else: jsondata.update({c.name: getattr(self, c.name)}) return jsondata
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), index=True) password_hash = db.Column(db.String(128)) todos = db.relationship('Todo', backref='author', lazy='dynamic') def to_dict(self): cols = self.__table__.columns return {col.name: getattr(self, col.name) for col in cols} def to_json(self): user_json = { 'id': self.id, 'username': self.username, 'uri': url_for('api.get_user', user_id=self.id, _external=True) } return user_json def hash_password(self, password): self.password_hash = pwd_context.encrypt(password) def verify_password(self, password): return pwd_context.verify(password, self.password_hash) def generate_auth_token(self, expiration=600): s = Serializer(server.config['SECRET_KEY'], expires_in=expiration) return s.dumps({'id': self.id}) @staticmethod def verify_auth_token(token): s = Serializer(server.config['SECRET_KEY']) try: data = s.loads(token) except SignatureExpired: return None # valid token, but expired except BadSignature: return None # invalid token user = User.query.get(data['id']) return user
class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(120), nullable=False) def save_to_db(self): db.session.add(self) db.session.commit() @classmethod def find_by_username(cls, username): return cls.query.filter_by(username=username).first() @classmethod def return_all(cls): def to_json(x): return {'username': x.username, 'password': x.password} return { 'users': list(map(lambda x: to_json(x), UserModel.query.all())) } @classmethod def delete_all(cls): try: num_rows_deleted = db.session.query(cls).delete() db.session.commit() return {'message': '{} row(s) deleted'.format(num_rows_deleted)} except: return {'message': 'Something went wrong'} @staticmethod def generate_hash(password): return sha256.hash(password) @staticmethod def verify_hash(password, hash): return sha256.verify(password, hash)
class Study(db.Model): study_code = db.Column(db.Integer, primary_key=True) programme_name = db.Column(db.String(200), nullable=False) uni_code = db.Column(db.String(10), db.ForeignKey('university.uni_code')) education_field = db.Column(db.String(25)) ordinary = db.Column(db.String(4)) ordinary_first = db.Column(db.String(4)) def __repr__(self): return str({ "study_code": self.study_code, "programme_name": self.programme_name, "uni_code": self.uni_code, "education_field": self.education_field, "ordinary": self.ordinary, "ordinary_first": self.ordinary_first }) def return_object(self): return { "study_code": self.study_code, "programme_name": self.programme_name, "uni_code": self.uni_code, "education_field": self.education_field, "ordinary": self.ordinary, "ordinary_first": self.ordinary_first }
class UserRightsModel(TimestampMixinModel, db.Model): """Table de gestion des droits des utilisateurs de GeoNature-citizen""" __tablename__ = "t_users_rights" __table_args__ = {"schema": "gnc_core"} id_user_right = db.Column(db.Integer, primary_key=True) id_user = db.Column(db.Integer, db.ForeignKey(UserModel.id_user), nullable=False) id_module = db.Column( db.Integer, db.ForeignKey(ModulesModel.id_module), nullable=True ) id_module = db.Column( db.Integer, db.ForeignKey(ProgramsModel.id_program), nullable=True ) right = db.Column(db.String(150), nullable=False) create = db.Column(db.Boolean(), default=False) read = db.Column(db.Boolean(), default=False) update = db.Column(db.Boolean(), default=False) delete = db.Column(db.Boolean(), default=False)
class CatalogItem(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(64), index=True, unique=True) image = db.Column(db.String(128)) event_specific = db.Column(db.Boolean) available = db.Column(db.Boolean) is_rocket = db.Column(db.Boolean) cost1 = db.Column(db.Integer) cost2 = db.Column(db.Integer) cost3 = db.Column(db.Integer) planet_items = db.relationship('PlanetItem', backref='catalog_parent', lazy='dynamic') def __repr__(self): return '<CatalogItem {}>'.format(self.name)
class MailConfig(db.Model): __tablename__ = 'mailconfig' id = db.Column(db.Integer, primary_key=True, autoincrement=True) fromName = db.Column(db.String(10), nullable=False) toName = db.Column(db.String(10), nullable=False) fromEmail = db.Column(db.String(50), nullable=False) fromEmailKey = db.Column(db.String(30), nullable=False) toEmail = db.Column(db.String(50), nullable=False) ownerId = db.Column(db.Integer, db.ForeignKey('user.id')) owner = db.relationship('User', backref=db.backref('mailconfigs'))
class Instagram(db.Model): # model for each instagram account __tablename__ = 'instagram_info' # name of the table id = db.Column(db.Integer, primary_key=True) # primary key of db (required) username = db.Column(db.String()) # instagram username access_token = db.Column(db.String()) # access token of the app instagram_id = db.Column(db.String()) # instagram user id def __init__(self, username, access_token, instagram_id): self.username = username self.access_token = access_token self.instagram_id = instagram_id def __repr__(self): # can return a printable representation of the object return '<id {}>'.format(self.id) def serialize(self): # not needed but conventional return { 'id': self.id, 'username': self.username, 'access_token': self.access_token, 'instagram_id': self.instagram_id }
class SatisfiesMajor(db.Model): #reference PERMs via 'PERMs', teach table via 'taught_by' majorID = db.Column(db.Integer, ForeignKey(Major.id), primary_key=True, autoincrement=False) courseID = db.Column(db.String(20), ForeignKey(Course.id), primary_key=True, autoincrement=False) #reference course via 'course' major = db.relationship("Major", backref=db.backref('satisfied_by')) course = db.relationship("Course", backref=db.backref('satisfies')) def __init__(self, majorID, courseID): self.majorID = majorID self.courseID = courseID def __repr__(self): return "<SatisfiesMajor(majorID='%s', courseID='%s')>" % ( self.majorID, self.courseID)
class Log(db.Model): id = db.Column(db.Integer, primary_key=True) date = db.Column(db.DateTime) nodeName = db.Column(db.Text) userName = db.Column(db.Text) userMail = db.Column(db.Text) authType = db.Column(db.Integer) authInfo = db.Column(db.Text) logText = db.Column(db.Text) logType = db.Column(db.Text) logLevel = db.Column(db.Text) def __init__(self, date, nodeName, userName, userMail, logText, logType, logLevel, authType, authInfo): self.date = date self.nodeName = nodeName self.userName = userName self.userMail = userMail self.logType = logType self.logLevel = logLevel self.logText = logText self.authType = authType self.authInfo = authInfo
class Product(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) description = db.Column(db.String(500)) price = db.Column(db.String(10)) quantity = db.Column(db.Integer) store = db.Column(db.Integer, db.ForeignKey("store.id")) images = db.Column(db.String(10)) types = db.Column(db.String(20)) brand = db.Column(db.String(50)) date_update = db.Column(db.DateTime, default=datetime.utcnow) def __init__(self, name, desciption, price, quantity, store, images, types, brand): self.name = name self.description = desciption self.price = price self.quantity = quantity self.store = store self.images = images self.types = types self.brand = brand
class ArticleLike(db.Model): __tablename__ = 'article_likes' id = db.Column(db.Integer, primary_key=True, autoincrement=True) article_id = db.Column(db.Integer, nullable=False) author_id = db.Column(db.Integer, nullable=False) created_time = db.Column(db.DateTime, default=datetime.now) updated_time = db.Column(db.DateTime, default=datetime.now) status = db.Column(db.Integer, nullable=False, default=1) order = db.Column(db.Integer, nullable=True, default=0)
class Staff(db.Model, UserMixin): __tablename__ = 'staff' staff_id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(10), unique=True) password = db.Column(db.String(30)) role = db.Column(db.String(20)) online = db.Column(db.Boolean) def get_id(self): return 'Staff' + str(self.staff_id) @property def chat(self): return self.chat_ @chat.setter def set_chat(self, chat_service): self.chat_ = chat_service @chat.getter def get_chat(self): return self.chat_
class User(db.Model): __tablename__ = 'user' id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, unique=True, nullable=False) email = db.Column(db.String(50), index=True, unique=True, nullable=False) first_name = db.Column(db.String(64), index=True, nullable=False) last_name = db.Column(db.String(64), index=True, nullable=False) password = db.Column(db.String(128), nullable=False) recipes = db.relationship('Recipe', backref='author', lazy='dynamic') def __repr__(self): return f'<User {self.first_name} {self.last_name}>' def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password)
class Users(db.Model): email = db.Column(db.String(128), primary_key=True) user_id = db.Column(db.String(36)) user_name = db.Column(db.Text) auth_type = db.Column(db.String(32)) profile_picture = db.Column(db.Text, nullable=True) def __init__( # pylint: disable=too-many-arguments self, email: str, user_id: str, user_name: str, auth_type: AuthType, profile_picture: str = None, ): self.email = email self.user_id = user_id self.user_name = user_name self.auth_type = auth_type.value self.profile_picture = profile_picture def __repr__(self): return "User(email={}, user_id={}, user_name={}, auth_type={}, profile_picture={})".format( self.email, self.user_id, self.user_name, self.auth_type, self.profile_picture, ) def json(self) -> dict: data = { "email": self.email, "user_id": self.user_id, "user_name": self.user_name, "auth_type": self.auth_type, "profile_picture": self.profile_picture, } return data
class Result(db.Model): ''' 비교결과 관리 테이블 ''' __tablename__ = 'result_tbl' resultID = db.Column(db.Integer, primary_key=True, autoincrement=True) '''비교결과 번호 ''' pairID = db.Column(db.Integer, db.ForeignKey('pair_tbl.pairID'), nullable=False) '''비교쌍 번호 ''' originLine = db.Column(db.Integer, nullable=False) '''원본 라인 번호 ''' compLine = db.Column(db.Integer, nullable=False) '''비교 라인 번호 ''' rType = db.Column(db.Integer, nullable=False, default=1) '''결과 유형 :rType 1: 일치 :rType 2: 유사 ''' def __init__(self, pairID, originLine, compLine, rType=1): self.pairID = pairID self.originLine = originLine self.compLine = compLine self.rType = rType def __repr__(self): return '<Result %r>' % self.resultID @property def serialize(self): return { 'pairID': self.pairID, 'originLine': self.originLine, 'compLine': self.compLine, 'rType': self.rType }
class BlockchainTaskableBase(ModelBase): __abstract__ = True blockchain_task_uuid = db.Column(db.String) @hybrid_property def blockchain_status(self): if self.blockchain_task_uuid: task = bt.get_blockchain_task(self.blockchain_task_uuid) return task.get('status', 'ERROR') else: return 'UNKNOWN'
class Survey(db.Model): __tablename__ = "survey" survey_id = db.Column(db.Integer, primary_key=True) status = db.Column(db.String(32), nullable=False) # this can either be "to_be_reviewed" or "to_be_answered" course_offering = db.relationship("CourseOffering", uselist=False, lazy=True) answers = db.relationship("Answer", lazy=True, backref=db.backref("survey", lazy=True)) questions = db.relationship("Question", secondary=survey_question_table, lazy=True, backref=db.backref("survey", lazy=True)) def get_survey_id(self): return self.survey_id def get_status(self): return self.status def update_status(self, status): if status != "to_be_reviewed" and status != "to_be_answered" and status != "closed": raise InvalidParameterError self.status = status def add_question(self, question): self.questions.append(question) def add_answer(self, answer): self.answers.append(answer) def get_all_questions(self): return self.questions def get_all_answers(self): return self.answers def get_course_str(self): return self.course_offering.course_name + " " + self.course_offering.semester
class PostModel(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) body = db.Column(db.Text()) timestamp = db.Column(db.DateTime, index=True, default=datetime.datetime.utcnow) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) def to_json(self): return { "id": self.id, "body": self.body, "timestamp": str(self.timestamp), "user_id": self.user_id, "like_count": len(PostLikeModel.query.filter_by(post_id=self.id).all()), }
class Correspondant(Entite): __tablename__ = 'ann_correspondant' __mapper_args__ = { 'polymorphic_identity': 'correspondant', } id_entite = db.Column(db.Integer, db.ForeignKey('ann_entite.id'), primary_key=True) civilite = db.Column(db.Unicode(length=50)) _prenom = db.Column('prenom', db.Unicode(length=100)) adresse = db.Column(db.Unicode(length=255)) adresse2 = db.Column(db.Unicode(length=255)) code_postal = db.Column(db.Unicode(length=50)) telephone = db.Column(db.Unicode(length=20)) mobile = db.Column(db.Unicode(length=20)) email = db.Column(db.Unicode(length=255)) fonction = db.Column(db.Unicode(length=100)) @hybrid_property def label(self): return self._label @hybrid_property def nom(self): return self._nom @nom.setter def nom(self, val): self._nom = val self._label = '%s %s' % (val, self._prenom) @hybrid_property def prenom(self): return self._prenom @prenom.setter def prenom(self, val): self._prenom = val self._label = '%s %s' % (self.nom, val)
class ArticleView(db.Model): __tablename__ = 'article_view' id = db.Column(db.Integer, primary_key=True, autoincrement=True) article_id = db.Column(db.Integer, nullable=False) user_id = db.Column(db.Integer, nullable=True) ip = db.Column(db.String(50), nullable=True) created_time = db.Column(db.DateTime, default=datetime.now) updated_time = db.Column(db.DateTime, default=datetime.now) status = db.Column(db.Integer, nullable=False, default=1)
class CourseOffering(db.Model): __tablename__ = "course_offering" course_id = db.Column(db.Integer, primary_key=True) course_name = db.Column(db.String(10), nullable=False) semester = db.Column(db.String(5), nullable=False) survey_id = db.Column(db.Integer, db.ForeignKey("survey.survey_id"), unique=True) users = db.relationship("User", secondary=course_user_table, lazy="subquery", backref=db.backref("course_offering", lazy=True)) def get_course_id(self): return self.course_id def get_course_name_and_sem(self): return self.course_name + " " + self.semester def get_users(self): return self.users
class Flight_Details(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) departure_date = db.Column(db.Date) arrival_date = db.Column(db.Date) passenger_count = db.Column(db.Integer, nullable=False) fare = db.Column(db.Integer, nullable=True) airport_id = db.Column(db.Integer, db.ForeignKey('airport.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Flight_Details('{self.departure_date}','{self.arrival_date}', '{self.fare}', '{self.user_id}', '{self.airport_id}')"
class CollectionItem(db.Model): __tablename__ = 'collection_items' id = db.Column(db.Integer, primary_key=True, autoincrement=True) collection_id = db.Column(db.Integer, nullable=False) article_id = db.Column(db.Integer, nullable=False) created_time = db.Column(db.DateTime, default=datetime.now) updated_time = db.Column(db.DateTime, default=datetime.now) status = db.Column(db.Integer, nullable=False, default=1) order = db.Column(db.Integer, nullable=True, default=0)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True, autoincrement=True) first_name = db.Column(db.String(20), nullable=False) second_name = db.Column(db.String(20)) gender = db.Column(db.String(10)) password = db.Column(db.String(60), nullable=False) dateOfBirth = db.Column(db.Date) email = db.Column(db.String(20), unique=True, nullable=False) document_number = db.Column(db.String(20), unique=True, nullable=False) address = db.relationship('Psngr_Adrs_Dtls', backref='adrs', lazy=True) docs = db.relationship('Psngr_Doc_Dtls', backref='user', lazy=True) ticket_user = db.relationship('Flight_Details', backref='user1', lazy=True) def __repr__(self): return f"User('{self.first_name}','{self.second_name}','{self.email}','{self.gender}','{self.dateOfBirth}')"
class Message(db.Model): __tablename__ = 'message' id = db.Column(db.Integer, primary_key=True) schedule = db.Column(db.Integer, db.ForeignKey('schedule.id')) text = db.Column(db.String(2054)) sender = db.Column(db.Integer, db.ForeignKey('guttersnipe.id')) recipient = db.Column(db.Integer, db.ForeignKey('guttersnipe.id')) sent = db.Column(db.DateTime)
class Profile(db.Model): __tablename__ = 'profile' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(20), unique=True) full_name = db.Column(db.String(20), unique=True) password = db.Column(db.String(20), unique=True) additional_info = db.Column(db.String(20), unique=True)