Exemple #1
0
class Track(db.Model):
    """
    Model for storing track information
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(140), unique=True)
    uri = db.Column(db.String(50), unique=True)
    track_id = db.Column(db.String(140), unique=True)

    def __init__(self, track_id, title, uri):
        self.title = title
        self.track_id = track_id
        self.uri = uri

    def __repr__(self):
        return '<Track %r>' % (self.title)

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        return {
            'id': self.id,
            'title': self.title,
            'uri': self.uri,
            'track_id': self.track_id
        }
Exemple #2
0
class AccessToken(db.Model):
    """
    Model for storing OAuth2 token data for a given user
    """
    @classmethod
    def from_json(cls, data):
        token_dict = json.loads(data)
        return cls(token_dict['access_token'], token_dict['token_type'],
                   token_dict['expires_in'], token_dict['refresh_token'])

    id = db.Column(db.Integer, primary_key=True)
    access_token = db.Column(db.String(255))
    token_type = db.Column(db.String(50))
    expires_in = db.Column(db.Integer)
    refresh_token = db.Column(db.String(255))

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref('access_token', lazy='dynamic'))

    def __init__(self, access_token, token_type, expires_in, refresh_token):
        self.access_token = access_token
        self.token_type = token_type
        self.expires_in = expires_in
        self.refresh_token = refresh_token
class Users(db.Model, UserMixin):
    """
    A class to map the users table using SQLAlchemy

    ...

    Attributes
    -------
    user_id : Integer database column
        Holds the id of the user from DB
    username: String databse column
        Holds the username for the user
    email   : String databse column
        Holds the email for the user
    password: String databse column
        Holds the hashed password for the user
    
    Methods
    -------
    get_id()
        Overwrites the get_id from db.Model class
    __repr__()
        Method to represent the class object
    """

    user_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(60), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)

    def get_id(self):
        return (self.user_id)

    def __repr__(self):
        return f"Users('{self.username}', '{self.email}')"
Exemple #4
0
class Songs(db.Model):
    """
    A class to map the songs table using SQLAlchemy

    ...

    Attributes
    -------
    song_id     : Integer database column
        Holds the id of the song
    song_title  : String databse column
        Holds the song name
    seconds     : String databse column
        Holds the duration in seconds
    thumbnail_url: String databse column
        Holds the thumbnail url for song
    album_id    : Integer database column
        Holds the foreign key for albums table
    
    Methods
    -------
    __repr__()
        Method to represent the class object
    """
    song_id = db.Column(db.Integer, primary_key=True)
    song_title = db.Column(db.String(60), nullable=False)
    seconds = db.Column(db.Integer, nullable=False)
    thumbnail_url = db.Column(db.String(200), default='thumbnail.png')
    album_id = db.Column(db.Integer,
                         db.ForeignKey('albums.album_id'),
                         nullable=False)

    def __repr__(self):
        return f"Songs('{self.song_title}', '{self.seconds}', {self.album_id})"
class EventStatus(db.Model, UserMixin):
    time = db.Column(db.Integer, db.ForeignKey('event.time'))
    begin_date = db.Column(db.String(100), primary_key=True)
    end_date = db.Column(db.String(100), primary_key=True)
    status = db.Column(db.String(100), nullable=True)

    def __repr__(self):
        return f"EventStatus('{self.status})"
class City(db.Model, UserMixin):
    pincode = db.Column(db.Integer,
                        db.ForeignKey('place.pincode'),
                        primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    state = db.Column(db.String(75), nullable=True)

    def __repr__(self):
        return f"City('{self.name}', '{self.state}')"
class Place(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    address = db.Column(db.String(75), nullable=True)
    pincode = db.Column(db.Integer, nullable=True, unique=True)
    place = db.relationship('City', backref='places', lazy="dynamic")

    def __repr__(self):
        return f"Place('{self.name}', '{self.pincode}')"
class Label(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    types = db.Column(db.String(75), nullable=True)
    insi = db.Column(db.String(75), nullable=True, unique=True)
    artist = db.relationship('Artist', backref='artist', lazy=True)

    def __repr__(self):
        return f"Label('{self.name}', '{self.insi}')"
class Admin(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    fname = db.Column(db.String(75), nullable=False)
    mname = db.Column(db.String(75), nullable=True)
    lname = db.Column(db.String(75), nullable=True)
    email = db.Column(db.String(128), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)

    def __repr__(self):
        return f"Admin('{self.fname}', '{self.lname}')"
class Artist(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    email = db.Column(db.String(128), unique=True)
    likes = db.Column(db.Integer, default=0)
    dislikes = db.Column(db.Integer, default=0)
    rating = db.Column(db.Integer, default=2)
    song = db.relationship('Song', backref='singer', lazy=True)
    user = db.relationship('User', backref='user_art', uselist=False)
    podcast = db.relationship('Podcast',
                              backref='podcast',
                              lazy=True,
                              uselist=False)
    label_id = db.Column(db.Integer, db.ForeignKey('label.id'))
class Podcast(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=True)
    title = db.Column(db.String(75), nullable=False)
    description = db.Column(db.String, default='No description')
    category = db.Column(db.String, nullable=False)
    release_date = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    pod_file = db.Column(db.String(200), nullable=False)
    image_file = db.Column(db.String(32), nullable=True, default='default.jpg')
    rating = db.Column(db.Integer, default=2)
    likes = db.Column(db.Integer, default=0)
    dislikes = db.Column(db.Integer, default=0)
    artist_id = db.Column(db.Integer, db.ForeignKey('artist.id'))
Exemple #12
0
class Albums(db.Model):
    """
    A class to map the artists table using SQLAlchemy

    ...

    Attributes
    -------
    album_id    : Integer database column
        Holds the id of the album
    album_title : String databse column
        Holds the albums's title
    artist_id   :
        Foreign key for artists table
    songs       : Relationship
        A relationship to songs table
    
    Methods
    -------
    __repr__()
        Method to represent the class object
    """
    album_id = db.Column(db.Integer, primary_key=True)
    album_title = db.Column(db.String(60), nullable=False)
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('artists.artist_id'),
                          nullable=False)
    songs = db.relationship('Songs', backref='songs', lazy=True)

    def __repr__(self):
        return f"Albums('{self.album_title}', {self.artist_id})"
Exemple #13
0
class Artists(db.Model):
    """
    A class to map the artists table using SQLAlchemy

    ...

    Attributes
    -------
    artist_id   : Integer database column
        Holds the id of the artist
    artist      : String databse column
        Holds the artist's name
    albums      : Relationship
        A relationship to albums table
    
    Methods
    -------
    __repr__()
        Method to represent the class object
    """
    artist_id = db.Column(db.Integer, primary_key=True)
    artist = db.Column(db.String(30), nullable=False)
    albums = db.relationship('Albums', backref='albums', lazy=True)

    def __repr__(self):
        return f"Artists('{self.artist}')"
Exemple #14
0
class Playlist(db.Model):
    """
    Model for storing playlist information belonging to a specific user
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), unique=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    user = db.relationship('User',
                           backref=db.backref('playlists', lazy='dynamic'))

    tracks = db.relationship('Track',
                             secondary=tracks,
                             backref=db.backref('playlists', lazy='dynamic'))

    def __init__(self, title, user):
        self.title = title
        self.user = user

    def __repr__(self):
        return '<Playlist %r>' % (self.title)

    @property
    def serialize(self):
        """Return object data in easily serializeable format"""
        return {
            'id': self.id,
            'title': self.title,
            'user': self.user.serialize,
            'tracks': [item.serialize for item in self.tracks]
        }
