Exemple #1
0
class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), nullable=False, unique=True)
    email = db.Column(db.String(200), nullable=False, unique=True)
    password = db.Column(db.String(200))
    avatar_image = db.Column(db.String(100), default=None)
    is_active = db.Column(db.Boolean(), default=False)
    created_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now())
    updated_at = db.Column(db.DateTime(), nullable=False, server_default=db.func.now(), onupdate=db.func.now())

    recipes = db.relationship('Recipe', backref='user')
    pantry = db.relationship('Pantry', backref='user')

    @classmethod
    def get_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def get_by_email(cls, email):
        return cls.query.filter_by(email=email).first()

    @classmethod
    def get_by_id(cls, id):
        return cls.query.filter_by(id=id).first()

    def save(self):
        db.session.add(self)
        db.session.commit()
Exemple #2
0
class LibraryEntry(db.Model):
    __tablename__ = 'libraries'
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    game_id = db.Column(db.Integer, db.ForeignKey('games.id'), nullable=False)
    release_id = db.Column(db.Integer,
                           db.ForeignKey('releases.id'),
                           nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    play_status_id = db.Column(db.Integer,
                               db.ForeignKey('play_statuses.id'),
                               nullable=False)
    score = db.Column(db.Integer)
    own = db.Column(db.Integer, nullable=False, default=1)
    digital = db.Column(db.Integer, nullable=False, default=0)
    hours = db.Column(db.Integer)
    notes = db.Column(db.String)
    created_at = db.Column(db.DateTime, nullable=True, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=True,
                           default=datetime.now,
                           onupdate=datetime.now)

    game = db.relationship('Game')
    release = db.relationship('Release')
    user = db.relationship('User')
    play_status = db.relationship('PlayStatus')

    def __repr__(self):
        return '<LibraryEntry %r>' % self.id
Exemple #3
0
class user_personal(db.Model):

    __tablename__ = 'user_personal'
    id = db.Column(db.Integer, primary_key=True)
    surname = db.Column(db.String(20), nullable=False)
    first_name = db.Column(db.String(30), nullable=False)
    middle_name = db.Column(db.String(20))
    birth_date = db.Column(db.Date, nullable=False)
    blood_group = db.Column(db.String(3), nullable=False)
    civil_status = db.Column(db.String(1), nullable=False)
    gender = db.Column(db.String(1), nullable=False)
    nationality = db.Column(db.String(10), nullable=False)
    religion = db.Column(db.String(30))
    education = db.Column(db.String(30))
    occupation = db.Column(db.String(30))

    #Relationships
    user_address_id = db.relationship('user_address',
                                      backref='user_personal',
                                      lazy=True)
    user_contact_id = db.relationship('user_contact',
                                      backref='user_personal',
                                      lazy=True)

    def __repr__(self, active=True):
        return '<user_personal {}>'.format(self.surname)
class Recommendation(db.Model):
    __tablename__ = 'recommendations'
    __table_args__ = {'extend_existing': True}

    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    game_id = db.Column(db.Integer, db.ForeignKey('games.id'), nullable=False)
    release_id = db.Column(db.Integer,
                           db.ForeignKey('releases.id'),
                           nullable=False)
    second_game_id = db.Column(db.Integer,
                               db.ForeignKey('games.id'),
                               nullable=False)
    second_release_id = db.Column(db.Integer,
                                  db.ForeignKey('releases.id'),
                                  nullable=False)
    created_at = db.Column(db.DateTime, nullable=True, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=True,
                           default=datetime.now,
                           onupdate=datetime.now)

    user = db.relationship('User')
    game = db.relationship('Game', foreign_keys=[game_id])
    release = db.relationship('Release', foreign_keys=[release_id])
    recommended_game = db.relationship('Game', foreign_keys=[second_game_id])
    recommended_release = db.relationship('Release',
                                          foreign_keys=[second_release_id])

    def __repr__(self):
        return '<Recommendation %r>' % self.id
Exemple #5
0
class PageSection(db.Model):
    section_type_enum = {
        1: 'page',
        2: 'tab',
        3: 'details',
        4: 'form',
        5: 'search',
        6: 'html',
        7: 'buttons',
        8: 'search_buttons',
        9: 'list',
        10: 'analysis',
        11: 'editor'
    }
    __tablename__ = 'page_section'
    id = Column(VARCHAR(32), default=generate_uuid, primary_key=True)
    title = Column(VARCHAR(32), comment='标题')
    entity_id = Column(VARCHAR(32),
                       ForeignKey('entity.id', ondelete='CASCADE'),
                       comment='实例ID')
    entity_params = Column(VARCHAR(300), comment='查询实体的参数')
    page_id = Column(VARCHAR(32),
                     ForeignKey('page.id', ondelete='CASCADE'),
                     comment='页面ID')
    html_content = Column(Text, comment='页面内容')
    section_type = Column(TINYINT, comment='组件类型')
    has_add_btn = Column(Boolean, default=False, comment='是否显示添加按钮')
    nodes = Column(JSON, comment='Page Section 中的所有节点', default=[])
    config = Column(JSON, comment='页面段落的展示样式配置', default={})

    sort = Column(Integer)
    create_time = Column(BigInteger, comment='创建时间')

    page = db.relationship(Page,
                           backref=backref('page_section', order_by=sort))
    entity = db.relationship('Entity', backref='page_section')

    page_section_to = db.relationship(
        'PageSectionTab',
        backref=backref('to', uselist=False),
        primaryjoin=id == PageSectionTab.to_page_section_id,
        lazy='dynamic',
        uselist=True)
    page_section_from = db.relationship(
        'PageSectionTab',
        backref=backref('from', uselist=False),
        primaryjoin=id == PageSectionTab.from_page_section_id,
        lazy='dynamic',
        uselist=True)

    @classmethod
    def section_type_to_string(cls, section_type: int) -> str:
        assert section_type in cls.section_type_enum, '没有对应的page类型'
        return cls.section_type_enum[section_type]

    @classmethod
    def string_to_data_type(cls, data_string: str) -> int:
        for k, v in cls.section_type_enum.items():
            if data_string == v:
                return k
Exemple #6
0
class Colonne(db.Model):
    numCol = db.Column(db.Integer, primary_key=True)
    graphId = db.Column(db.Integer, db.ForeignKey('graphique.graphId'))
    graphique = db.relationship("Graphique",
                                backref=db.backref("colonnes", lazy="dynamic"))
    colName = db.Column(db.String(255))
    dateDebut = db.Column(db.Date())
    dateFin = db.Column(db.Date())
    agregatSimple = db.Column(db.String(255))
    capteur_id = db.Column(db.Integer, db.ForeignKey('capteur.captId'))
    capteur = db.relationship("Capteur")

    def __repr__(self):
        return "<Colonne (%d) (%s) >" % (self.numCol, self.colName)

    @property
    def aggreger(self):
        return agregats.get(self.agregatSimple, lambda x: 0)

    @property
    def valeurs(self):
        valeurs = [m.valeur for m in self.capteur.mesures.all()]
        if not self.agregatSimple:
            return valeurs
        else:
            v = self.aggreger(valeurs)
            return [v for _ in range(len(self.capteur.mesures.all()))]

    @property
    def valeurs_datees(self):
        return list(zip(self.dates, self.valeurs))

    @property
    def dates(self):
        return [m.date for m in self.capteur.mesures.all()]
Exemple #7
0
class Round(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    poem_id = db.Column(db.Integer, db.ForeignKey('poem.id'), nullable=False)
    number = db.Column(db.Integer)
    current = db.Column(db.Boolean, default=True)
    length = db.Column(
        db.Integer)  # if corpus is timed, then length is prescriptive
    first_line_id = db.Column(db.Integer, db.ForeignKey("line.id"))
    second_line_id = db.Column(db.Integer, db.ForeignKey("line.id"))
    first_line = db.relationship(
        'Line',
        foreign_keys=[first_line_id],
        backref='roundAppearingAsPrompt',
        lazy=True)  #maybe alias as exposed_line for number > 0
    second_line = db.relationship('Line',
                                  foreign_keys=[second_line_id],
                                  backref='roundWrittenIn',
                                  lazy=True)
    start_time = db.Column(db.DateTime,
                           server_default=db.func.now(),
                           nullable=False)
    completed_time = db.Column(db.DateTime, nullable=True)

    def __init__(self, number):
        self.number = number

    def complete(self):
        self.current = False
Exemple #8
0
class Post(db.Model):
    id = db.Column(db.Integer,
                   index=True,
                   primary_key=True,
                   autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    text = db.Column(db.Text, nullable=False)
    title = db.Column(db.String, nullable=False)
    image = db.Column(db.Text, nullable=True)
    likes = db.Column(db.Integer, default=0)
    user = db.relationship('User', lazy=True, backref='post')
    comment = db.relationship('Comment',
                              lazy=True,
                              backref='post',
                              uselist=True)
    created_at = db.Column(db.DateTime, default=datetime.datetime.now())

    def save(self):
        db.create_all()
        db.session.add(self)
        db.session.commit()

    def update(self):
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Exemple #9
0
class CompanyModel(db.Model):
    __tablename__ = "companies"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    telephone = db.Column(db.String(40), nullable=False)
    default_off_days = db.Column(db.Integer)
    address_id = db.Column(db.Integer, db.ForeignKey('addresses.id'))
    users = db.relationship('UserModel',
                            back_populates='company',
                            lazy="select")
    address = db.relationship('AddressModel',
                              uselist=False,
                              back_populates='company',
                              lazy="select")
    employee_quota = db.relationship('RemainingEmployeeModel',
                                     uselist=False,
                                     back_populates='company',
                                     lazy="select")

    __table_args__ = (db.CheckConstraint(
        'default_off_days >= 0', name='check_default_off_days_positive'), )

    def save_to_db(self) -> int:
        db.session.add(self)
        db.session.commit()
        db.session.refresh(self)
        return self.id
Exemple #10
0
class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), nullable=False, unique=True)
    email = db.Column(db.String(200), nullable=False, unique=True)
    password = db.Column(db.String(200), nullable=False)
    is_turkuamk = db.Column(db.Boolean(), default=False)
    is_admin = db.Column(db.Boolean(), default=False)
    created_at = db.Column(db.DateTime(),
                           nullable=False,
                           server_default=db.func.now())
    reservations = db.relationship('Reservation', backref='user')
    timeframes = db.relationship('Timeframes', backref='user')

    @classmethod
    def get_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def get_by_email(cls, email):
        return cls.query.filter_by(email=email).first()

    @classmethod
    def get_by_id(cls, user_id):
        return cls.query.filter_by(id=user_id).first()

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Exemple #11
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(128), unique=True)
    password = db.Column(db.LargeBinary(128), nullable=False)
    primary_email_id = db.Column(db.Integer,
                                 db.ForeignKey('email.id',
                                               name='fk_primary_email'),
                                 nullable=True)

    primary_email = db.relationship(
        'Email',
        post_update=True,
        primaryjoin='User.primary_email_id==Email.id')
    email = db.relationship('Email',
                            back_populates='user',
                            primaryjoin='User.id==Email.user_id')
    track_list = association_proxy('tracked_product', 'product')

    def __init__(self, username=None, password=None, primary_email=None):
        self.username = username
        self.password = password
        self.primary_email = primary_email

    def __repr__(self):
        return f'username: {repr(self.username)}, email: {repr(self.email)}'
