class Track(db.Model):
    __tablename__ = "tracks"

    id = db.Column(db.Integer, primary_key=True)
    album_id = db.Column(db.Integer,
                         db.ForeignKey("albums.id"),
                         nullable=False)
    album = db.relationship("Album", back_populates="tracks")
    artist_id = db.Column(db.Integer,
                          db.ForeignKey("artists.id"),
                          nullable=False)
    artist = db.relationship("Artist", back_populates="tracks")
    disc_number = db.Column(db.Integer, nullable=False, default=1)
    duration_ms = db.Column(db.Integer, nullable=False)
    explicit = db.Column(db.Boolean, nullable=False, default=False)
    href = db.Column(db.String(),
                     nullable=False,
                     default="https://api.spotify.com/tracks/<id>")
    name = db.Column(db.String(), nullable=False)
    popularity = db.Column(db.Integer, nullable=False, default=0)
    preview_url = db.Column(db.String(),
                            nullable=False,
                            default="https://p.scdn.co/mp3-preview/<id>")
    track_number = db.Column(db.Integer, nullable=False)
    object_type = db.Column(db.String(20), nullable=False, default="track")
    uri = db.Column(db.String(), nullable=False, default="spotify:track:<id>")
    is_local = db.Column(db.Boolean, nullable=False, default=False)
Exemplo n.º 2
0
class Ticket(db.Model):
    """
    Model for tickets
    """

    __tablename__ = "tickets"

    id = db.Column(db.Integer, primary_key=True)
    transaction_id = db.Column(db.String(128), nullable=False)
    movie = db.Column(db.Integer, db.ForeignKey('movies.id'), nullable=False)
    cinema = db.Column(db.Integer, db.ForeignKey('cinemas.id'), nullable=False)
    show_time = db.Column(db.String(8), nullable=False)
    no_of_seats = db.Column(db.Integer, nullable=False)
    ticket_date = db.Column(db.Date, nullable=False)
    transaction_date = db.Column(db.Date,
                                 nullable=False,
                                 default=datetime.utcnow)
    user = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    def pre_commit_setup(self):
        """
        This method is used to generate uuids for each ticket transaction.
        """

        self.transaction_id = uuid.uuid1()
Exemplo n.º 3
0
class Product(db.Model):
    """
    Product Model Class
    """
    __tablename__ = 'product'
    __bind_key__ = 'products'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120), unique=True, nullable=False)
    description = db.Column(db.String(400), nullable=True)
    price = db.Column(db.DECIMAL(10, 2), nullable=False)
    """
    Save product details in database
    """
    def save(self):
        db.session.add(self)
        db.session.commit()

    """
    Delete product
    """

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

    """
    Generate json data
    """

    def to_json(self):
        return {
            'id': self.id,
            'name': self.name,
            'price': str(round(self.price, 2)),
            'description': self.description
        }

    """
    Find user by name
    """

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

    """
    Find user by id
    """

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

    """
    Return all products
    """

    @classmethod
    def return_all(cls):
        return {'products': [prod.to_json() for prod in Product.query.all()]}
Exemplo n.º 4
0
class Album(db.Model):
    __tablename__ = "albums"

    id = db.Column(db.Integer, primary_key=True)
    album_type = db.Column(db.String(20), nullable=False, default="album")
    artist_id = db.Column(db.Integer,
                          db.ForeignKey("artists.id"),
                          nullable=False)
    artist = db.relationship("Artist", back_populates="albums")
    copyright = db.Column(db.String(100), nullable=False)
    copyright_type = db.Column(db.String(1), nullable=False)
    genre = db.Column(db.String(20), nullable=False)
    href = db.Column(db.String(),
                     nullable=False,
                     default="https://api.spotify.com/albums/<id>")
    label = db.Column(db.String(50), nullable=False)
    name = db.Column(db.String(), nullable=False)
    release_date = db.Column(db.Integer, nullable=False)
    release_date_precision = db.Column(db.String(5),
                                       nullable=False,
                                       default="year")
    object_type = db.Column(db.String(20), nullable=False, default="album")
    tracks = db.relationship("Track", back_populates="album")
    uri = db.Column(db.String(), nullable=False, default="spotify:album:<id>")

    def __repr__(self):
        return f"<Album {self.name}>"
Exemplo n.º 5
0
class Cinema(db.Model):
    """
    Model for cinemas
    """
    __tablename__ = "cinemas"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120), nullable=False)
    show_times = db.Column(ARRAY(db.String(8)))
    city = db.Column(db.Integer, db.ForeignKey('cities.id'), nullable=False)
    movies = db.relationship("Movie",
                             secondary='shows',
                             back_populates="cinemas")
