class Application(ModelBase): user_id = db.Column( db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False, ) company_name = db.Column(db.String(255), nullable=False, index=True) application_date = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) application_notes = db.Column(db.Text, nullable=True) position = db.Column(db.String(255), nullable=False, index=True) user = db.relationship( 'User', backref=db.backref('applications', lazy='dynamic'), ) events = db.relationship( 'ApplicationEvent', backref='application', lazy='dynamic', ) contacts = db.relationship( 'ApplicationContact', backref='application', lazy='dynamic', ) keywords = db.relationship('Keyword', secondary=application_keyword, backref=db.backref('applications', lazy='dynamic'), lazy='dynamic')
class Email(db.Model): id: Optional[int] email: str url: str search_query: str sent_posts: Optional[List[Post]] id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(120)) url = db.Column(db.String(500)) search_query = db.Column(db.String(200)) sent_posts = db.relationship("Post", secondary=posts_identifier, cascade="all, delete") def __repr__(self): return "<Email %r>" % self.email def subscribe(self): db.session.add(self) db.session.commit() def unsubscribe(self): db.session.delete(self) db.session.commit()
class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(120), nullable=False) name = db.Column(db.String(120), nullable=False) @classmethod def find_by_email(cls, email): return cls.query.filter_by(email=email).first() #generating hash for password @staticmethod def generate_hash(password): return sha256.hash(password) #check if hashes match @staticmethod def verify_hash(password, hash): return sha256.verify(password, hash) #saving user to database def save_to_db(self): db.session.add(self) db.session.commit()
class TicketRecords(db.Model): __tablename__ = 'TICKET_RECORDS' id_ticket = db.Column(db.Integer, primary_key=True) id_ticket_hash = db.Column(db.String(255), unique=True, default='') id_creator = db.Column( db.Integer, db.ForeignKey('USERS.id_user', ondelete='RESTRICT', onupdate='RESTRICT')) id_admin = db.Column(db.Integer, db.ForeignKey('USERS.id_user', ondelete='RESTRICT', onupdate='RESTRICT'), nullable=True) id_channel = db.Column(db.String(255), unique=True, default='') # status: -1 => No admin has taken the ticket # status: 0 => Ticket is assigned to an admin # status: 1 => Ticket is marked as closed status = db.Column(TINYINT(1), default=-1) title = db.Column(db.String(255), default='') category = db.Column(db.String(100), default='') create_timestamp = db.Column( TIMESTAMP, default=datetime.utcnow().replace(microsecond=0)) last_activity_timestamp = db.Column( TIMESTAMP, default=datetime.utcnow().replace(microsecond=0))
class Note(db.Model): __tablename__ = 'notes' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(250)) body = db.Column(db.String()) creation_date = db.Column(db.DateTime, server_default=db.func.current_timestamp(), nullable=False) modified_date = db.Column(db.DateTime, server_default=db.func.current_timestamp(), nullable=False) notebook_id = db.Column(db.Integer, db.ForeignKey('notebooks.id'), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE')) @classmethod def filter_by_user_id(cls, user_id): return cls.query.filter_by(user_id=user_id).all() @classmethod def filter_by_notebook_id(cls, notebook_id): return cls.query.filter_by(notebook_id=notebook_id).all()
class Recipes(db.Model): """This is Recipes class for table structure.""" __tablename__ = 'recipes' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(40), nullable=False) ingredients = db.Column(db.Text, nullable=False) description = db.Column(db.Text, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) date_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) category_id = db.Column(db.Integer, db.ForeignKey('categories.id'), nullable=False) category = db.relationship('Categories', foreign_keys=[category_id]) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) user = db.relationship('Users', foreign_keys=[user_id]) def __rerp__(self): """Representation string of an Recipes object.""" return f"Recipes('{self.name}', " \ f"'{self.category_id}', " \ f"'{self.user_id}', " \ f"'{self.date_posted}', " \ f"'{self.date_updated}', " \ f"'{self.image_file}')"
class User(db.Model): __tablename__ = 'db_user' id = db.Column(db.Integer, autoincrement=True, primary_key=True) email = db.Column(db.String(128), unique=True, nullable=False) firstName = db.Column(db.String(32), nullable=False) lastName = db.Column(db.String(32), nullable=False) active = db.Column(db.Boolean, nullable=False) password_hash = db.Column(db.String(128), nullable=False) def __repr__(self): return '<User %r>' % self.email def hash_password(self, password): self.password_hash = pwd_context.encrypt(password) def activate(self): self.active = True def verify_password(self, password): return pwd_context.verify(password, self.password_hash) #Generate a token using flask_jwt_extended def generate_auth_token(self, expiration=600): identity = {'id': self.id, 'email': self.email} return create_access_token(identity=identity, expires_delta=False)
class RoomType(db.Model): __tablename__ = 'RoomTypes' id = db.Column(db.Integer, name='Id', primary_key=True) name = db.Column(db.String(255), name='Name') guid = db.Column(db.String(255), name='GUID') image_path = db.Column(db.String(255), name='Image_Path', nullable=True) formulas = db.relationship('Formula', back_populates='room_type') def to_json(self): return { 'id': self.id, 'name': self.name, 'guid': self.guid, 'imagePath': self.image_path, 'formulas': self.formulas } def to_view_json(self): return {'id': self.id, 'name': self.name} @classmethod def from_json(cls, data): return cls(id=data.get('id', None), name=data['name'], guid=data['guid'], image_path=data['imagePath'], formulas=list(map(Formula.from_json, data['formulas'])))
class Comment(db.Model): __tablename__ = 'comments' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), nullable=False) comment = db.Column(db.String(255), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('posts.id'), nullable=False) created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False) updated_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False, onupdate=datetime.now()) post = db.relationship("Post", backref=db.backref("posts", lazy=True)) def __init__(self, username, comment, post_id): self.username = username self.comment = comment self.post_id = post_id def json(self): return { "id": self.id, "username": self.username, "comment": self.comment, "post_id": self.post_id, "created_at": str(self.created_at), "updated_at": str(self.updated_at) } def create(self): db.session.add(self) db.session.commit() return self @classmethod def find_all(cls): comments = Comment.query.all() return [comment.json() for comment in comments] @classmethod def find_by_id(cls, id): return Comment.query.filter_by(id=id).first() @classmethod def delete(cls, id): comment = Comment.find_by_id(id) db.session.delete(comment) db.session.commit() return comment.json() @classmethod def update(cls, id, fields): comment = Comment.find_by_id(id) for key in field: setattr(comment, key, fields[key]) db.session.commit() return comment.json()
class Books(db.Model): __tablename__ = 'books' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) author = db.Column(db.String(100), nullable=False) url = db.Column(db.String(100), nullable=False) imgurl = db.Column(db.String(100), nullable=False) category = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False)
class WorkType(db.Model): __tablename__ = 'WorkTypes' id = db.Column(db.Integer, name='Id', primary_key=True) guid = db.Column(db.String(255), name='GUID') name = db.Column(db.String(255), name='Name') price_value = db.Column(db.Float, name='PriceValue', nullable=False) salary = db.Column(db.Float, name='Salary', nullable=False) time = db.Column(db.Float, name='Time', nullable=False) order = db.Column(db.Integer, name='Order', nullable=False) description = db.Column(db.Text, name='Description') materials_count = db.Column(db.Text, name='MaterialsCount') formula_id = db.Column(db.ForeignKey('Formulae.Id'), name='Formula_Id', index=True) formula = db.relationship('Formula') categories = db.relationship('Category', secondary='WorkTypeCategories') def to_json(self): return { 'id': self.id, 'name': self.name, 'GUID': self.guid, 'priceValue': self.price_value, 'salary': self.salary, 'time': self.time, 'order': self.order, 'descriptions': self.description, 'materialsCount': self.materials_count, 'formula': self.formula, 'categories': list(map(lambda c: {'id': c.id}, self.categories)) } @classmethod def from_json(cls, data): return WorkType(id=data.get('id', None), name=data['name'], guid=data['GUID'], price_value=data['priceValue'], salary=data['salary'], time=data['time'], order=data['order'], description=data['description'], materials_count=data['materialsCount'], formula=Formula.from_json(data['formula']))
class User(db.Model): """User model""" __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) created_on = db.Column(db.DateTime, server_default=db.func.now()) updated_on = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now()) email = db.Column(db.String(255), index=True, unique=True) password_hash = db.Column(db.String(64)) role = db.Column(types.Enum('user', 'admin'), default='user') busy = db.Column(db.Boolean, default=False) def __init__(self, email, password): """User object Initialization inputs ------------ email : string_type password : string_type """ self.email = email self.password = self.hash_password(password) def save(self): """Saves User to Database""" try: db.session.add(self) db.session.commit() except IntegrityError as e: db.session.rollback() raise ValueError('Data invalid. \ Cannot create account at this time.') def hash_password(self, password): """Takes raw password as input as encrypts it and stores it in model""" self.password_hash = pwd_context.encrypt(password) def verify_password(self, password): """Verifies given password matches one stored in model""" return pwd_context.verify(password, self.password_hash) def generate_auth_token(self, expiration=4320): """Generates an authorization token to be stored on client expiration time can be set manually, defaults to 3 days (4320 minutes) """ payload = { 'sub': self.id, 'iat': datetime.utcnow(), 'exp': datetime.utcnow() + timedelta(minutes=expiration) } token = jwt.encode(payload, SECRET_KEY, algorithm='HS256') return token.decode('unicode_escape')
class GameChar(Base): __tablename__ = 'game_char' char_id = db.Column(db.Integer, primary_key=True) char_name = db.Column(db.String(80), unique=True, nullable=False) life = db.Column(db.Integer, nullable=True) traits = db.Column(utils.TextPickleType(), nullable=False) traits_blurb = db.Column(db.String(TRAITS_BLURB_LENGTH), nullable=False) def __repr__(self): return '<Character %r (id:$d)>' % self.char_name, char_id
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(120), unique=True, nullable=False) password = db.Column(db.String(80), unique=True, nullable=False) def __init__(self, username, email, password): self.username = username self.email = email self.password = password
class ApplicationContact(ModelBase): application_id = db.Column( db.Integer, db.ForeignKey('application.id', ondelete='CASCADE'), nullable=False, ) first_name = db.Column(db.String(255), nullable=True) last_name = db.Column(db.String(255), nullable=True) email = db.Column(db.String(255), nullable=True) phone_number = db.Column(db.String(255), nullable=True) position = db.Column(db.String(255), nullable=True) contact_notes = db.Column(db.Text, nullable=True)
class MaterialType(db.Model): __tablename__ = 'MaterialTypes' Id = db.Column(db.Integer, primary_key=True) Name = db.Column(db.String(255)) GUID = db.Column(db.String(255)) Unit = db.Column(db.String(255)) Formula_Id = db.Column(db.ForeignKey('Formulae.Id'), index=True) WorkType_Id = db.Column(db.ForeignKey('WorkTypes.Id'), index=True) Formula = relationship('Formula') WorkType = relationship('WorkType')
class Post(db.Model): id: int url: str title: str time: datetime id = db.Column(db.Integer, primary_key=True, autoincrement=False) url = db.Column(db.String(1000)) title = db.Column(db.String(200)) time = db.Column(db.DateTime) def __repr__(self): return "<Post %r>" % self.id
class HiddenLesson(db.Model): __tablename__ = "hiddenLesson" hidden_lesson_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, nullable=False) department = db.Column(db.String(200), nullable=False) group = db.Column(db.String(200), nullable=False) sub_group = db.Column(db.String(200), nullable=False) week_day = db.Column(db.Integer, nullable=False) week_type = db.Column(db.String(200), nullable=False) lesson_number = db.Column(db.Integer, nullable=False) def __repr__(self): return f"<HiddenLesson {self.hidden_lesson_id}>" @staticmethod def find_all(): return db.session.query(HiddenLesson).all() @staticmethod def find_hidden_lessons(user_id): return db.session.query(HiddenLesson).filter_by(user_id=user_id).all() @staticmethod def find_hidden_lessons_by_day(user_id, week_day): return db.session.query(HiddenLesson).filter_by( user_id=user_id, week_day=week_day).all() @staticmethod def hide_lesson(user_id, user_department, user_group, sub_group, week_day, week_type, lesson_number): new_hidden_lesson = HiddenLesson(user_id=user_id, department=user_department, group=user_group, sub_group=sub_group, week_day=week_day, week_type=week_type, lesson_number=lesson_number) db.session.add(new_hidden_lesson) db.session.commit() return new_hidden_lesson.hidden_lesson_id @staticmethod def unhide_lesson(lesson_id): db.session.query(HiddenLesson).filter_by( hidden_lesson_id=lesson_id).delete() db.session.commit() @staticmethod def clear_lessons(user_id): db.session.query(HiddenLesson).filter_by(user_id=user_id).delete() db.session.commit()
class Post(db.Model): __tablename__ = 'posts' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) username = db.Column(db.String(255), nullable=False) image = db.Column(db.String(255), nullable=False) description = db.Column(db.Text, nullable=False) bid = db.Column(db.Float, nullable=False) created_at = db.Column(db.DateTime, default=str(datetime.utcnow()), nullable=False) updated_at = db.Column(db.DateTime, default=datetime.utcnow(), nullable=False, onupdate=datetime.now()) user = db.relationship('User', backref=db.backref('users', lazy=True)) def __init__(self, user_id, username, image, bid, description): self.user_id = user_id self.username = username self.image = image self.bid = bid self.description = description def json(self): return { "id": self.id, "user_id": self.user_id, "username": self.username, "image": self.image, "bid": self.bid, "description": self.description, "created_at": str(self.created_at), "updated_at": str(self.updated_at) } def create(self): db.session.add(self) db.session.commit() return self @classmethod def find_all(cls): return Post.query.order_by(Post.bid.desc()).all() @classmethod def find_by_id(cls, post_id): post = Post.query.filter_by(id=post_id).first() return post
class Users(db.Model): __tablename__ = 'USERS' id_user = db.Column(db.Integer, primary_key=True) id_user_hash = db.Column(db.String(255), unique=True, default='') id_chat = db.Column(db.String(255), unique=True, default='') is_admin = db.Column(TINYINT(3), default=0) username = db.Column(db.String(255), default='') password = db.Column(db.String(255), default='') email = db.Column(db.String(255), unique=True, default='') create_timestamp = db.Column( TIMESTAMP, default=datetime.utcnow().replace(microsecond=0)) # TODO: User tier and classification def check_password(self, password): return check_password_hash(self.password, password)
class AddedLesson(db.Model): __tablename__ = "addedLesson" lesson_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, nullable=False) lesson_name = db.Column(db.String(200), nullable=False) department = db.Column(db.String(200), nullable=False) group = db.Column(db.String(200), nullable=False) week_day = db.Column(db.Integer, nullable=False) place = db.Column(db.String(200), nullable=False) subgroup = db.Column(db.String(200), nullable=False) #числитель/знаменатель week_type = db.Column(db.String(200), nullable=False) lesson_number = db.Column(db.Integer, nullable=False) #лекция/практика lesson_type = db.Column(db.String(200), nullable=False) teacher_name = db.Column(db.String(200), nullable=False) time_begin = db.Column(db.Time, nullable=False) time_end = db.Column(db.Time, nullable=False) def __repr__(self): return f"<Lesson {self.lesson_id}>" @staticmethod def find_all(): return db.session.query(AddedLesson).all() @staticmethod def find_added_lessons(user_id=2): return db.session.query(AddedLesson).filter_by(user_id=user_id).all() @staticmethod def delete_lesson(lesson_id=2): db.session.query(AddedLesson).filter_by(lesson_id=lesson_id).delete() db.session.commit() @staticmethod def save_lesson(user_id, lesson_name, place, department, group, subgroup, week_day, week_type, lesson_number, lesson_type, teacher_name, time_begin, time_end): new_lesson = AddedLesson(user_id=user_id, lesson_name=lesson_name, department=department, group=group, week_day=week_day, week_type=week_type, lesson_number=lesson_number, lesson_type=lesson_type, teacher_name=teacher_name, time_begin=time_begin, time_end=time_end, subgroup=subgroup, place=place) db.session.add(new_lesson) db.session.commit() return new_lesson.lesson_id
class Contestant(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(256), nullable=False) insta = db.Column(db.String(256), nullable=False) image_url = db.Column(db.String(512), nullable=False) elimated_date = db.Column(db.DateTime, nullable=True) is_slops_crew = db.Column(db.Boolean) data_points = db.relationship( 'FollowerCountDataPoint', backref='user', lazy=True ) def __unicode__(self): return '<User %r>' % self.id def __repr__(self): return '<User %r>' % self.id
class Document(db.Model): __tablename__ = "Documents" id = db.Column(db.Integer, primary_key=True, name="Id", nullable=False) name = db.Column(db.String(255), name="Name", nullable=False) type = db.Column(db.Integer, name="DocumentType", nullable=False) date_created = db.Column(db.DateTime, name="DateCreated", nullable=False, default=datetime.now()) date_modified = db.Column(db.DateTime, name="DateModified", nullable=False, default=datetime.now()) project_id = db.Column(db.ForeignKey('MultiProjects.Id'), name='MultiProject_Id', index=True) rooms = db.relationship(Room, back_populates='document', cascade="all, delete-orphan") project = relationship('MultiProject') def to_view_json(self): return { 'id': self.id, 'name': self.name, 'dateCreated': str(self.date_created), 'dateModified': str(self.date_modified), 'documentType': self.type } def to_json(self): return { 'id': self.id, 'name': self.name, 'documentType': self.type, 'dateCreated': str(self.date_created), 'dateModified': str(self.date_modified), 'rooms': self.rooms } def update_from_json(self, data): self.name = data['name'] self.type = data['documentType'] self.date_modified = datetime.now() self.rooms = Room.array_from_json(data['rooms'], self.rooms) @classmethod def from_json(cls, data): return cls(name=data['name'], type=data['documentType'], rooms=list(map(Room.from_json, data['rooms'])))
class Game(Base): __tablename__ = 'game' game_id = db.Column(db.Integer, primary_key=True) game_name = db.Column(db.String(80), unique=True, nullable=False) def __repr__(self): return '<Game %r (id:$d)>' % self.game_name, self.game_id
class StoreModel(db.Model): __tablename__ = 'stores' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) items = db.relationship('InventoryModel', lazy='dynamic') def __init__(self, name): self.name = name def json(self): return {'name': self.name, 'items': [item.json() for item in self.items.all()]} @classmethod def find_by_name(cls, name): return cls.query.filter_by(name=name).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class UserModel(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(32), nullable=False) posts = db.relationship('Post', backref='user', lazy=True) def __init__(self, name): self.name = name def json(self): return {'id': self.id, 'name': self.name} @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() @classmethod def find_by_name(cls, name): return cls.query.filter_by(name=name).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class User(db.Model): __tablename__ = 'user' id = db.Column( db.Integer, name='id', primary_key=True, nullable=False ) name = db.Column( db.String(100), name='name', unique=True, nullable=False ) email = db.Column( db.String(100), name='email', nullable=False, unique=True ) password = db.Column( db.String(100), name='password', nullable=False ) roles = db.relationship( "Role", secondary='user_role', backref=db.backref('user'), single_parent=True ) def set_password(self, password): """Set password.""" bcrypt = Bcrypt(current_app) self.password = bcrypt.generate_password_hash(password) def check_password(self, value): """Check password.""" bcrypt = Bcrypt(current_app) return bcrypt.check_password_hash(self.password, value)
class ApplicationEvent(ModelBase): application_id = db.Column( db.Integer, db.ForeignKey('application.id', ondelete='CASCADE'), nullable=False, ) event_time = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) event_type = db.Column(db.String(255), nullable=False, index=True) event_description = db.Column(db.String(255), nullable=False, index=True) application_notes = db.Column(db.Text, nullable=True) contacts = db.relationship('ApplicationContact', secondary=event_contacts, backref=db.backref('events', lazy='dynamic'), lazy='dynamic')
class Group(db.Model): __tablename__ = 'db_group' id = db.Column(db.Integer, autoincrement=True, primary_key=True) name = db.Column(db.String(32), unique=True, nullable=False) users = db.relation('User', secondary=user_group_table, backref='groups') def __repr__(self): return '%r' % self.name
class User(ModelBase): username = db.Column(db.String(255), nullable=False, unique=True) email = db.Column(db.String(255), nullable=False, unique=True) @property def is_authenticated(self): return self.id is not None @property def is_active(self): return True @property def is_anonymous(self): return not self.is_authenticated def get_id(self): return str(self.id)