Exemple #12
0
class Kindness(db.Model):
    __tablename__ = "Kindness"

    id_kindness = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(50))
    identifier = db.Column(db.String(40), unique=True, nullable=False)
    body = db.Column(db.Text, nullable=False)
    latitude = db.Column(db.Float, nullable=False)
    longitude = db.Column(db.Float, nullable=False)
    post_date = db.Column(db.DateTime, default=datetime.datetime.now)
    user_id = db.Column(db.Integer, db.ForeignKey('Users.id'), nullable=False)
    unnamed = db.Column(db.Boolean, default=False)
    likes = db.relationship('Likes', backref='likes', lazy='dynamic')
    files = db.relationship('Kindness_Files', backref='file', lazy=True)
    tags = db.relationship('Tags',
                           secondary=kindness_tags_association,
                           lazy='subquery',
                           backref=db.backref('kindness', lazy=True))

    def __repr__(self):
        return '<Kindness {}>'.format(self.title)

    def to_json(self):
        return {
            "idPost": self.identifier,
            "title": self.title,
            "body": self.body,
            "latitude": self.latitude,
            "longitude": self.longitude,
            "postDate": self.post_date,
            "userId": self.user_id
        }
Exemple #13
0
class Drugclass(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), unique=True, nullable=False)
    beers_criteria = db.Column(db.Text, nullable=True)
    stopp_start_criteria = db.Column(db.Text, nullable=True)
    drugs = db.relationship('Drug', backref='drugclass')
    notes = db.relationship('Note', backref='drugclass')