class Song(db.Model, UserMixin):
    #__searchable__ = ['name', 'genre']
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=False)
    album = db.Column(db.String(75), nullable=False)
    genre = db.Column(db.String(75), nullable=True)
    release_date = db.Column(db.DateTime,
                             nullable=True,
                             default=datetime.utcnow)
    rating = db.Column(db.Integer, default=2)
    likes = db.Column(db.Integer, default=0)
    dislikes = db.Column(db.Integer, default=0)
    song_file = db.Column(db.String(200), nullable=False)
    image_file = db.Column(db.String(32), nullable=True, default='default.jpg')
    artist_id = db.Column(db.Integer, db.ForeignKey('artist.id'))
    contains = db.relationship('Contains', backref='contains', uselist=False)
class User(db.Model, UserMixin):
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(75), nullable=True)
    lname = db.Column(db.String(75), nullable=True)
    username = db.Column(db.String(32), unique=True, nullable=False)
    email = db.Column(db.String(128), unique=True, nullable=False)
    image_file = db.Column(db.String(32), nullable=True, default='default.jpg')
    preflang = db.Column(db.String(20), nullable=True)
    password = db.Column(db.String(60), nullable=False)
    #searches = db.relationship('user_search_history', backref=db.backref('user'))
    #playlists = db.relationship('user_song_playlist', backref=db.backref('user'))
    #songs = db.relationship('Song', secondary=listened)
    posts = db.relationship('Post', backref='author', lazy=True)
    podcasts = db.relationship('Podcast',
                               secondary=subscribed,
                               backref='pod_art',
                               lazy=True)
    listen = db.relationship('Song',
                             secondary=listened,
                             backref=db.backref('listener', lazy=True))
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('artist.id'),
                          nullable=True)
    #playlist_id = db.Column(db.Integer, db.ForeignKey('playlist.id'))
    playlist_id = db.Column(db.Integer,
                            db.ForeignKey('playlist.id'),
                            nullable=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.name}', '{self.email}', '{self.image_file}')"
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=True)
    date_posted = db.Column(db.DateTime,
                            nullable=True,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
class Review(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=True)
    date_posted = db.Column(db.DateTime,
                            nullable=True,
                            default=datetime.utcnow)
    suggestions = db.Column(db.Text, nullable=True)
    event_id = db.Column(db.Integer,
                         db.ForeignKey('event.id'),
                         primary_key=True)

    #__table_args__ = (
    #PrimaryKeyConstraint('field2', 'field1'),
    #{},
    #)
    def __repr__(self):
        return f"Label('{self.title})"
class Event(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=True)
    time = db.Column(db.Integer, nullable=True, default=datetime.utcnow)
    event = db.relationship('EventStatus', backref='events', uselist=False)
    review = db.relationship('Review', backref='review', lazy="dynamic")
    art_perform = db.relationship('Artist',
                                  secondary=performance,
                                  backref='perform',
                                  lazy="dynamic")
    place = db.relationship('Place',
                            secondary=held_in,
                            backref='places',
                            lazy="dynamic")

    def __repr__(self):
        return f"Event('{self.name})"