Esempio n. 1
0
class Recipient(BasePersonModel):

    __tablename__ = 'recipient'
    height = Column(db.Integer)
    bike_recieved = Column(db.DateTime)
    delivery_date = Column(db.DateTime)
    consult_date = Column(db.DateTime)
    bike_id = reference_col('bike', nullable=True)
    bike = relationship('Bike', backref='recipient')
    accessory_id = reference_col('accessory', nullable=True)
    accessory = relationship('Accessory', backref='recipient')
Esempio n. 2
0
class Extra(SurrogatePK, Model):
    """A extra profile."""

    __tablename__ = 'extras'
    user_id = reference_col('users', nullable=True)
    user = relationship('User', backref='extras')
    name = Column(db.String(80), nullable=True)
    last_name = Column(db.String(255), nullable=True)
    birthday = Column(db.DateTime(), nullable=True)
    phone = Column(db.Integer(), nullable=True)
    genre = Column(db.String(6), nullable=True)
    address = Column(db.String(200), nullable=True)
    province_id = reference_col('provinces', nullable=True)
    province = relationship('Province', backref='extras')
    locality_id = reference_col('localities', nullable=True)
    locality = relationship('Locality', backref='extras')
    nationality = Column(db.String(20), nullable=True)
    vat_number = Column(db.String(11), unique=True, nullable=True)
    insurance_number = Column(db.BigInteger(), unique=True, nullable=True)
    height = Column(db.Integer(), nullable=True)
    weight = Column(db.Integer(), nullable=True)
    tshirt_size_id = reference_col('tshirt_sizes', nullable=True)
    tshirt_size = relationship('TshirtSize', backref='extras')
    trouser_size_id = reference_col('trouser_sizes', nullable=True)
    trouser_size = relationship('TrouserSize', backref='extras')
    foot_size_id = reference_col('foot_sizes', nullable=True)
    foot_size = relationship('FootSize', backref='extras')
    eye_color_id = reference_col('eye_colors', nullable=True)
    eye_color = relationship('EyeColor', backref='extras')
    hair_color_id = reference_col('hair_colors', nullable=True)
    hair_color = relationship('HairColor', backref='extras')
    profession = Column(db.String(80), nullable=True)
    availability = Column(db.String(255), nullable=True)
    driving_license = Column(db.Boolean(), nullable=True)
    driving_license_type_id = reference_col('driving_licenses_types',
                                            nullable=True)
    driving_license_type = relationship('DrivingLicense', backref='extras')
    hobbies = Column(db.String(200), nullable=True)
    extra_experience = Column(db.Boolean(), nullable=True)
    dance_experience = Column(db.Boolean(), nullable=True)
    singing_experience = Column(db.Boolean(), nullable=True)
    sea_experience = Column(db.Boolean(), nullable=True)
    waiter_experience = Column(db.Boolean(), nullable=True)
    other_experience = Column(db.String(80), nullable=True)
    face_image = Column(db.String(255), nullable=True)
    body_image = Column(db.String(255), nullable=True)
    created_at = Column(db.DateTime(),
                        nullable=True,
                        default=dt.datetime.utcnow)

    def __init__(self, vat_number, **kwargs):
        """Create instance."""
        db.Model.__init__(self, vat_number=vat_number, **kwargs)

    def __repr__(self):
        return '<Extra({vat_number})>'.format(vat_number=self.vat_number)
Esempio n. 3
0
class Comment(Model, SurrogatePK):
    __tablename__ = 'comment'

    id = db.Column(db.Integer, primary_key=True)
    body = Column(db.Text)
    createdAt = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    updatedAt = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    author_id = reference_col('userprofile', nullable=False)
    author = relationship('UserProfile', backref=db.backref('comments'))
    article_id = reference_col('article', nullable=False)

    def __init__(self, article, author, body, **kwargs):
        db.Model.__init__(self,
                          author=author,
                          body=body,
                          article=article,
                          **kwargs)
