class User(db.Model): id = db.Column(db.Integer(), primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) def __init__(self, first_name, last_name, email, password): self.first_name = first_name self.last_name = last_name self.email = email self.active = True self.password = User.hashed_password(password) @staticmethod def hashed_password(password): return bcrypt.generate_password_hash(password).decode("utf-8") @staticmethod def get_user_by_id(user_id): user = User.query.filter_by(id=user_id).first() return user @staticmethod def get_user_with_email_and_password(email, password): user = User.query.filter_by(email=email).first() if user and bcrypt.check_password_hash(user.password, password): return user else: return None
class Question(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(30)) text = db.Column(db.String(1000)) register_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) engineer = db.Column(db.String(30)) closed = db.Column(db.Boolean) user_id = db.Column(db.Integer, nullable=False) ups = db.Column(db.Integer) downs = db.Column(db.Integer) def __repr__(self): return '<Question %r>' % self.id # the Questions object can now be iterated over. (also allows us to convert to a dict() ) def __iter__(self): yield 'id', self.id yield 'title', self.title yield 'text', self.text yield 'register_date', str(self.register_date) yield 'engineer', self.engineer yield 'closed', self.closed yield 'user_id', self.user_id yield 'ups', self.ups yield 'downs', self.downs
class Image(db.Model): id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id'), nullable=False) data = db.Column(db.LargeBinary()) categories = db.Column(db.String(255)) public = db.Column(db.Integer()) file_name = db.Column(db.String(255)) def __init__(self, user_id, file_name, data, categories=None, public=0): self.data = data self.categories = categories self.public = public self.user_id = User.query.get(user_id).id self.file_name = file_name @staticmethod def get_all_public_images(): images = Image.query.filter(Image.public == 1) return images @staticmethod def get_allowed_images_from_user(queried_user, querying_user): if queried_user == querying_user: return Image.query.filter(Image.user_id == querying_user) else: return Image.query.filter((Image.user_id == queried_user) & Image.public)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), unique=True, nullable=False) email = db.Column(db.String(128), unique=True, nullable=False) image_file = db.Column(db.String(32), nullable=False, default='default.jpg') password = db.Column(db.String(64), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def get_reset_password_token(self, expires_in=900): return jwt.encode( { 'reset_password': self.id, 'exp_time': time() + expires_in }, key=ConfigManager.SECRET_KEY, algorithm='HS256').decode('utf-8') @staticmethod def verify_reset_password_token(token): try: id = jwt.decode(token, key=ConfigManager.SECRET_KEY, algorithms=['HS256'])['reset_password'] except: return else: return User.query.get(id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) resume = db.Column(db.String(140), nullable=False) titre = db.Column(db.String(140), nullable=False) content = db.Column(db.String(140), nullable=False) date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
class OAuth2Token(db.Model): # id = db.Column(db.Integer(), primary_key=True) # use email as userId user_id = db.Column(db.String(255), nullable=False) token_type = db.Column(db.String(100)) access_token = db.Column(db.String(500), primary_key=True) refresh_token = db.Column(db.String(48)) expires_at = db.Column(db.Integer, default=0) def __init__(self, **kwargs): super(OAuth2Token, self).__init__(**kwargs) def to_token(self): return dict( access_token=self.access_token, token_type=self.token_type, refresh_token=self.refresh_token, expires_at=self.expires_at, ) @staticmethod def save(current_user, token): rf_token = None if 'refresh_token' in token: rf_token = token['refresh_token'] new_token = OAuth2Token(user_id=current_user, token_type=token['token_type'], access_token=token['access_token'], refresh_token=rf_token, expires_at=token['expires_at']) db.session.add(new_token) db.session.commit()
class Chatroom(db.Model): """ Model for chatroom platform Attributes: ---------------- room_id : int room_id for the chatroom from db name : str room name from db tag : str room interest tag from db """ room_id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(255)) tag = db.Column(db.String(255)) def __init__(self, name, tag): """ Initialize model Chatroom """ self.name = name self.tag = tag def get_chatroom_with_user_id(user_id): """ Get function for chatroom from the same user :return: return room_id and names """ return db.engine.execute("SELECT room_id, name FROM chatroom natural \ join participant where user_id =" + str(user_id)) def get_room_members_with_room_id(room_id): """ Get function for room members in the same room :return: return room members' user.id and username """ return db.engine.execute("SELECT distinct user.id, username FROM user \ join participant on user.id = participant.user_id where room_id =" + str(room_id)) def get_chatroom_with_room_id(room_id): """ Get function for room using room_id :return: return room_id """ return Chatroom.query.filter_by(room_id=room_id).first() def delete_chatroom_with_room_id(room_id): """ Delete chatroom with room_id """ chatroom = Chatroom.get_chatroom_with_room_id(room_id) if chatroom: db.session.delete(chatroom) db.session.commit()
class User(db.Model): __tablename__ = "user" id = db.Column(db.Integer(), primary_key=True) email = db.Column(db.String(255), unique=True) username = db.Column(db.String(255), unique=True) password = db.Column(db.Binary(60), nullable=False) bodyweight = db.Column(db.Integer()) one_rep_max = db.relationship("OneRepMax") imperial = db.Column(db.Boolean()) sessions = db.relationship("UserSession", lazy="dynamic") def __init__(self, email, password, imperial=True, bodyweight=-1): self.email = email self.active = True self.password = User.hashed_password(password) self.imperial = imperial self.bodyweight = bodyweight @staticmethod def hashed_password(password): return bcrypt.generate_password_hash(password) @staticmethod def get_user_with_email_and_password(email, password): user = User.query.filter_by(email=email).first() if user and bcrypt.check_password_hash(user.password, password): return user else: return None
class Offer(db.Model): id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) asal = db.Column(db.String(255)) tujuan = db.Column(db.String(255)) fee = db.Column(db.Integer()) time = db.Column(db.DateTime()) passenger = db.Column(db.Integer) color = db.Column(db.Integer) @staticmethod def get_all_offers(): offers = Offer.query.all() offers = { x.id: { 'user_id': x.user_id, 'asal': x.asal, 'tujuan': x.tujuan, 'fee': x.fee, 'time': x.time, 'passenger': x.passenger, 'passengers': [y.id for y in x.passenger_list], 'color': x.color } for x in offers } return offers
class users(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) def __repr__(self): return f"users('{self.username}')"
class Appointment(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) room = db.Column(db.Integer, db.ForeignKey('room.roomNumber'), nullable=False) clinic_id = db.Column(db.Integer, db.ForeignKey('clinic.id'), nullable=False) doctor_permit_number = db.Column(db.String(7), db.ForeignKey('doctor.permit_number'), nullable=False) patient_hcnumber = db.Column(db.String(12), db.ForeignKey('patient.hcnumber'), nullable=False) length = db.Column(db.Integer, nullable=False) time = db.Column(db.String(), nullable=False) date = db.Column(db.Date(), nullable=False) def __iter__(self): yield 'id', self.id yield 'room', self.room yield 'clinic_id', self.clinic_id yield 'doctor_permit_number', self.doctor_permit_number yield 'patient_hcnumber', self.patient_hcnumber yield 'length', self.length yield 'time', self.time yield 'date', self.date.strftime("%Y-%m-%d")
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(120), unique=True, nullable=False) image_file = db.Column(db.String(120), nullable=False, default='default.jpg') password = db.Column(db.String(120), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) #creating user token to reset the user password def get_reset_token(self, expires_sec=1800): 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}', '{self.image_file}')"
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(50), unique=True, nullable=False) password = db.Column(db.String(50), nullable=False) def __repr__(self): return f"User('{self.username}','{self.password}')"
class Address(db.Model): id = db.Column(db.Integer(), primary_key=True) street_address = db.Column(db.String(255)) postal_code = db.Column(db.Integer()) city = db.Column(db.String(100)) state = db.Column(db.String(100)) country = db.Column(db.String(100))
class User(db.Model): __tablename__ = 'User' id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(80), unique=True, nullable=False) email = db.Column(db.String(255), unique=True, nullable=False) password = db.Column(db.String(255)) def __init__(self, username, email, password): self.username = username self.email = email self.active = True self.password = User.hashed_password(password) @staticmethod def hashed_password(password): return bcrypt.generate_password_hash(password).decode("utf-8") @staticmethod def get_user_with_email_and_password(email, password): user = User.query.filter_by(email=email).first() if user and bcrypt.check_password_hash(user.password, password): return user else: return None @staticmethod def get_user_with_username_and_password(username, password): user = User.query.filter_by(username=username).first() if user and bcrypt.check_password_hash(user.password, password): return user else: return None
class Person(db.Model): 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(120), unique=True, nullable=False) phone_number = db.Column(db.String(50)) password = db.Column(db.String(255), nullable=False) address_id = db.Column(db.Integer(), db.ForeignKey('address.id')) job_id = db.Column(db.Integer(), db.ForeignKey('job.id')) stage_id = db.Column(db.Integer(), db.ForeignKey('stage.id')) def __init__(self, first_name, last_name, email, phone_number, password, address_id, job_id, stage_id): self.first_name = first_name self.last_name = last_name self.email = email self.phone_number = phone_number self.active = True self.password = Person.hashed_password(password) self.address_id = address_id self.job_id = job_id self.stage_id = stage_id @staticmethod def hashed_password(password): return bcrypt.generate_password_hash(password).decode("utf-8") @staticmethod def get_person_with_email_and_password(email, password): person = Person.query.filter_by(email=email).first() if person and bcrypt.check_password_hash(person.password, password): return person else: return None
class DbConnection(db.Model): __tablename__ = "db_connection" db_connection_id = db.Column( db.Integer, primary_key=True, ) project_id = db.Column(db.ForeignKey('project.project_id'), nullable=False, index=True) owner_id = db.Column(db.ForeignKey('user.user_id'), nullable=False) db_connection_name = db.Column(db.Text) db_type = db.Column(db.SMALLINT, nullable=False) db_name = db.Column(db.String(80), nullable=False) db_hostname = db.Column(db.String(255), nullable=False) db_username = db.Column(db.String(80), nullable=False) db_encrypted_password = db.Column(db.Text, nullable=False) is_deleted = db.Column(db.Boolean, nullable=False, default=False) created_at = db.Column(db.DateTime, default=datetime.now) modified_at = db.Column(db.DateTime, default=datetime.now) def __init__(self, project_id, owner_id, db_connection_name, db_type, db_name, db_hostname, db_username, db_encrypted_password): self.project_id = project_id self.owner_id = owner_id self.db_connection_name = db_connection_name self.db_type = db_type self.db_name = db_name self.db_hostname = db_hostname self.db_username = db_username self.db_encrypted_password = db_encrypted_password def save_to_db(self): db.session.add(self) db.session.commit()
class File(db.Model): __bind_key__ = 'wehomeproperty' id = db.Column(db.Integer(), index=True, primary_key=True) # 0 => s3 file type = db.Column(db.Integer()) is_active = db.Column(db.Boolean(), default=True, index=True) foreign_id = db.Column(db.Integer(), nullable=False, index=True) # like report's item id and itme id item_id = db.Column(db.Integer(), nullable=False, index=True) filename = db.Column(db.String(255)) # the raw name of upload raw_name = db.Column(db.String(255)) created_at = db.Column(db.DateTime(), default=datetime.datetime.now) updated_at = db.Column(db.DateTime(), default=datetime.datetime.now, onupdate=datetime.datetime.now) __table_args__ = ( db.Index("idx_foreign_id_item_id_type_is_active", "foreign_id", 'item_id', 'type', 'is_active'), ) def __init__(self, type, foreign_id, item_id, filename, raw_name, is_active=True): self.type = type self.foreign_id = foreign_id self.item_id = item_id self.filename = filename self.is_active = is_active self.raw_name = raw_name
class Account(db.Model): id = db.Column(db.Integer(), primary_key=True) user = db.Column(db.Integer()) label = db.Column(db.String(255)) bank = db.Column(db.String(255)) iban = db.Column(db.String(34), unique=True) bic = db.Column(db.String(12)) projected_date = db.Column(db.Date()) def __init__(self, user, label, bank, iban, bic, projected_date): self.user = user['id'] self.label = label self.bank = bank self.iban = iban self.bic = bic self.projected_date = projected_date @staticmethod def get_accounts(user): return Account.query.filter_by(user=user['id']).all() @staticmethod def get_account_by_id(id): account = Account.query.filter_by(id=id) if account: return account else: return None @staticmethod def get_projected_date(id): account = Account.query.filter_by(id=id).first() return account.projected_date
class TestCase(db.Model): __tablename__ = "test_case" test_case_id = db.Column(db.Integer, primary_key=True) test_suite_id = db.Column(db.ForeignKey(TestSuite.test_suite_id)) test_id = db.Column(db.String(80), nullable=True) test_status = db.Column(db.Integer, nullable=True) test_case_detail = db.Column(LONGTEXT, nullable=True) test_name = db.Column(db.String(80), nullable=True) src_db_id = db.Column(db.ForeignKey('dbdetail.db_id')) target_db_id = db.Column(db.ForeignKey('dbdetail.db_id')) created = db.Column(db.DateTime, default=datetime.datetime.now) test_suite = db.relationship(TestSuite, back_populates='test_case', lazy=True) test_case_log = db.relationship("TestCaseLog", back_populates='test_cases', lazy=True) src_db = db.relationship("DbDetail", foreign_keys=[src_db_id]) target_db = db.relationship("DbDetail", foreign_keys=[target_db_id]) def save_to_db(self): db.session.add(self) db.session.commit() def __init__(self, test_suite_id, test_id, test_status, test_case_detail, test_name, src_db_id, target_db_id): self.test_suite_id = test_suite_id self.test_id = test_id self.test_status = test_status self.test_name = test_name self.test_case_detail = test_case_detail self.src_db_id = src_db_id self.target_db_id = target_db_id
class User(db.Model): """ User Model for server runtime Attributes ---------- id : id user id in db email : str user email in db password : str user password after hashing in db username : str username in db children : relationship database relationship for User_Info """ id = db.Column(db.Integer(), primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) username = db.Column(db.String(255), unique=True) children = relationship("User_info") def __init__(self, email, password, username): """ Initialize user model from db """ self.email = email self.active = True self.password = User.hashed_password(password) self.username = username @staticmethod def hashed_password(password): """ Return hashed password :return: return hashed password """ return bcrypt.generate_password_hash(password) @staticmethod def get_user_with_email_and_password(email, password): """ Get function for user :param email: email address :param password: raw password :return: return user if found; if not, return None """ user = User.query.filter_by(email=email).first() if user and bcrypt.check_password_hash(user.password, password): return user else: return None def get_user_with_user_id(user_id): """get user information with user id.""" return User.query.filter_by(id=user_id).first()
class Drawings(db.Model): id = db.Column(db.Integer(), primary_key=True) fileName = db.Column(db.String(255), unique=True) name = db.Column(db.String(255), unique=True) def __init__(self, name, fileName): self.name = name self.fileName = fileName
class Tag(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(255), unique=True) color = db.Column(db.String(255), unique=True) def __init__(self, name, color): self.active = True self.name = name self.color = color
class Clinic(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(), nullable=False) address = db.Column(db.String(), nullable=False, unique=True) def __iter__(self): yield 'id', self.id yield 'name', self.name yield 'address', self.address
class Vokabel(db.Model): id = db.Column('wort_id', db.Integer, primary_key=True) wort = db.Column(db.String(45)) bedeutung = db.Column(db.String(45)) beispiel = db.Column(db.String(250)) quelle_id = db.Column(db.Integer, db.ForeignKey('quelle.id')) quelle = db.relationship("Quelle", backref=db.backref("Vokabel", lazy=True))
class User(db.Model): """docstring for User""" __tablename__ = "users" id = db.Column('user_id', db.Integer, primary_key=True) email = db.Column('email', db.String(80), unique=True) username = db.Column('username', db.String(80), unique=True) password = db.Column('password', db.String(80), nullable=False) auth = db.Column('auth', db.String(300), nullable=False) sync_token = db.Column('sync_token', db.String(150)) events = db.relationship('Event', backref='user', lazy='dynamic') def __init__(self, email, username, password, sync_token, auth): self.email = email self.username = username self.password = password self.sync_token = sync_token self.auth = auth def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.id) def __repr__(self): return '<User %r>' % (self.username) # 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 get_id(self): return unicode(self.id) def __repr__(self): return '<User %r>' % self.username @staticmethod def verify_email_password(email, password): # user = User.verify_auth_token(username_or_token) data = User.query.all() print("hey from model", email, password) user = User.query.filter_by(email=email).first() print(user) if user and user.password == password: g.user = user return user else: return None
class Event(db.Model): """ Model for Events platform Attributes: --------------- room_id : int room_id in db name : str name of the event in db location : str location of the event in db description: str event description in db start_time : str event start time end_time : str event end time """ room_id = db.Column(db.Integer(), ForeignKey('chatroom.room_id'), primary_key=True) name = db.Column(db.String(45)) location = db.Column(db.String(45)) description = db.Column(db.String(255)) start_time = db.Column(db.DateTime()) end_time = db.Column(db.DateTime()) def __init__(self, room_id, name, location, start_time, end_time, description): """ Initialize the model Event """ self.room_id = room_id self.name = name self.location = location self.start_time = start_time self.end_time = end_time self.description = description def get_event_with_room_id(room_id): """ Get function for event with room_id :return: return event with the room_id """ return Event.query.filter_by(room_id=room_id).first() def delete_event_with_room_id(room_id): """ Delete function for event with room_id """ event = Event.get_event_with_room_id(room_id) if event: db.session.delete(event) db.session.commit()
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()
class Task(db.Model): class STATUS: COMPLETED = 'COMPLETED' IN_PROGRESS = 'IN_PROGRESS' id = db.Column(db.Integer(), primary_key=True) date = db.Column(db.DateTime()) task = db.Column(db.String(255)) user_id = db.Column(db.String(255)) status = db.Column(db.String(255)) def __init__(self, task, user_id, status): self.date = datetime.utcnow().date() self.task = task self.user_id = user_id self.status = status @staticmethod def get_latest_tasks(): # import pdb;pdb.set_trace() user_to_task = {} result = db.engine.execute( """SELECT date, task, t.user_id, status from task t INNER JOIN (SELECT user_id, max(date) as MaxDate from task group by user_id) tm on t.user_id = tm.user_id and t.date = tm.MaxDate""") for t in result: # Task.query.join(subq, and_(Task.user_id == subq.user_id, Task.date == subq.date)) # all_tasks = Task.query.filter(Task.date >= datetime.utcnow().date()) # user_to_task = {} # for t in all_tasks: if t.user_id in user_to_task: user_to_task.get(t.user_id).append(dict(t)) else: user_to_task[t.user_id] = [dict(t)] return user_to_task @staticmethod def get_tasks_for_user(user_id): return Task.query.filter_by(user_id=user_id) @property def serialize(self): """Return object data in easily serializeable format""" return { 'date' : self.date.strftime("%Y-%m-%d"), 'task' : self.task, 'user_id' : self.user_id, 'status' : self.status, }
class RoomSchedule(db.Model): roomNumber = db.Column(db.String(), nullable=False, primary_key=True) clinic_id = db.Column(db.String(), nullable=False, primary_key=True) date = db.Column(db.String(), nullable=False, primary_key=True) timeSlots = db.Column(db.String(), nullable=False) def __iter__(self): yield 'roomNumber', self.roomNumber yield 'clinic_id', self.clinic_id yield 'timeSlots', self.timeSlots yield 'date', self.date