Exemple #14
0
class Personel(db.Model):
    __tablename__ = 'personel'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), nullable=False, unique=True)
    firstname = db.Column(db.String(80))
    lastname = db.Column(db.String(80))
    email = db.Column(db.String(200), nullable=False, unique=True)
    phone_number = db.Column(db.String(200))
    role = db.Column(db.String(80))
    password = db.Column(db.String(200))
    is_active = db.Column(db.Boolean(), default=False)
    created_at = db.Column(db.DateTime(),
                           nullable=False,
                           server_default=db.func.now())
    updated_at = db.Column(db.DateTime(),
                           nullable=False,
                           server_default=db.func.now(),
                           onupdate=db.func.now())

    facilities = db.relationship('Facility', backref='personel')

    animals = db.relationship('Animal', backref='personel')

    @classmethod
    def get_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

    @classmethod
    def get_by_email(cls, email):
        return cls.query.filter_by(email=email).first()

    def save(self):
        db.session.add(self)
        db.session.commit()
Exemple #15
0
class CIRelation(db.Model):
    __tablename__ = "ci_relations"
    cr_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    first_ci_id = db.Column(db.Integer,
                            db.ForeignKey("cis.ci_id"),
                            primary_key=True)
    second_ci_id = db.Column(db.Integer,
                             db.ForeignKey("cis.ci_id"),
                             primary_key=True)
    first_ci = db.relationship("CI",
                               primaryjoin="CI.ci_id==CIRelation.first_ci_id")
    second_ci = db.relationship(
        "CI", primaryjoin="CI.ci_id==CIRelation.second_ci_id")
    relation_type = db.Column(db.String(8),
                              db.Enum("connect",
                                      "deploy",
                                      "install",
                                      "contain",
                                      name="relation_type"),
                              nullable=False)
    more = db.Column(db.Integer, db.ForeignKey("cis.ci_id"))

    __table_args__ = (db.UniqueConstraint("first_ci_id",
                                          "second_ci_id",
                                          name="first_second_uniq"), )
