Exemplo n.º 1
0
class Client(BaseModel):
    client_id = db.Column(db.String(40), unique=True, index=True, nullable=False)
    client_secret = db.Column(db.String(55), unique=True, index=True, nullable=False)

    name = db.Column(db.String(255))

    scopes = db.relationship("Scope",
                             secondary=api_client_scope,
                             back_populates="clients")

    def __init__(self, name=None, scopes=[]):
        self.name = name
        self.scopes = scopes
        self.client_id = gen_salt(40)
        self.client_secret = gen_salt(50)

    @classmethod
    def create(cls, name):
        return Client(name=name)

    # Some properties required by oauthlib.
    @property
    def default_redirect_uri(self):
        return None

    @property
    def default_scopes(self):
        return [scope.name for scope in self.scopes]

    def __repr__(self):
        return self.name
Exemplo n.º 2
0
class AuditEvent(BaseModel):
    who_id = db.Column(UUID(), db.ForeignKey('user.id', ondelete='CASCADE'))
    who = relationship("User")

    section = db.Column(db.String(255))
    action = db.Column(db.String(255))

    object_type = db.Column(db.Unicode(255))
    # This is used to point to the primary key of the linked row.
    object_id = db.Column(UUID)

    # A pointer to a row in the database somewhere.
    object = generic_relationship(object_type, object_id)
Exemplo n.º 3
0
class Scope(BaseModel):
    name = db.Column(db.String(255), unique=True)

    clients = db.relationship("Client",
                              secondary=api_client_scope,
                              back_populates="scopes")

    def __repr__(self):
        return self.name
Exemplo n.º 4
0
class Rock1500Album(BaseModel):
    name = db.Column(db.String(100), unique=True, index=True)

    year = db.Column(db.Integer())

    # the cover art image url
    cover_art_url = db.Column(db.String(255))

    artist_id = db.Column(UUID(), db.ForeignKey('rock1500_artist.id'))
    artist = db.relationship(Rock1500Artist, backref="albums")

    @classmethod
    def find_by_name(cls, name):
        album = Rock1500Album.query.filter_by(name=name).first()
        return album

    def __repr__(self):
        return self.name
Exemplo n.º 5
0
class Rock1500Artist(BaseModel):
    name = db.Column(db.String(100), unique=True, index=True)

    @classmethod
    def find_by_name(cls, name):
        artist = Rock1500Artist.query.filter_by(name=name).first()
        return artist

    def __repr__(self):
        return self.name
Exemplo n.º 6
0
class Rock1500Song(BaseModel):
    title = db.Column(db.String(100), index=True)

    artist_id = db.Column(UUID(),
                          db.ForeignKey('rock1500_artist.id'),
                          nullable=False)
    artist = db.relationship(Rock1500Artist, backref="songs", lazy="joined")

    album_id = db.Column(UUID(),
                         db.ForeignKey('rock1500_album.id'),
                         nullable=False)
    album = db.relationship(Rock1500Album, backref="songs", lazy="joined")

    # The important rank, once it is known.
    rankThisYear = db.Column(db.Integer(), index=True)

    # Previous ranks if known.
    rank2021 = db.Column(db.Integer(), index=True, unique=True)
    rank2020 = db.Column(db.Integer(), index=True, unique=True)
    rank2019 = db.Column(db.Integer(), index=True, unique=True)
    rank2018 = db.Column(db.Integer(), index=True, unique=True)
    rank2017 = db.Column(db.Integer(), index=True, unique=True)
    rank2016 = db.Column(db.Integer(), index=True, unique=True)
    rank2015 = db.Column(db.Integer(), index=True, unique=True)
    rank2014 = db.Column(db.Integer(), index=True, unique=True)

    @classmethod
    def find_by_name(cls, title, artist):
        if not artist.id:
            # If the artist doesn't exist yet, then there won't be any songs by them.
            return None
        song = Rock1500Song.query.filter_by(title=title, artist=artist).first()
        return song

    def __repr__(self):
        return self.title

    def set2017Rank(self, value):
        self.rank2017 = int(value)

    def set2016Rank(self, value):
        self.rank2016 = int(value)

    def set2015Rank(self, value):
        self.rank2015 = int(value)
Exemplo n.º 7
0
class FoodItem(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), nullable=False, unique=True)
    unit_id = db.Column(db.Integer, db.ForeignKey('unit.id'), nullable=False)
    carbohydrates_per_unit = db.Column(db.Integer, nullable=False)
    calories_per_unit = db.Column(db.Integer, nullable=False)
    mealparts = db.relationship('MealPart')

    @property
    def unit(self):
        return self._unit.name

    @unit.setter
    def unit(self, value):
        unit = Unit.query.filter_by(name=value).first()
        if unit is None:
            unit = Unit(name=value)
        self._unit = unit
Exemplo n.º 8
0
class Unit(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), nullable=False)
    fooditems = db.relationship('FoodItem', backref='_unit', lazy=True)