class Dog(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) description = db.Column(db.String) breed_id = db.Column(db.Integer, db.ForeignKey('breed.id')) breed = db.relationship(Breed, backref='dogs') user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship(User, backref='dogs') photo = db.Column(db.Unicode) size = db.Column(db.String) born_date = db.Column(db.Date) location = db.Column(db.String) def __init__(self, name, description=None, size=None, photo=None, born_date=None, breed_id=None, location=None, user_id=None): self.name = name self.description = description self.size = size self.photo = photo self.born_date = born_date self.breed_id = breed_id self.location = location self.user_id = user_id def __repr__(self): return u'<Dog %s>' % self.name
class EventPromoter(db.Model): class Role(IntEnum): COPROMOTER = auto() MAIN = auto() class Status(IntEnum): PENDING = auto() APPROVED = auto() REJECTED = auto() event_id = db.Column(db.Integer, db.ForeignKey('event.id'), primary_key=True) promoter_id = db.Column(db.Integer, db.ForeignKey('promoter.id'), primary_key=True) role = db.Column(db.Integer, default=Role.MAIN.value, nullable=False) status = db.Column(db.Integer, default=Status.PENDING.value, nullable=False) event = db.relationship('Event', backref=db.backref('event_promoters')) promoter = db.relationship('Promoter', backref=db.backref('event_promoters', lazy='dynamic'))
class Promoter(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), nullable=False, unique=True, index=True) name = db.Column(db.String(100), nullable=False, index=True) description = db.Column(db.String) created_on = db.Column(db.DateTime, nullable=False, default=datetime.now) longitude = db.Column(db.Float(precision=9)) latitude = db.Column(db.Float(precision=9)) email = db.Column(db.String(40)) category_id = db.Column(db.Integer, db.ForeignKey('event_category.id')) category = db.relationship(EventCategory) users = db.relationship('User', secondary='promoter_user', backref=db.backref('promoters')) def __repr__(self): return f'<Promoter: {self.username}>' def get_user_role(self, user: User): promoter_user = PromoterUser.query.filter( PromoterUser.user == user).first() return promoter_user.role
class Accountdetails(db.Model): __tablename__ = "accountdetails" id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) company = db.Column(db.String(128), nullable=False) job_title = db.Column(db.String(100), nullable=False) city = db.Column(db.String(100), nullable=False) country = db.Column(db.String(100), nullable=False) instituition = db.Column(db.String(100), nullable=False) about_me = db.Column(db.String(140), nullable=False) def __init__(self, **kwargs): super(Accountdetails, self).__init__(**kwargs) def to_json(self): return { 'id': self.id, 'user_id': self.user_id, 'company': self.company, 'job_title': self.job_title, 'city': self.city, 'country': self.country, 'instituition': self.instituition, 'about_me': self.about_me }
class PromoterUser(db.Model): class Role(IntEnum): SUPPORT = auto() CREATOR = auto() ADMIN = auto() promoter_id = db.Column(db.Integer, db.ForeignKey('promoter.id'), primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) role = db.Column(db.Integer, default=Role.SUPPORT.value, nullable=False) promoter = db.relationship('Promoter', backref=db.backref('roles')) user = db.relationship('User', backref=db.backref('roles')) @classmethod def get_minimum_role_for_event(cls): return cls.Role.CREATOR
class Parecer(db.Model): __tablename__ = 'parecer' id = db.Column(db.Integer, primary_key=True) fiscalCampo = db.Column(db.String(50)) bilhete_id = db.Column(db.Integer, db.ForeignKey('bilhete.id')) def __init__(self, fiscalCampo=None, bilhete_id=None): self.fiscalCampo = fiscalCampo self.bilhete_id = bilhete_id
class EventCategory(db.Model): __tablename__ = 'event_category' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False, unique=True, index=True) description = db.Column(db.String) default = db.Column(db.Boolean, default=False) parent_id = db.Column(db.Integer, db.ForeignKey('event_category.id'), nullable=True) children = db.relationship('EventCategory') def __repr__(self): return f'<Event category: {self.name}'
class EventUpdate(db.Model): class Tag(IntEnum): GENERAL = auto() TICKETS = auto() DATES = auto() LINE_UP = auto() MERCH = auto() LOCATION = auto() id = db.Column(db.Integer, primary_key=True) event_id = db.Column(db.Integer, db.ForeignKey('event.id')) datetime = db.Column(db.DateTime, nullable=False, default=datetime.now) tag = db.Column(db.Integer, nullable=False, default=Tag.GENERAL.value) text = db.Column(db.Text)
class Elimination(db.Model): __tablename__ = 'elimination' id = db.Column(db.Integer, primary_key=True, autoincrement=True) replay_id = db.Column(db.Integer, db.ForeignKey('replay.id', ondelete='CASCADE')) eliminator = db.Column(db.String(255), nullable=False) eliminated = db.Column(db.String(255), nullable=False) knocked = db.Column(db.Boolean) weapon_type = db.Column(db.Integer, default=False, nullable=False) time = db.Column(db.DateTime, default=False, nullable=False) def __init__(self, replayId, **kwargs): super(Elimination, self).__init__(**kwargs) def __json__(self): return ['eliminator', 'eliminated', 'knocked', 'weapon_type', 'time']
class ProfileImage(db.Model): __tablename__ = "profileimage" id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) image_location = db.Column(db.String(128), nullable=False) border_radius = db.Column(db.String(100), nullable=False) status = db.Column(db.String(140), nullable=False) def __init__(self, **kwargs): super(ProfileImage, self).__init__(**kwargs) def to_json(self): return { 'id': self.id, 'user_id': self.user_id, 'image_location': self.image_location, 'border_radius': self.border_radius, 'status': self.status, }
class Pomodoro(db.Model): id = db.Column(db.Integer, primary_key=True) length_seconds = db.Column(db.Integer, default=1500) # Default 25 minutes end_time = db.Column(db.DateTime, default=datetime.utcnow) context = db.Column(db.String(80), default="") interruptions = db.Column(db.Integer) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) @staticmethod def create_new_pomodoro(context, interruptions, user_id): pomodoro = Pomodoro(context=context, interruptions=interruptions, user_id=user_id) db.session.add(pomodoro) db.session.commit() @staticmethod def past_n_days(n, user_id): now = datetime.utcnow() n_days_ago = now - timedelta(days=n) # TODO: floor to midnight res = db.session.query(Pomodoro).filter( Pomodoro.user_id == user_id, Pomodoro.end_time > n_days_ago, Pomodoro.end_time <= now).all() return res
class Event(db.Model): minumum_duration = relativedelta(minutes=30) id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) longitude = db.Column(db.Float(precision=9)) latitude = db.Column(db.Float(precision=9)) datetime_from = db.Column(db.DateTime, nullable=False, default=datetime.now) datetime_to = db.Column(db.DateTime) capacity = db.Column(db.Integer, default=0) profit = db.Column(db.Boolean, default=False, nullable=False) subcateogries = db.relationship('EventCategory', secondary=event_subcategories) main_category_id = db.Column(db.Integer, db.ForeignKey('event_category.id')) main_category = db.relationship('EventCategory') updates = db.relationship('EventUpdate', backref='event') def __repr__(self): return f'Event: {self.name}' @classmethod def create_event(cls, user: User, main_promoters: list, copromoters: list = [], **kwargs): event = cls(**kwargs) db.session.add(event) db.session.commit() for promoter in main_promoters: event.assign_promoter(promoter=promoter, user=user, main=True) for promoter in copromoters: event.assign_promoter(promoter, user) return event def assign_promoter(self, promoter: Promoter, user: User, main: bool = False): event_promoter = EventPromoter(event=self, promoter=promoter, role=EventPromoter.Role.MAIN.value) user_role = promoter.get_user_role(user) if user_role >= PromoterUser.Role.CREATOR.value: event_promoter.status = EventPromoter.Status.APPROVED db.session.add(event_promoter) db.session.commit() def create_update(self, text: str, tag: int = None, **kwargs): event_update = EventUpdate(tag=tag, text=text) self.updates.append(event_update) db.session.commit() return event_update
from enum import IntEnum, auto from dateutil.relativedelta import relativedelta from project.app import db from project.apps.promoter.models.promoter import Promoter, PromoterUser from project.apps.user.models.user import User from .eventCategory import EventCategory from .eventUpdate import EventUpdate event_subcategories = db.Table( 'event_subcategories', db.Column('event_id', db.Integer, db.ForeignKey('event.id'), primary_key=True), db.Column('category_id', db.Integer, db.ForeignKey('event_category.id'), primary_key=True)) class Event(db.Model): minumum_duration = relativedelta(minutes=30) id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) longitude = db.Column(db.Float(precision=9)) latitude = db.Column(db.Float(precision=9)) datetime_from = db.Column(db.DateTime,
class Application(db.Model): __tablename__ = "applications" id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) domain = db.Column(db.String(128), nullable=False) certificate = db.Column(db.String(128), nullable=False) contact_firstname = db.Column(db.String(128), nullable=True) contact_lastname = db.Column(db.String(128), nullable=True) contact_email = db.Column(db.String(128), nullable=True) contact_streetaddress = db.Column(db.String(128), nullable=True) contact_homecountry = db.Column(db.String(128), nullable=True) contact_phonenumber = db.Column(db.String(128), nullable=True) contact_company_name = db.Column(db.String(128), nullable=True) education_highest_degree = db.Column(db.String(128), nullable=True) education_year = db.Column(db.String(128), nullable=True) education_school = db.Column(db.String(128), nullable=True) education_city = db.Column(db.String(128), nullable=True) education_country = db.Column(db.String(128), nullable=True) general_main_language = db.Column(db.String(128), nullable=True) general_coding_years = db.Column(db.Integer(), nullable=True) general_coding_languages = db.Column(db.String(256), nullable=True) general_industry = db.Column(db.String(128), nullable=True) requirements_project_name_1 = db.Column(db.String(128), nullable=True) requirements_project_description_1 = db.Column(db.String(512), nullable=True) requirements_project_start_date_1 = db.Column(db.String(128), nullable=True) requirements_project_start_date_2 = db.Column(db.String(128), nullable=True) requirements_responsible = db.Column(db.String(128), nullable=True) requirements_accountable = db.Column(db.String(128), nullable=True) requirements_consulted = db.Column(db.String(128), nullable=True) requirements_informed = db.Column(db.String(128), nullable=True) requirements_project_company_1 = db.Column(db.String(128), nullable=True) requirements_project_reference_name_1 = db.Column(db.String(128), nullable=True) requirements_project_reference_email_1 = db.Column(db.String(128), nullable=True) requirements_project_reference_phonenumber_1 = db.Column(db.String(128), nullable=True) terms_agree = db.Column(db.String(128), nullable=True) status = db.Column(db.String(128), nullable=True) def __init__(self, **kwargs): super(Application, self).__init__(**kwargs) def to_json(self): return { 'id': self.id, 'domain': self.domain, 'certificate': self.certificate, 'contact_firstname': self.contact_firstname, 'contact_lastname': self.contact_lastname, 'contact_email': self.contact_email, 'contact_streetaddress': self.contact_streetaddress, 'contact_homecountry': self.contact_homecountry, 'contact_phonenumber': self.contact_phonenumber, 'contact_company_name': self.contact_company_name, "education_highest_degree": '', "education_year": self.education_year, "education_school": self.education_school, "education_city": self.education_city, "education_country": self.education_country, "general_main_language": self.general_main_language, "general_coding_years": self.general_coding_years, "general_coding_languages": self.general_coding_languages, "general_industry": self.general_industry, "requirements_project_name_1": self.requirements_project_name_1, "requirements_project_description_1": self.requirements_project_description_1, "requirements_project_start_date_1": self.requirements_project_start_date_1, "requirements_project_start_date_2": self.requirements_project_start_date_2, "requirements_responsible": self.requirements_responsible, "requirements_accountable": self.requirements_accountable, "requirements_consulted": self.requirements_consulted, "requirements_informed": self.requirements_informed, "requirements_project_company_1": self.requirements_project_company_1, "requirements_project_reference_name_1": self.requirements_project_reference_name_1, "requirements_project_reference_email_1": self.requirements_project_reference_email_1, "requirements_project_reference_phonenumber_1": self.requirements_project_reference_phonenumber_1, "terms_agree": self.terms_agree, "status": self.status }
class ReplayStats(db.Model): __tablename__ = 'stats' id = db.Column(db.Integer, primary_key=True, autoincrement=True) created_at = db.Column(db.DateTime, nullable=False, server_default=func.now()) replay_id = db.Column(db.Integer, db.ForeignKey('replay.id', ondelete='CASCADE')) username = db.Column(db.String(255), nullable=False) eliminations = db.Column(db.Integer, default=False, nullable=False) accuracy = db.Column(db.Float, default=False, nullable=False) assists = db.Column(db.Integer, default=False, nullable=False) weapon_damage = db.Column(db.Integer, default=False, nullable=False) other_damage = db.Column(db.Integer, default=False, nullable=False) revives = db.Column(db.Integer, default=False, nullable=False) damage_taken = db.Column(db.Integer, default=False, nullable=False) damage_structures = db.Column(db.Integer, default=False, nullable=False) materials_gathered = db.Column(db.Integer, default=False, nullable=False) materials_used = db.Column(db.Integer, default=False, nullable=False) total_traveled = db.Column(db.Integer, default=False, nullable=False) position = db.Column(db.Integer, default=False, nullable=False) replay = db.relationship("Replay", backref="ReplayStats") @hybrid_property def died(self): return any(i for i in self.replay.elimination_events if i.eliminated == self.username and not i.knocked) @hybrid_property def knocks(self): return len([ i for i in self.replay.elimination_events if i.eliminator == self.username and i.knocked ]) @hybrid_property def knocked(self): return len([ i for i in self.replay.elimination_events if i.eliminated == self.username and i.knocked ]) @hybrid_property def winner(self): return self.position == 1 def __init__(self, replay_id, username, stats, team_stats): self.replay_id = replay_id self.username = username self.eliminations = stats['eliminations'] self.accuracy = stats['accuracy'] self.assists = stats['assists'] self.weapon_damage = stats['weapon_damage'] self.other_damage = stats['other_damage'] self.revives = stats['revives'] self.damage_taken = stats['damage_taken'] self.damage_structures = stats['damage_structures'] self.materials_gathered = stats['materials_gathered'] self.materials_used = stats['materials_used'] self.total_traveled = stats['total_traveled'] self.position = team_stats['position'] def __json__(self): return [ 'replay_id', 'username', 'eliminations', 'accuracy', 'assists', 'weapon_damage', 'other_damage', 'revives', 'damage_taken', 'damage_structures', 'materials_gathered', 'materials_used', 'total_traveled', 'position', 'died', 'knocks', 'knocked', 'winner' ]