Exemple #16
0
class UserDishWeight(db.Model):
    __tablename__ = 'user_dish_weight'
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True)
    dish_id = db.Column(db.Integer, db.ForeignKey('dish.id'), primary_key=True)
    user = db.relationship('User')
    dish = db.relationship('Dish')
    weight = db.Column(db.Float, default=1.0)
Exemple #17
0
class Role(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), unique=True)
    users = db.relationship('User', back_populates='role')
    permissions = db.relationship('Permission',
                                  secondary=roles_permissions,
                                  back_populates='roles')

    @staticmethod
    def init_role():
        roles_permissions_map = {
            'Locked': ['FOLLOW', 'COLLECT'],
            'User': ['FOLLOW', 'COLLECT', 'COMMENT', 'UPLOAD'],
            'Moderator':
            ['FOLLOW', 'COLLECT', 'COMMENT', 'UPLOAD', 'MODERATE'],
            'Administrator': [
                'FOLLOW', 'COLLECT', 'COMMENT', 'UPLOAD', 'MODERATE',
                'ADMINISTER'
            ]
        }

        for role_name in roles_permissions_map:
            role = Role.query.filter_by(name=role_name).first()
            if role is None:
                role = Role(name=role_name)
                db.session.add(role)
            role.permissions = []
            for permission_name in roles_permissions_map[role_name]:
                permission = Permission.query.filter_by(
                    name=permission_name).first()
                if permission is None:
                    permission = Permission(name=permission_name)
                    db.session.add(permission)
                role.permissions.append(permission)
        db.session.commit()