Esempio n. 4
0
class UserProfile(Model, SurrogatePK):
    __tablename__ = 'userprofile'

    # id is needed for primary join, it does work with SurrogatePK class
    id = db.Column(db.Integer, primary_key=True)

    user_id = reference_col('users', nullable=False)
    user = relationship('User', backref=db.backref('profile', uselist=False))
    follows = relationship('UserProfile',
                           secondary=followers_assoc,
                           primaryjoin=id == followers_assoc.c.follower,
                           secondaryjoin=id == followers_assoc.c.followed_by,
                           backref='followed_by',
                           lazy='dynamic')

    def __init__(self, user, **kwargs):
        db.Model.__init__(self, user=user, **kwargs)

    def is_following(self, profile):
        return bool(self.follows.filter(followers_assoc.c.followed_by == profile.id).count())

    def follow(self, profile):
        if self is not profile and not self.is_following(profile):
            self.follows.append(profile)
            return True
        return False

    def unfollow(self, profile):
        if self is not profile and self.is_following(profile):
            self.follows.remove(profile)
            return True
        return False

    @property
    def following(self):
        if current_identity:
            return current_identity.profile.is_following(self)
        return False

    @property
    def username(self):
        return self.user.username

    @property
    def bio(self):
        return self.user.bio

    @property
    def image(self):
        return self.user.image

    @property
    def email(self):
        return self.user.email
Esempio n. 5
0
class Bike(PkModel):

    __tablename__ = 'bike'

    name = Column(db.String(150))
    color = Column(db.String(100))
    size_chart_to_use = Column(db.String(50))
    bottom_tube_length = Column(db.Integer)
    brakes = Column(db.String(50))
    shifters = Column(db.String(50))
    water_bottle = Column(db.Boolean)
    lights = Column(db.Boolean)
    bell = Column(db.Boolean)
    rack = Column(db.Boolean)
    pannier = Column(db.Boolean)
    kickstand = Column(db.Boolean)
    notes = Column(db.Text)
    intake_date = Column(db.DateTime)
    bike_tech_review_date = Column(db.DateTime)
    drop_off_date = Column(db.DateTime)
    mechanic_id = reference_col('mechanic', nullable=True)
    mechanic = relationship('Mechanic', backref='bike')
    donor_id = reference_col('donor', nullable=True)
    donor = relationship('Donor', backref='bike')
Esempio n. 6
0
class Locality(SurrogatePK, Model):
    """The localities."""

    __tablename__ = 'localities'
    name = Column(db.String(80), nullable=False)
    postal_code = Column(db.Integer(), nullable=False)
    province_id = reference_col('provinces', nullable=False)
    province = relationship('Province', backref='localities')

    def __init__(self, name, **kwargs):
        """Create instance."""
        db.Model.__init__(self, name=name, **kwargs)

    def __repr__(self):
        return '<Locality({name})>'.format(name=self.name)
Esempio n. 7
0
class Accessory(PkModel):

    __tablename__ = 'accessory'
    item_name = Column(db.String(200))
    donor_id = reference_col('donor')
    donor = relationship('Donor', backref='accessory')
Esempio n. 8
0
class Article(SurrogatePK, Model):
    __tablename__ = 'article'

    id = db.Column(db.Integer, primary_key=True)
    slug = Column(db.Text, unique=True)
    title = Column(db.String(100), nullable=False)
    description = Column(db.Text, nullable=False)
    body = Column(db.Text)
    createdAt = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    updatedAt = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow)
    author_id = reference_col('userprofile', nullable=False)
    author = relationship('UserProfile', backref=db.backref('articles'))
    favoriters = relationship('UserProfile',
                              secondary=favoriter_assoc,
                              backref='favorites',
                              lazy='dynamic')

    tagList = relationship('Tags', secondary=tag_assoc, backref='articles')

    comments = relationship('Comment',
                            backref=db.backref('article'),
                            lazy='dynamic')

    def __init__(self, author, title, body, description, slug=None, **kwargs):
        db.Model.__init__(self,
                          author=author,
                          title=title,
                          description=description,
                          body=body,
                          slug=slug or slugify(title),
                          **kwargs)

    def favourite(self, profile):
        if not self.is_favourite(profile):
            self.favoriters.append(profile)
            return True
        return False

    def unfavourite(self, profile):
        if self.is_favourite(profile):
            self.favoriters.remove(profile)
            return True
        return False

    def is_favourite(self, profile):
        return bool(
            self.query.filter(
                favoriter_assoc.c.favoriter == profile.id).count())

    def add_tag(self, tag):
        if tag not in self.tagList:
            self.tagList.append(tag)
            return True
        return False

    def remove_tag(self, tag):
        if tag in self.tagList:
            self.tagList.remove(tag)
            return True
        return False

    @property
    def favoritesCount(self):
        return len(self.favoriters.all())

    @property
    def favorited(self):
        if current_identity:
            profile = current_identity.profile
            return self.query.join(Article.favoriters).filter(
                UserProfile.id == profile.id).count() == 1
        return False