Exemplo n.º 6
0
class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(25), nullable=False, unique=True)
    email = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String, nullable=False)
    address = db.Column(db.String(50))
    phone_address = db.Column(db.String(50))
    created_on = db.Column(db.DateTime, index=False)
    last_login = db.Column(db.DateTime, index=False)

    def __init__(self,
                 username,
                 email,
                 password,
                 address=None,
                 phone_address=None):
        self.username = username
        self.email = email
        self.password = password
        self.address = address
        self.phone_address = phone_address

    def __repr__(self):
        return "<id {}>".format(self.id)

    def set_password(self, password):
        """Create hashed password."""
        self.password = generate_password_hash(password, method="sha256")

    def check_password(self, password):
        """Check hashed password."""
        return check_password_hash(self.password, password)

    def create(self, req):
        user_fields = {
            "username", "email", "password", "address", "phone_address"
        }
        assign_req_values(req, user_fields, None)
        new_user = User(
            username=req["username"],
            email=req["email"],
            password=req["password"],
            address=req["address"],
            phone_address=req["phone_address"],
        )
        return new_user
Exemplo n.º 7
0
class Move(db.Model):
    __tablename__ = "moves"

    move_id = db.Column(db.Integer, primary_key=True)
    move_name = db.Column(db.String(), nullable=False)

    def __repr__(self):
        return f"<(#{self.move_id} {self.move_name})>"

    @staticmethod
    def get_move_data(move_id):
        """
        Requests move data from pokeapi and returns the data as JSON
        """

        return json.loads(
            requests.get(f"https://pokeapi.co/api/v2/move/{move_id}").text)

    @staticmethod
    def get_move_list(pokemon_data, move_set):
        """
        Returns a list of learnable moves since a pokemon can't know the same move twice
        """

        learned_moves = {move.move.move_name for move in move_set}
        return [[
            move["move"]["name"],
            move["move"]["url"].replace("https://pokeapi.co/api/v2/move/",
                                        "").replace("/", "")
        ] for move in pokemon_data["moves"]
                if move["move"]["name"] not in learned_moves]
Exemplo n.º 8
0
class Checklist(db.Model):
    __tablename__ = "checklists"

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(), nullable=False)
    owner_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    is_group = db.Column(db.Boolean, nullable=False, default=False)
    repeat_id = db.Column(db.Integer, nullable=False, default=0)
    description = db.Column(db.String())
    thumbnail_image = db.Column(db.String())
    users = db.relationship("User",
                            secondary=users_checklists,
                            back_populates="checklists")
    items = db.relationship("Item",
                            backref="checklist",
                            cascade="all, delete-orphan")
Exemplo n.º 9
0
class Weight(db.Model):
    """体重表"""
    __tablename__ = "tb_weight"

    uid = db.Column(db.String(8), comment="用户id")
    weight = db.Column(db.Float, comment="体重")
    create_time = db.Column(db.Integer, comment="创建时间")
Exemplo n.º 10
0
class Artist(db.Model):
    __tablename__ = "artists"

    id = db.Column(db.Integer, primary_key=True)
    albums = db.relationship("Album", back_populates="artist")
    followers = db.Column(db.Integer, nullable=False, default=0)
    genre = db.Column(db.String(20), nullable=False)
    href = db.Column(db.String(),
                     nullable=False,
                     default="https://api.spotify.com/artists/<id>")
    name = db.Column(db.String(), nullable=False)
    popularity = db.Column(db.Integer, nullable=False, default=0)
    object_type = db.Column(db.String(20), nullable=False, default="artist")
    tracks = db.relationship("Track", back_populates="artist")
    uri = db.Column(db.String(), nullable=False, default="spotify:artist:<id>")

    def __repr__(self):
        return f"<Artist {self.name}>"
Exemplo n.º 11
0
class User(db.Model):
    """用户信息表"""
    __tablename__ = "tb_user"

    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.String(8), comment="用户id")
    birth_date = db.Column(db.Integer, comment="出生日期")
    sex = db.Column(db.Integer, comment="性别")
    height = db.Column(db.Integer, comment="身高")
    weight = db.Column(db.Float, comment="体重")
    create_time = db.Column(db.Integer, comment="创建时间")
Exemplo n.º 12
0
class Movie(db.Model):
    """
    Model form movie details
    """
    __tablename__ = "movies"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120), nullable=False)
    release_date = db.Column(db.DateTime)
    cinemas = db.relationship("Cinema",
                              secondary='shows',
                              back_populates="movies")