Exemple #18
0
class User(db.Model):
    id = db.Column(db.String(80), primary_key=True, nullable=False)
    # 1(Organisation)-to-many(User)
    org_id = db.Column(db.String(80),
                       db.ForeignKey('organisation.id'),
                       nullable=False)

    username = db.Column(db.String(120), nullable=False)
    email = db.Column(db.String(120), nullable=False)
    password = db.Column(db.String(256), nullable=False)
    name = db.Column(db.String(120), nullable=False)
    user_type = db.Column(db.Enum(UserType), nullable=False)
    created_at = db.Column(db.DateTime(), nullable=False)

    # 1(User)-to-Many(ProjectManager)
    project_managers = db.relationship('ProjectManager', backref='user')
    labels = db.relationship('Label', backref='user',
                             lazy=True)  # 1(User)-to-Many(Label)

    def __repr__(self):
        return f"<User {self.id} | {self.username} ({self.name}) ({self.email}) | Organisation : {self.org_id}>"

    def to_response(self):
        return {
            "orgId": self.org_id,
            "username": self.username,
            "email": self.email,
            "userType": self.user_type.name,
            "name": self.name,
            "id": self.id,
            "created_at": self.created_at
        }
Exemple #19
0
class facilityData(db.Model):
    __tablename__ = 'facility'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    facility_name = db.Column(db.String(128), nullable=False)

    stations = db.relationship('MedstationData', backref='facility', lazy=True, cascade="all, delete, delete-orphan")
    users = db.relationship('userData', backref='facility', lazy=True, cascade="all, delete, delete-orphan")

    def __init__(self, data) -> None:
        '''class constructor'''
        self.facility_name = data.get('facility_name')

    def save(self):
        db.session.add(self)
        db.session.commit()

    def update(self, data):
        for key, item in data.items():
            setattr(self, key, item)

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    def _asdict(self):
        return dict(
            id=self.id,
            facility_name=self.facility_name,
            users=[user._asdict() for user in self.users],
            stations=[station._asdict() for station in self.stations]
        )

    def __repr__(self) -> str:
        return "{}".format(self.facility_name)
Exemple #20
0
class Grant(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id',
                                                  ondelete='CASCADE'))
    user = db.relationship('User')

    client_id = db.Column(
        db.String(40),
        db.ForeignKey('client.client_id'),
        nullable=False,
    )
    client = db.relationship('Client')

    code = db.Column(db.String(255), index=True, nullable=False)

    redirect_uri = db.Column(db.String(255))
    expires = db.Column(db.DateTime)

    _scopes = db.Column(db.Text)

    def delete(self):
        db.session.delete(self)
        db.session.commit()
        return self

    @property
    def scopes(self):
        if self._scopes:
            return self._scopes.split()
        return []
Exemple #21
0
class Teacher(db.Model):
    __tablename__ = 'teacher'

    teacher_id = db.Column(db.Integer, primary_key=True)
    teacher_username = db.Column(db.String(80), nullable=False, unique=True)
    teacher_password = db.Column(db.String(200))
    created_at = db.Column(db.DateTime(),
                           nullable=False,
                           server_default=db.func.now())
    updated_at = db.Column(db.DateTime(),
                           nullable=False,
                           server_default=db.func.now(),
                           onupdate=db.func.now())

    reservations_A = db.relationship('Reservation_A', backref='teacher')
    reservations_B = db.relationship('Reservation_B', backref='teacher')
    reservations_C = db.relationship('Reservation_C', backref='teacher')
    reservations_D = db.relationship('Reservation_D', backref='teacher')

    @classmethod
    def get_by_teacher_username(cls, teacher_username):
        return cls.query.filter_by(teacher_username=teacher_username).first()

    def save(self):
        db.session.add(self)
        db.session.commit()
Exemple #22
0
class Token(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    client_id = db.Column(
        db.String(40),
        db.ForeignKey('client.client_id'),
        nullable=False,
    )
    client = db.relationship('Client')

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User')

    # currently only bearer is supported
    token_type = db.Column(db.String(40))

    access_token = db.Column(db.String(255), unique=True)
    refresh_token = db.Column(db.String(255), unique=True)
    expires = db.Column(db.DateTime)
    _scopes = db.Column(db.Text)

    @property
    def scopes(self):
        if self._scopes:
            return self._scopes.split()
        return []
class Application(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    last_name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), nullable=False)
    tel = db.Column(db.String(19), nullable=False)
    car_brand_id = db.Column(db.Integer, db.ForeignKey('car_brand.id'), nullable=False)
    car_brand = db.relationship('CarBrand')
    car_model_id = db.Column(db.Integer, db.ForeignKey('car_model.id'), nullable=False)
    car_model = db.relationship('CarModel')
    unique_track_number = db.Column(db.Integer, default=_generate_unique_track_number)
    date = db.Column(db.DateTime, default=datetime.now())
    status_id = db.Column(db.Integer, db.ForeignKey('status.id'), default=1)
    status = db.relationship('Status')

    def __repr__(self):
        return f'<Application id: {self.id}, Name: {self.name}, Last name: {self.last_name}, E-mail: {self.email},' \
               f' Telephone number: {self.tel}, Car brand id: {self.car_brand_id}, Car model id: {self.car_model_id}, ' \
               f'Date: {self.date} '

    def serialize(self):
        result = {
            'track_number': self.unique_track_number,
            'car_brand': self.car_brand.name,
            'car_model': self.car_model.name,
            'price': self.car_model.price,
            'date': self.date,
            'status': self.status.name
        }
        return result
