class ScopusAbstractCount(db.Model): __tablename__ = 'abstract_count' id = db.Column(db.Integer(), primary_key=True) institute = db.Column(db.String(128)) year = db.Column(db.Integer()) articles = db.Column(db.Integer()) citations = db.Column(db.Integer())
class Another(db.Model): id = db.Column(db.Integer(), unique=True, nullable=False, primary_key=True) title = db.Column(db.String(80), nullable=False) grouping = db.Column(db.Integer(), nullable=False) def __repr__(self): return self.title
class Entry(db.Model): id = db.Column(db.Integer(), unique=True, nullable=False, primary_key=True) title = db.Column(db.String(80), nullable=False) grouping = db.Column(db.Integer(), nullable=False) def __repr__(self): return "<title: {}>".format(self.title)
class Ranges(db.Model): """Model for the facility table""" __tablename__ = 'Ranges' id = db.Column(db.Integer(), primary_key=True) org_id = db.Column(db.Integer()) start_date = db.Column(db.DateTime()) facility = db.Column(db.String()) hours = db.Column(db.Integer()) scheduled = db.Column(db.Boolean()) def create_range(self): result = "" try: db.session.add(self) db.session.commit() result = {'success': True} except Exception as e: print(e) result = { 'error': "Unable to create range entry", 'success': False } return result def __repr__(self): return "<Range(id=%s, facility=%s)>" % (self.org_id, self.facility)
class Calendar(db.Model): """Model for the calendar table""" __tablename__ = 'Calendar' id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(50), nullable=False) facility = db.Column(db.String(50)) integrator = db.Column(db.String(50)) totalTime = db.Column(db.Integer()) startDate = db.Column(db.DateTime(), nullable=False) private = db.Column(db.Boolean()) title = db.Column(db.String(50)) requestId = db.Column(db.Integer()) rangeId = db.Column(db.Integer()) beam = db.Column(db.Boolean()) energy = db.Column(db.Float()) def create_entry(self): result = "" try: db.session.add(self) db.session.commit() result = {'success': True} except Exception as e: print(e) result = { 'error': "Unable to create calendar entry", 'success': False } return result def __repr__(self): return "<Calendar(username=%s)>" % (self.username)
class District(db.Model): __tablename__ = 'districts' id = db.Column('id', db.Integer(), primary_key=True) name = db.Column('name', db.String(40), nullable=False) code = db.Column('code', db.String(), nullable=False) province_id = db.Column(db.Integer(), db.ForeignKey('provinces.id')) subdistricts = db.relationship('Subdistrict', backref=db.backref('district'))
class Task(db.Model): id = db.Column(db.Integer(), primary_key=True) header = db.Column(db.String(255)) description = db.Column(db.String()) status = db.Column(db.Boolean) date_creation = db.Column(db.Date) date_modification = db.Column(db.Date) board_id = db.Column(db.Integer(), db.ForeignKey("board.id"))
class User(db.Model): __tablename__ = 'user' uid = db.Column(db.Integer(), primary_key=True) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(120), nullable=False) curr_loc = db.Column(db.Integer(), db.ForeignKey('location.loc_id')) def __repr__(self): return '<User %r>' % self.email
class ClassCheckIn(db.Model): __tablename__ = 'class_check_in' id = db.Column('id', db.Integer(), primary_key=True) class_id = db.Column('class_id', db.ForeignKey('classes.id')) deadline = db.Column('deadline', db.String()) late_mins = db.Column('late_mins', db.Integer()) class_ = db.relationship('Class', backref=db.backref('checkin_info')) def __str__(self): return self.class_.refno
class FavFriends(db.Model): __tablename__ = "fav_friends" fav_friends_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer()) friend_id = db.Column(db.Integer()) user_id = db.Column(db.Integer, db.ForeignKey("users.user_id"), nullable=False) friend_id = db.Column(db.Integer, db.ForeignKey("users.user_id"), nullable=False) def __repr__(self): return f"<{self.user_id} friend/s are {self.friend_id}>"
class StrategyActivity(db.Model): __tablename__ = 'strategy_activities' id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) refno = db.Column('refno', db.String(), nullable=False) created_at = db.Column('created_at', db.DateTime(), server_default=func.now()) content = db.Column('content', db.String, nullable=False) theme_id = db.Column('theme_id', db.Integer(), db.ForeignKey('strategy_themes.id')) kpis = db.relationship('KPI', backref=db.backref('strategy_activity'))
class Integrator(db.Model): """Model for the facility table""" __tablename__ = 'Integrator' org_id = db.Column(db.Integer(), primary_key=True) range = db.Column(db.ARRAY(db.DateTime())) facility = db.Column(db.ARRAY(db.String())) hours = db.Column(db.ARRAY(db.Integer())) def __repr__(self): return "<Integrator(id=%s)>" % (self.org_id)
class TAMU(db.Model): """Model for the TAMU table""" __tablename__ = 'TAMU' id = db.Column(db.Integer(), primary_key=True) bad_dates = db.Column(db.ARRAY(db.Date())) request_id = db.Column(db.Integer()) def create_request(self): db.session.add(self) db.session.commit()
class PizzaRating(db.Model): __tablename__ = "pizza_rating" rating_id = db.Column(db.Integer, primary_key=True) pizza_id = db.Column(db.Integer()) user_id = db.Column(db.Integer()) user_rating = db.Column(db.Integer()) user_id = db.Column(db.Integer, db.ForeignKey("users.user_id"), nullable=False) pizza_id = db.Column(db.Integer, db.ForeignKey("pizzas.pizza_id"), nullable=False) def __repr__(self): return f"<{self.user_id} rated {self.pizza_id} = {self.user_rating}>"
class Menu(db.Model): __tablename__ = "menu" id = db.Column(db.Integer(), primary_key=True) title = db.Column(db.String()) price = db.Column(db.Integer()) vegetarian = db.Column(db.Boolean()) order = db.relationship("Order", backref="menu", lazy="dynamic") def __repr__(self): return f"<Book {self.title}>"
class HomeAddress(db.Model): __tablename__ = 'addresses' id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) village = db.Column(db.String(), nullable=True) street = db.Column(db.String(), nullable=True) province_id = db.Column('province_id', db.Integer(), db.ForeignKey('provinces.id')) district_id = db.Column('district_id', db.Integer(), db.ForeignKey('districts.id')) subdistrict_id = db.Column('subdistrict_id', db.Integer(), db.ForeignKey('subdistricts.id')) postal_code = db.Column('postal_code', db.Integer())
class JobSalary(db.Model): __tablename__ = "jobsalaries" id = db.Column(db.Integer(), primary_key=True, autoincrement=True) title = db.Column(db.String(), nullable=False) lower_quartile = db.Column(db.Integer(), nullable=False) median_salary = db.Column(db.Integer(), nullable=False) upper_quartile = db.Column(db.Integer(), nullable=False) average_years_experience = db.Column(db.Float(), nullable=False) last_updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # books = db.relationship("Book", backref="user", lazy="dynamic") def __repr__(self): return f"<JobSalary {self.id}>"
class Strategy(db.Model): __tablename__ = 'strategies' id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) refno = db.Column('refno', db.String(), nullable=False) created_at = db.Column('created_at', db.DateTime(), server_default=func.now()) content = db.Column('content', db.String(), nullable=False) org_id = db.Column('org_id', db.Integer(), db.ForeignKey('orgs.id'), nullable=False) tactics = db.relationship('StrategyTactic', backref=db.backref('strategy'))
class ChangeLog(db.Model): __tablename__ = 'changelog' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(45), unique=True, nullable=False) created = db.Column(db.String(20), nullable=False) @staticmethod def add_params(name: str, *obj: object): log = ChangeLog.query.filter_by(name=name).all() successful = False if log is not None and len(log) > 0: return else: try: changelog = ChangeLog() for o in obj: try: db.session.add(o) successful = True except Exception as e: Logger.info(e) db.session.rollback() successful = False if successful: changelog.name = name changelog.created = str(int(dt.now().timestamp())) db.session.add(changelog) db.session.commit() except Exception as e: Logger.info(e) db.session.rollback() raise
class User(db.Model): id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(255), nullable=True) email = db.Column(db.String(255), nullable=False) password = db.Column(db.Text()) def __repr__(self): return "{username}'s account" def set_password(self, password): self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) def delete_account(self): db.session.delete(self) db.session.commit() def reset_password(self, old_password, new_password): if check_password_hash(self.password, old_password) and new_password: self.password = new_password db.session.commit() def save(self): db.session.add(self) db.session.commit()
class Mission(db.Model): __tablename__ = 'missions' id = db.Column('id', db.Integer(), primary_key=True, autoincrement=True) name = db.Column('name', db.String(), nullable=False) def __repr__(self): return u'{}:{}'.format(self.id, self.name)
class FollowUpSummary(db.Model): __tablename__ = 'follow_up_summary' id = db.Column(db.Integer, primary_key=True) program_id = db.Column(db.Integer, db.ForeignKey('academic_programs.id')) post_grad_employment_rate = db.Column(db.Float()) survey_year = db.Column(db.Integer())
class Comments(db.Model): __tablename__ = "comments" comment_id = db.Column(db.Integer, primary_key=True) pizza_id = db.Column(db.Integer()) user_id = db.Column(db.Integer()) comment = db.Column(db.String()) user_id = db.Column(db.Integer, db.ForeignKey("users.user_id"), nullable=False) pizza_id = db.Column(db.Integer, db.ForeignKey("pizzas.pizza_id"), nullable=False) def __repr__(self): return f"<{self.user_id} comment on {self.pizza_id} = {self.comment}>"
class TaskType(db.Model): __tablename__ = 'task_type' id = db.Column(db.Integer(), primary_key=True) type = db.Column(db.Integer(), nullable=False, unique=True) name = db.Column(db.String(20), nullable=False, unique=True) tags = db.Column(db.String(255)) @staticmethod def create(_type, name, *tags: str): taskType = TaskType() taskType.type = _type taskType.name = name taskType.tags = "" for t in tags: taskType.tags += "{};".format(t) return taskType
class Person(db.Model): id = db.Column(db.Integer, primary_key=True) nick = db.Column(db.String(128)) email = db.Column(db.String(128), unique=True) tshirt = db.Column(db.String(128)) price = db.Column(db.Integer()) days = db.Column(db.String(128)) paid = db.Column(db.Boolean()) token = db.Column(db.String(32)) def __init__(self, nick, email, tshirt, price, days): self.nick = nick self.email = email self.tshirt = tshirt self.price = price self.days = days self.token = hashlib.sha256(os.urandom(32)).hexdigest() self.paid = False def serialize(self): r = vars(self) if "_sa_instance_state" in r: del r["_sa_instance_state"] return r
class My_Anime(db.Model ): # creating a My_Anime class inheriting from db.model __tablename__ = "My_Anime" # explicitly providing the name of the table id = db.Column( db.Integer, primary_key=True ) # column id, integer set onto a primary key, must be unique anime_title = db.Column(db.String()) # anime title, string anime_started = db.Column( db.DateTime, default=datetime.fromisoformat) # anime started, date anime_finished = db.Column( db.DateTime, default=datetime.fromisoformat) # anime finished, date rating / 100 = db.Column(db.Integer()) # anime rating out of 100, integer profile_id_fk = db.Column( db.Integer, db.ForeignKey("profile.id"), nullable=False ) # foreign key linked to Profile, integer, must be present @classmethod def date_filter(cls, year, month, day, user_id): # data filtering function sql_query = text( "SELECT * FROM My_Anime WHERE DATE(anime_started) = ':year-:month-:day' and profile_id_fk=':user_id';" ) # sql query, anime_started: year, month, day and profile id sql_query = text( "SELECT * FROM My_Anime WHERE DATE(anime_finished) = ':year-:month-:day' and profile_id_fk=':user_id';" ) # sql query, anime_finished: year, month, day and profile id return db.engine.execute(sql_query, { "year": year, "month": month, "day": day, "user_id": user_id }) def __repr__(self): return f"<My_Anime {self.journal_entry}>"
class Competes(db.Model): __tablename__ = 'competes' uid = db.Column(db.Integer(), primary_key=True, nullable=False) cid = db.Column(db.Integer(), nullable=False) # status = db.Column(db.String(200), nullable = False) def __init__(self, uid, cid): self.uid = uid self.cid = cid # self.status = status def __repr__(self): return "<competes(uid='%s', cid='%s')>" % (self.uid, self.cid)
class FavPizza(db.Model): __tablename__ = "fav_pizza" fav_pizza_id = db.Column(db.Integer, primary_key=True) pizza_id = db.Column(db.Integer()) user_id = db.Column(db.Integer()) pizza_id = db.Column(db.Integer, db.ForeignKey("pizzas.pizza_id"), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey("users.user_id"), nullable=False) def __repr__(self): return f"<{self.pizza_id} favourited pizza/s are {self.pizza_id}>"
class Playlist(db.Model): __tablename__ = "playlists" id = db.Column(db.Integer, primary_key=True) playlist_title = db.Column(db.String()) playlist_s_tracks_count = db.Column(db.Integer()) playlist_s_users_count = db.Column(db.Integer()) playlist_s_tracks = db.relationship("Track", secondary=tpat, back_populates="track_s_playlists") playlist_s_users = db.relationship("User", secondary=upat, back_populates="user_s_playlists") def __repr__(self): return f"<Track {self.playlist_title}>"
class Likes(db.Model): __tablename__ = "likes" likes_id = db.Column(db.Integer, primary_key=True) comment_id = db.Column(db.Integer()) user_id = db.Column(db.Integer()) likes = db.Column(db.Boolean()) user_id = db.Column(db.Integer, db.ForeignKey("users.user_id"), nullable=False) comment_id = db.Column(db.Integer, db.ForeignKey("comments.comment_id"), nullable=False) def __repr__(self): return f"<{self.user_id} on {self.comment_id} = {self.likes}>"