Exemplo n.º 13
0
class Item(db.Model):
    __tablename__ = "items"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), nullable=False)
    status = db.Column(db.Boolean, nullable=False, default=False)
    index = db.Column(db.Integer, nullable=False, default=1)
    checklist_id = db.Column(db.Integer,
                             db.ForeignKey("checklists.id"),
                             nullable=False)
    assigned_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    completion_date = db.Column(db.DateTime(), nullable=True)
Exemplo n.º 14
0
class User(db.Model):
    """
    User model for storing user data
    """
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    phone_number = db.Column(db.String(10), unique=True, nullable=False)
    password = db.Column(db.String(128), nullable=False)
    tickets = db.relationship("Ticket")

    @classmethod
    def check_password(cls, password, _hash):
        return django_pbkdf2_sha256.verify(password, _hash)

    def pre_commit_setup(self):
        """
        This method generates the required fields either from available
        information else automatic fields are generated.
        """
        self.password = django_pbkdf2_sha256.hash(self.password)
Exemplo n.º 15
0
class Show(db.Model):
    __tablename__ = "shows"
    movie_id = db.Column(db.Integer,
                         db.ForeignKey('movies.id'),
                         primary_key=True)
    cinema_id = db.Column(db.Integer,
                          db.ForeignKey('cinemas.id'),
                          primary_key=True)
    show_times = db.Column(db.String(8), nullable=False, primary_key=True)
    show_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    no_of_seats = db.Column('no_of_seats', db.Integer, nullable=False)
    cinema = db.relationship("Cinema", backref="shows")
Exemplo n.º 16
0
class User(db.Model, UserMixin):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(), nullable=False, unique=True)
    username = db.Column(db.String(30), nullable=False, unique=True)
    password = db.Column(db.String(), nullable=False)
    teams = db.relationship("Team",
                            backref="owner",
                            cascade="all, delete-orphan")

    def __repr__(self):
        return f"<User {self.email}>"

    @classmethod
    def check_unique_email(cls, email):
        """
        Checks uniqueness of an email address, returns True if unique
        """

        if User.query.filter_by(email=email).first():
            return False
        return True

    @classmethod
    def check_unique_username(cls, username):
        """
        Checks uniqueness of a username, returns True if unique
        """

        if User.query.filter_by(username=username).first():
            return False
        return True

    def check_password(self, password):
        """
        Checks that password data entered in a form matches the password has in the database
        """

        return bcrypt.check_password_hash(self.password, password)
Exemplo n.º 17
0
class City(db.Model):
    """
    List of cities  which are playing movies
    """
    __tablename__ = "cities"

    id = db.Column(db.Integer, primary_key=True)
    city_name = db.Column(db.String(80), nullable=False)
    cinemas = db.relationship("Cinema")

    @hybrid_property
    def movies(self):
        return list(chain(*[cinema.movies for cinema in self.cinemas]))
Exemplo n.º 18
0
class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(), nullable=False, unique=True)
    password = db.Column(db.String(), nullable=False)
    username = db.Column(db.String(), nullable=False, unique=True)
    name = db.Column(db.String())
    profile_image = db.Column(db.String())
    timezone = db.Column(db.Integer, nullable=False, default=0)
    has_reminders = db.Column(db.Boolean, nullable=False, default=False)
    reminder_time = db.Column(db.Integer, default=None)
    checklists = db.relationship("Checklist",
                                 secondary=users_checklists,
                                 back_populates="users")
    owned_checklists = db.relationship("Checklist",
                                       backref="owner",
                                       cascade="all, delete-orphan")
    items = db.relationship("Item", backref="assigned_to")

    def __repr__(self):
        return f"<User {self.email}>"
Exemplo n.º 19
0
class FeatureRequest(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(80), nullable = False)
    description = db.Column(db.String(120))
    client_id = db.Column(db.Integer, db.ForeignKey('client.id'), nullable = False)
    client = db.relationship("Client", back_populates = "feature_requests")

    def __init__(self, title, description, client_id):
        self.title = title
        self.description = description
        self.client_id = client_id

    def __repr__(self):
        return '<FeatureRequest %s>' % self.title

    def jsonify(self):
       """Return JSON representation of the object"""
       return {
           'id' : self.id,
           'title': self.title,
           'description': self.description,
           'client_id': self.client_id
       }