Exemple #24
0
class Genre(db.Model):
    __ftcolumns__ = 'name, raw_desc'

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(4096))
    image = db.Column(db.String(4096))
    desc = db.Column(db.Text)
    raw_desc = db.Column(db.Text)

    games = db.relationship('Game', secondary=game_genre_assoc, back_populates='genres')
    direct_events = db.relationship('Event', secondary=event_genre_assoc)
    indirect_events = db.relationship('Event',
                                      viewonly=True,
                                      secondary=join(game_genre_assoc, event_game_assoc,
                                                     game_genre_assoc.c.game_id == event_game_assoc.c.game_id).alias())

    developers = db.relationship('Developer',
                                 viewonly=True,
                                 secondary=join(game_genre_assoc, game_developer_assoc,
                                                game_genre_assoc.c.game_id == game_developer_assoc.c.game_id).alias())

    def json(self):
        return {'id': self.id,
                'img': self.image,
                'name': self.name,
                'desc': self.desc,
                'games': [(game.id, game.primary_name) for game in self.games],
                'events': [(event.id, event.name) for event in self.events],
                'developers': [(developer.id, developer.name) for developer in self.developers]
                }

    @hybrid_property
    def events(self):
        return self.direct_events or self.indirect_events
Exemple #25
0
class Artist(db.Model):
    __tablename__ = 'Artist'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False, unique=True)
    city_id = db.Column(db.Integer, db.ForeignKey('City.id'), nullable=False)
    phone = db.Column(db.String(120), nullable=True)
    image_link = db.Column(db.String(500), nullable=True)
    facebook_link = db.Column(db.String(120), nullable=True)
    website = db.Column(db.String(120), nullable=True)
    seeking_venue = db.Column(db.Boolean, nullable=True)
    seeking_description = db.Column(db.String, nullable=True)
    genres = db.relationship('Genre', secondary=artist_genres,
      backref=db.backref('artists', lazy=True))
    regitration_time = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    @aggregated('upcoming_shows', db.Column(db.Integer))
    def num_upcoming_shows(self):
        return db.func.count(Show.id)
    upcoming_shows = db.relationship('Show', 
      primaryjoin='and_(Artist.id == Show.artist_id, cast(Show.start_time, Date) >= func.current_date())',
      order_by='Show.start_time')
    @aggregated('past_shows', db.Column(db.Integer))
    def num_past_shows(self):
        return db.func.count(Show.id)
    past_shows = db.relationship('Show', 
      primaryjoin='and_(Artist.id == Show.artist_id, cast(Show.start_time, Date) < func.current_date())',
      order_by='Show.start_time')
    shows = db.relationship('Show', cascade="delete", backref=db.backref('artist', lazy=True))
Exemple #26
0
class Developer(db.Model):
    __ftcolumns__ = 'name, raw_desc, website'

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(4096))
    image = db.Column(db.String(4096))
    desc = db.Column(db.Text)
    raw_desc = db.Column(db.Text)
    website = db.Column(db.String(4096))

    games = db.relationship('Game', secondary=game_developer_assoc, back_populates='developers')

    genres = db.relationship('Genre',
                             viewonly=True,
                             secondary=join(game_developer_assoc, game_genre_assoc,
                                            game_developer_assoc.c.game_id == game_genre_assoc.c.game_id).alias())

    def json(self):
        return {'id': self.id,
                'img': self.image,
                'name': self.name,
                'desc': self.desc,
                'games': [(game.id, game.primary_name) for game in self.games],
                'genres': [(genre.id, genre.name) for genre in self.genres],
                'website': self.website
                }
