class Users(db.Model): '''Main class that handles our db columns''' id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(120), nullable=False) name = db.Column(db.String(120)) email = db.Column(db.String(120)) profile_image = db.Column(db.String(120)) user_id = db.Column(db.String(120), unique=True, nullable=False) access_token = db.Column(db.LargeBinary(), unique=True) def __init__(self, login, name, email, profile_image, user_id, access_token): self.login = login self.name = name self.email = email self.profile_image = profile_image self.access_token = access_token self.user_id = user_id def __repr__(self): return str({ 'login': self.login, 'name': self.name, 'email': self.email, 'profile_image': self.profile_image, 'user_id': self.user_id, 'access_token': self.access_token })
class FeatureRequest(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(200)) description = db.Column(db.String(5000)) client = db.Column(db.String(50)) client_priority = db.Column(db.Integer()) target_date = db.Column(db.String(100)) product_area = db.Column(db.String(100)) def __init__(self, title, description, client, client_priority, target_date, product_area): """ :param title: :param description: :param client: :param client_priority: :param target_date: :param product_area: """ self.title = title self.description = description self.client = client self.client_priority = client_priority self.target_date = target_date self.product_area = product_area def __repr__(self): return '<Feature Request %r>' % self.title
class Student(db.Model): __tablename__ = "students" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30), nullable=False, unique=True) email = db.Column(db.String(45), nullable=False) school_ = db.Column(db.Integer, db.ForeignKey("school.id")) course = db.relationship("Course", secondary=courses_students_table, backref="students") teacher = db.relationship("Teacher", secondary=teachers_students_table, backref="students") # teacher = db.Column(db.Integer, db.ForeignKey("teacher.id")) grade = db.Column(JSON) module = db.relationship("Module", secondary=modules_students_table, backref="students") def __repr__(self): return f"{self.name} with unique id: {self.id}" def serialize(self): return { "id": self.id, "name": self.name, "email": self.email, "course": str(self.course), "teacher": str(self.teacher), "modules": str(self.module), "grade": str(self.grade) }
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) f_name = db.Column(db.String(255)) l_name = db.Column(db.String(255)) password = db.Column(db.String(60)) email = db.Column(db.String(255), unique=True) phone = db.Column(db.String(255)) access = db.Column(db.Integer) def __init__(self, f_name, l_name, password, email, phone="", access=ACCESS['user']): self.f_name = f_name self.l_name = l_name self.password = password self.email = email self.phone = phone self.access = access def is_admin(self): return self.access == ACCESS['admin'] def allowed(self, access_level): return self.access >= access_level
class Task(db.Model): __tablename__ = "tasks" id = db.Column(db.Integer, primary_key=True) creator_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) # assignee_id = db.relationship("User", # secondary=task_users_table, # backref="tasks") dashboard_id = db.Column(db.Integer, db.ForeignKey("dashboards.id"), nullable=False) text = db.Column(db.String(1000), nullable=False) status = db.Column(db.String(80), nullable=False) creator = db.relationship("User", foreign_keys=[creator_id]) # assignee = db.relationship("User", foreign_keys=[assignee_id]) def serialize(self): return { "id": self.id, "creator_id": self.creator_id, "dashboard_id": self.dashboard_id, "text": self.text, "status": self.status }
class party_list(db.Model): __tablename__ = "party_list" id = db.Column(db.Integer, primary_key=True) character_id = db.Column(db.Integer, db.ForeignKey("character.id")) character_name = db.Column(db.String(400)) stat_name = db.Column(db.String(400)) stat_value = db.Column(db.Integer)
class User(db.Model): __tablename__ = "users333" id = db.Column('user_id', db.Integer, primary_key=True) username = db.Column('username', db.String(20), unique=True, index=True) password = db.Column('password', db.String(250)) email = db.Column('email', db.String(50), unique=True, index=True) registered_on = db.Column('registered_on', db.DateTime) todos = db.relationship('Todo', backref='user', lazy='dynamic') def __init__(self, username, password, email): self.username = username self.set_password(password) self.email = email self.registered_on = datetime.utcnow() def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return str(self.id) def __repr__(self): return '<User %r>' % (self.username)
class Bills(db.Model): bill_no = db.Column(db.Integer, primary_key = True) bill_date = db.Column(db.Date, default = arrow.now().format('YYYY-MM-DD')) bill_priority = db.Column(db.Integer) total_item = db.Column(db.Integer) bill_amt = db.Column(db.Integer) gst = db.Column(db.Float) ship_id = db.Column(db.Integer) ship_date = db.Column(db.Date, default = arrow.now().format('YYYY-MM-DD')) customer_name = db.Column(db.String(20)) cid = db.Column(db.String(10), db.ForeignKey('customer.cid', ondelete='CASCADE')) city = db.Column(db.String(20)) state = db.Column(db.String(20)) country = db.Column(db.String(20)) ref_from_transactions_for_bill_no = db.relationship('Transactions' , backref = 'bills', passive_deletes=True) def __init__(self, bill_priority, total_item, bill_amt, gst, ship_id, customer_name, customer, city, state, country): self.bill_priority = bill_priority self.total_item = total_item self.bill_amt = bill_amt self.gst = gst self.ship_id = ship_id self.customer_name = customer_name self.customer = customer self.city = city self.state = state self.country = country
class Product(db.Model): __tablename__ = 'products' id = db.Column(db.Integer, primary_key=True) product_name = db.Column(db.String(100), nullable=False) author_name = db.Column(db.String(100), nullable=False) product_description = db.Column(db.Text(500), nullable=False) price = db.Column(db.Float, nullable=False) category_id = db.Column(db.Integer, db.ForeignKey("categories.id"), nullable=False) created_at = db.Column(db.DateTime, default=db.func.now()) status = db.Column(db.String(50), default="IN STOCK") #image = db.Column(db.String(100), nullable=False) def __repr__(self): return '<Product %r>' % self.product_name def serialize(self): return { "id": self.id, "name": self.product_name, "author_name": self.author_name, "product_description": self.product_description, "price": self.price, "category": self.category.category_name, "created at": str(self.created_at), "status": self.status, #"image": self.image }
class User(db.Model): __tablename__ = 'user' id = db.Column(db.INTEGER, primary_key=True) username = db.Column(db.String(80), unique=True) password = db.Column(db.String(80), nullable=False) department = db.Column(db.INTEGER, db.ForeignKey('departments.id')) superuser = db.Column(db.Boolean, nullable=True, default=False)
class Admin(db.Model): username = db.Column(db.String(25), primary_key = True) password = db.Column(db.String(25)) def __init__(self,username, password): self.username = username self.password = password
class Product(db.Model): pid = db.Column(db.String(10), primary_key = True) p_category = db.Column(db.String(25)) p_sub_category = db.Column(db.String(25)) p_name = db.Column(db.String(25)) p_price = db.Column(db.Integer) gst = db.Column(db.Integer) product_base_margin = db.Column(db.Integer) product_sale_price = db.Column(db.Integer) #product_arrival_date = db.Column(db.DateTime()) product_arrival_date = db.Column(db.Date, default = arrow.now().format('YYYY-MM-DD')) sid = db.Column(db.String(10),db.ForeignKey('supplier.sid', ondelete='CASCADE')) ref_from_stock_for_pid = db.relationship('Stock' , backref = 'product', passive_deletes=True) ref_from_transactions_for_pid = db.relationship('Transactions' , backref = 'product', passive_deletes=True) ref_from_supplier_for_pid = db.relationship('Supplier' , backref = 'product', passive_deletes=True) ref_from_supplier_product_for_pid = db.relationship('Supplier_product' , backref = 'product', passive_deletes=True) def __init__(self, pid, p_category, p_sub_category, p_name, p_price, gst, product_base_margin, product_sale_price, supplier): self.pid = pid self.p_category = p_category self.p_sub_category = p_sub_category self.p_name = p_name self.p_price = p_price self.gst = gst self.product_base_margin = product_base_margin self.product_sale_price = product_sale_price #self.product_arrival_date = product_arrival_date self.supplier = supplier
class User(db.Model): __tablename__ = 'users' chat_id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), nullable=False) email = db.Column(db.String(32), unique=True, nullable=False) dashboards = db.relationship('DashBoard', secondary=dashboard_users, backref=db.backref('users', lazy=True)) tasks = db.relationship('Task', secondary=task_users, backref=db.backref('users', lazy=True)) comments = db.relationship("Comment", backref='author') subscriptions = db.relationship('Event', secondary=user_subscriptions, backref=db.backref("subscribers", lazy=True)) def __repr__(self): return '<User %r>' % self.username def serialize(self) -> dict: return { "chat_id": self.chat_id, "username": self.username, "email": self.email }
class registro_horas(db.Model): _id = db.Column("id", db.Integer, primary_key=True) login = db.Column(db.String(30),nullable=False) motivo = db.Column(db.String(100),nullable=False) aonde = db.Column(db.String(100),nullable=False) date = db.Column(db.Date,index=False,nullable=False) initial_time = db.Column(db.Time,index=False,nullable=False) pause_launch = db.Column(db.Time,index=False,nullable=False) back_launch = db.Column(db.Time,index=False,nullable=False) final_time = db.Column(db.Time,index=False,nullable=False) total_time = db.Column(db.Time,index=False,nullable=False) done = db.Column(db.Boolean, default=False, nullable=False) created_at = db.Column(db.DateTime,index=False,nullable=False) updated_at = db.Column(db.DateTime,index=False,nullable=False) def __init__(self, login, motivo, aonde, date, initial_time, pause_launch, back_launch, final_time, total_time, done, created_at, updated_at): self.login = login self.motivo = motivo self.aonde = aonde self.date = date self.initial_time = initial_time self.pause_launch = pause_launch self.back_launch = back_launch self.final_time = final_time self.total_time = total_time self.done = done self.created_at = created_at self.updated_at = updated_at
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) login = db.Column(db.String(255), unique=True, nullable=False) # user - vk_id; admin - login _password = db.Column(db.Text, nullable=False) # user - vk_access_token; admin - password email = db.Column(db.String(255), unique=True) active = db.Column(db.Boolean(), nullable=False) roles = db.relationship( 'Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic') ) def __init__(self, login='', password='', active=True, roles=[]): self.login = login self.password = password self.active = active self.roles = roles @hybrid_property def password(self): return self._password @password.setter def password(self, password): self._password = sha256_crypt.hash(password) @hybrid_method def verify_hash(self, password): return sha256_crypt.verify(password, self._password) @staticmethod def find_by_login(login): return User.query.filter_by(login=login).first()
class Task(db.Model): __tablename__ = 'tasks' id = db.Column(db.Integer, primary_key=True) task_name = db.Column(db.String(32), nullable=False) text = db.Column(db.Text, nullable=True) admin = db.Column(db.Integer, db.ForeignKey("users.chat_id", ondelete='CASCADE'), nullable=False) dashboard_id = db.Column(db.Integer, db.ForeignKey("dashboards.id", ondelete='CASCADE'), nullable=False) created_at = db.Column(db.DateTime, default=db.func.now()) status = db.Column(db.String(32), default="TO DO") comments = db.relationship('Comment', backref='task') admin_name = db.relationship('User', backref='task') def __repr__(self): return '<Task %r>' % self.task_name def serialize(self): return { "id": self.id, "task_name": self.task_name, "text": self.text, "admin": self.admin, "admin_name": self.admin_name.username, "dashboard_id": self.dashboard_id, "dashboard": self.dashboard.dashboard_name, "created_at": self.created_at.strftime("%d-%m-%Y %H:%M:%S"), "status": self.status }
class User(db.Model): id = db.Column(INTEGER(unsigned=True), primary_key=True, autoincrement=True) username = db.Column(db.String(80), nullable=False) email = db.Column(db.String(80), nullable=False) avatar = db.Column(db.String(200), nullable=False) info = db.Column(db.Text) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True) email = db.Column(db.String(120), unique=True) def __init__(self, username, email): self.username = username self.email = email
class UserDetails(db.Model): # __tablename__ = 'userdetails' id = db.Column(db.Integer, primary_key=True) f_name = db.Column(db.String(120), unique=False, nullable=False) l_name = db.Column(db.String(120), unique=False, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship('User', backref='UserDetails')
class inventory_dsc(db.Model): """ Stores character inventory """ __tablename__ = "inventory_dsc" id = db.Column(db.Integer, primary_key=True) character_id = db.Column(db.Integer, db.ForeignKey("character.id")) items = db.Column(db.String(400)) item_type = db.Column(db.String(400))
class Form(db.Model): __tablename__ = 'form' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) create = db.Column(db.DateTime, default=datetime.datetime.now) estatus = db.Column(db.String(1)) detail = db.Column(db.Text) fields = db.relationship('Field')
class Task(db.Model): """Tasks table""" __tablename__ = "tasks1" id = db.Column(db.Integer, primary_key=True) task_id = db.Column(db.String(32), unique=True) task_status = db.Column(db.String(32)) task_error = db.Column(db.String(64))
class Supplier_product(db.Model): id = db.Column(db.Integer, primary_key = True) pid = db.Column(db.String(10), db.ForeignKey('product.pid', ondelete='CASCADE')) sid = db.Column(db.String(10), db.ForeignKey('supplier.sid', ondelete='CASCADE')) def __init__(self, product, supplier): self.product = product self.supplier = supplier
class Field(db.Model): __tablename__ = 'field' id = db.Column(db.Integer, primary_key=True) form_id = db.Column(db.Integer, db.ForeignKey('form.id')) name = db.Column(db.String(50)) tipe = db.Column(db.String(50)) label = db.Column(db.String(100)) detail = db.Column(db.Text) answers = db.relationship('Answer')
class Car(db.Model): id = db.Column(db.Integer, primary_key=True) brand = db.Column(db.String(100)) model = db.Column(db.String(100)) manufacture = db.Column(db.String(100)) year = db.Column(db.Integer) def __repr__(self): return '<Car %r>' % self.brand
class UserProfileTable(db.Model): id = db.Column(db.Integer, primary_key=True) firstName = db.Column(db.String(80), unique=False, nullable=False) lastName = db.Column(db.String(80), unique=False, nullable=False) email = db.Column(db.String(120), unique=False, nullable=False) bio = db.Column(db.String(300), unique=False, nullable=False) def __repr__(self): return '<User %r>' % self.id
class CostExplorer(db.Model): __tablename__ = 'cost_explorer' ce_instance_id = db.Column(db.String()) ce_date = db.Column(db.String(), nullable=True) ce_instance_name = db.Column(db.String(), nullable=True) ce_month = db.Column(db.String()) ce_instance_daily_bill = db.Column(db.Float()) __table_args__ = ( PrimaryKeyConstraint('ce_instance_id', 'ce_date'), {}, ) def add_daily_bill(self, instance_id, current_month, today_date, daily_bill): ids = ins_obj.get_instances_ids() if instance_id in ids: self.ce_instance_id = instance_id self.ce_month = current_month self.ce_date = today_date self.ce_instance_daily_bill = daily_bill instance_name = ins_obj.get_instance_name_by_id(instance_id) self.ce_instance_name = instance_name row = db.session.merge(self) db.session.add(row) db.session.commit() def get_complete_bill_from_db(self): c_month = datetime.utcnow().month c_date = (datetime.utcnow() - timedelta(days=1)).strftime('%Y-%m-%d') instances_bill_list = [] complete_bill_list = CostExplorer.query.filter_by(ce_month=str(c_month)).\ with_entities(CostExplorer.ce_instance_id, func.sum(CostExplorer.ce_instance_daily_bill)).\ group_by(CostExplorer.ce_instance_id).all() for row in complete_bill_list: instance_name = ins_obj.get_instance_name_by_id(row[0]) result = CostExplorer.query.filter_by(ce_instance_id=row[0]).filter_by(ce_date=str(c_date)).first() if row[1] is None: row[1] = 0.0 if result is None: daily_bill = 0.0 else: daily_bill = result.ce_instance_daily_bill d_bill_roundoff = round(float(daily_bill), 2) m_bill_roundoff = round(float(row[1]), 2) bill_dict = { "Id": row[0], "Name": instance_name, "DailyBill": d_bill_roundoff, "MonthlyBill": m_bill_roundoff } instances_bill_list.append(bill_dict) return instances_bill_list def delete_instance_cost_from_db(self, ins_cost_list): for row in ins_cost_list: db.session.query(CostExplorer).filter(CostExplorer.ce_instance_id == row).delete() db.session.commit()
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), unique=True) role = db.Column(db.String(24)) password_hash = db.Column(db.String(128)) blogObjects = db.relationship('BlogObject', backref='user', lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username)
class SSHKeys(db.Model): __tablename__ = 'ssh_keys' __table_args__ = {'extend_existing': True} # ssh_id = db.Column(db.Integer, primary_key=True, autoincrement=True) ssh_key_name = db.Column(db.String(), primary_key=True) ssh_key_value = db.Column(db.String()) ssh_key_format = db.Column(db.String()) def add_ssh_key_value(self, key_name, key_value, key_format): self.ssh_key_name = key_name self.ssh_key_value = key_value self.ssh_key_format = key_format row = db.session.merge(self) db.session.add(row) db.session.commit() def get_ssh_key_names(self): ssh_keys = set({}) instances_list = instance_obj.get_all_instances_from_db() for instance in instances_list: ssh_keys.add(instance['KeyName']) return list(ssh_keys) def get_ssh_keys_from_db(self): all_keys_list = [] remaining_keys_list = [] key_names = self.get_ssh_key_names() all_ssh_keys = db.session.query(SSHKeys) for key in all_ssh_keys: keys_dict = { # "KeyId": key.ssh_id, "KeyName": key.ssh_key_name, "KeyValue": key.ssh_key_value, "KeyFormat": key.ssh_key_format } all_keys_list.append(keys_dict) if not key.ssh_key_value: if key in key_names: key_names.remove(key) remaining_keys_list = [{"KeyName": key} for key in key_names] return remaining_keys_list, all_keys_list def get_key_by_name(self, key_name): row = SSHKeys.query.filter_by(ssh_key_name=key_name).first() key_dict = { "KeyName": row.ssh_key_name, "KeyValue": row.ssh_key_value, "keyFormat": row.ssh_key_format } return key_dict def delete_key(self, key_id): db.session.query(SSHKeys).filter( SSHKeys.ssh_key_name == key_id).delete() db.session.commit()
class BHARound(db.Model): __tablename__ = 'BHA_Round' id = db.Column(db.Integer, primary_key=True) round = db.Column(db.String(50)) status = db.Column(db.String(20), default=StatusEnum.Preparing.value) comment = db.Column(db.TEXT) bha_id = db.Column( db.Integer, db.ForeignKey('BHA.id', ondelete='CASCADE', onupdate="CASCADE"))