Exemplo n.º 20
0
class Team(db.Model):
    __tablename__ = "teams"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    description = db.Column(db.String(2000), nullable=True)
    is_private = db.Column(db.Boolean, nullable=False, default=True)
    owner_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    team_pokemon = db.relationship("Teams_Pokemon", backref="team", cascade="all, delete-orphan")

    def __repr__(self):
        return f"<Team {self.id}: {self.name}>"

    @staticmethod
    def sort_team_pokemon(teams):
        """
        Sorts pokemon in team.team_pokemon by team index for a list of teams
        """

        if type(teams) == list:
            for team in teams:
                team.team_pokemon.sort(key=lambda x: x.team_index)
            return teams

    @staticmethod
    def fill_empty_team_slots(team_list_dict):
        """
        Takes a list of team dicts and fills empty pokemon slots with None
        """

        for team in team_list_dict:
            indices = [pokemon["team_index"] for pokemon in team["team_pokemon"]]
            for i in range(6):
                if i + 1 not in indices:
                    team["team_pokemon"].insert(i, None)
        return team_list_dict
Exemplo n.º 21
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    login = db.Column(db.String(80), nullable=False)
    password = db.Column(PasswordType(schemes=['pbkdf2_sha512']),
                         nullable=False)

    def __init__(self, login, password):
        self.login = login
        self.password = password

    def __repr__(self):
        return '<User %s>' % self.login

    def jsonify(self):
        """Return JSON representation of the object"""
        return {'id': self.id, 'login': self.login}
class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(), nullable=False, unique=True)
    password = db.Column(db.String(), nullable=False)
    country = db.Column(db.String(2), nullable=True)
    display_name = db.Column(db.String(30), nullable=True)
    href = db.Column(db.String(),
                     nullable=False,
                     default="https://api.spotify.com/users/<id>")
    product = db.Column(db.String(20), nullable=False, default="free")
    object_type = db.Column(db.String(20), nullable=False, default="user")
    uri = db.Column(db.String(), nullable=False, default="spotify:user:<id>")
    track_ratings = db.relationship("Track_Rating", backref="user")
    admin = db.Column(db.Boolean, nullable=False, default=False)

    def __repr__(self):
        return f"<User {self.email}>"
Exemplo n.º 23
0
class InvalidatedToken(db.Model):
    token = db.Column(db.String(120), primary_key=True)
    invalidated_date = db.Column(db.DateTime(timezone=True),
                                 server_default=func.now())

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

    def __repr__(self):
        return '<InvalidatedToken %s, %s>' % (self.token,
                                              str(self.invalidated_date))

    def jsonify(self):
        """Return JSON representation of the object"""
        return {
            'token': self.token,
            'invalidated_date': str(self.invalidated_date)
        }
Exemplo n.º 24
0
class RevokedTokenModel(db.Model):
    """
    Revoked Token Model Class
    """
    __tablename__ = 'revoked_tokens'
    __bind_key__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(120))
    """
    Save Token in DB
    """
    def add(self):
        db.session.add(self)
        db.session.commit()

    """
    Checking that token is blacklisted
    """

    @classmethod
    def is_jti_blacklisted(cls, jti):
        query = cls.query.filter_by(jti=jti).first()
        return bool(query)
Exemplo n.º 25
0
class Client(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), nullable=False)
    feature_requests = db.relationship("FeatureRequest",
                                       back_populates="client")

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

    def __repr__(self):
        return '<Client %s>' % self.name

    def jsonify(self):
        """Return JSON representation of the object"""
        return {
            'id':
            self.id,
            'name':
            self.name,
            'feature_requests': [
                feature_request.jsonify()
                for feature_request in self.feature_requests
            ]
        }
Exemplo n.º 26
0
class User(db.Model):
    """
    User Model Class
    """
    __tablename__ = 'user'
    __bind_key__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(120), nullable=False)
    first_name = db.Column(db.String(120), nullable=True)
    last_name = db.Column(db.String(120), nullable=True)
    """
    Save user details in database
    """
    def save(self):
        db.session.add(self)
        db.session.commit()

    """
    Delete user
    """

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

    """
    Generate json data
    """

    def to_json(self):
        return {
            'id': self.id,
            'username': self.username,
            'password': self.password,
            'first_name': self.first_name,
            'last_name': self.last_name
        }

    """
    Find user by username
    """

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

    """
    Find user by id
    """

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

    """
    Return all the user data
    """

    @classmethod
    def return_all(cls):
        return {'users': [user.to_json() for user in User.query.all()]}

    """
    Generate hash from password
    """

    @staticmethod
    def generate_hash(password):
        return sha256.hash(password)

    """
    Verify hash and password
    """

    @staticmethod
    def verify_hash(password, hash_):
        return sha256.verify(password, hash_)