Exemple #27
0
class user_account(UserMixin, db.Model):

    __tablename__ = 'user_account'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user_personal.id'),
                        nullable=False)
    role_id = db.Column(db.Integer,
                        db.ForeignKey('user_role.id'),
                        nullable=False)
    username = db.Column(db.String(30), nullable=False)
    password = db.Column(db.String(30), nullable=False)
    date_created = db.Column(db.DateTime, nullable=False)
    last_active = db.Column(db.DateTime, nullable=False)
    status = db.Column(db.String(1), nullable=False)

    user_account_id = db.relationship('blood_center',
                                      backref='user_account',
                                      lazy=True)
    user_request_id = db.relationship('blood_request',
                                      backref='user_account',
                                      lazy=True)
    user_participate_id = db.relationship('event_participate',
                                          backref='user_account',
                                          lazy=True)

    def __repr__(self, active=True):
        return '<user_account {}>'.format(self.username)
Exemple #28
0
class House(db.Model):
    __tablename__ = 'house'
    houseID = db.Column(db.String(20), primary_key=True)
    housetitle = db.Column(db.String(40), nullable=False)
    city = db.Column(db.String(10), nullable=False)
    district = db.Column(db.String(10), nullable=False)
    area = db.Column(db.String(50), nullable=False)
    street = db.Column(db.String(50), nullable=False)
    community = db.Column(db.String(50), nullable=False)
    room = db.Column(db.String(10), nullable=False)
    lng = db.Column(db.String(30), nullable=False)
    lat = db.Column(db.String(30), nullable=False)
    housepic = db.Column(db.String(200), nullable=False)
    housearea = db.Column(db.Float, nullable=False)
    housedirect = db.Column(db.String(5), nullable=False)
    housefloor = db.Column(db.String(5), nullable=False)
    househall = db.Column(db.String(10), nullable=False)
    balcony = db.Column(db.Boolean, nullable=False)
    bathroom = db.Column(db.Boolean, nullable=False)
    housestatus = db.Column(db.Boolean, nullable=False)
    housetype = db.Column(db.String(5), nullable=False)
    housearound = db.Column(db.Text)
    # 外码
    tenanttel = db.Column(db.String(11), db.ForeignKey('user.usertel'))
    # relationship
    tenant = db.relationship('User', backref=db.backref('renthouse'))
    pics = db.relationship('Housepic', backref=db.backref('house'))
    prices = db.relationship('Payment', backref=db.backref('house'))
Exemple #29
0
class CITypeRelation(db.Model):
    __tablename__ = "ci_type_relations"

    ctr_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    parent_id = db.Column(db.Integer,
                          db.ForeignKey("ci_types.type_id"),
                          primary_key=True)
    parent = db.relationship(
        "CIType", primaryjoin="CIType.type_id==CITypeRelation.parent_id")
    child_id = db.Column(db.Integer,
                         db.ForeignKey("ci_types.type_id"),
                         primary_key=True)
    child = db.relationship(
        "CIType", primaryjoin="CIType.type_id==CITypeRelation.child_id")
    relation_type = db.Column(db.String(7),
                              db.Enum("contain",
                                      "connect",
                                      "deploy",
                                      "install",
                                      name="relation_type"),
                              default="contain")

    __table_args__ = (db.UniqueConstraint("parent_id",
                                          "child_id",
                                          name="parent_child_uniq"), )
Exemple #30
0
class Quantity(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    quantity = db.Column(db.Float)

    recipe_id = db.Column(db.Integer,
                          db.ForeignKey('recipe.id', ondelete="CASCADE"),
                          nullable=False)
    recipe = db.relationship('Recipe',
                             backref=db.backref('quantities',
                                                cascade="all,delete",
                                                lazy=True))

    ingredient_id = db.Column(db.Integer,
                              db.ForeignKey('ingredient.id'),
                              nullable=False)
    ingredient = db.relationship('Ingredient',
                                 backref=db.backref('quantities', lazy=True))

    measurement_id = db.Column(db.Integer,
                               db.ForeignKey('measurement.id'),
                               nullable=False)
    measurement = db.relationship('Measurement',
                                  backref=db.backref('quantities', lazy=True))

    def __init__(self, quantity, recipe, ingredient, measurement):
        self.quantity = quantity
        self.recipe = recipe
        self.ingredient = ingredient
        self.measurement = measurement

    def __repr__(self):
        return '<Quantity %r>' % self.quantity