Esempio n. 1
0
class Subscription(sql.Model):
    __tablename__ = 'subscribe'
    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    show_id = sql.Column(sql.Integer,
                         sql.ForeignKey('shows.id'),
                         primary_key=True)
    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")

    show = sql.relationship('Show')

    watched = sql.column_property(
        sql.select([
            sql.case([(sql.func.count(Watched.episode_id) == 0, True)],
                     else_=False)
        ]).where(
            sql.and_(Watched.episode.has(Episode.air_date < today()),
                     Watched.show_id == show_id, Watched.user_id == user_id,
                     Watched.watched.is_(False))))
Esempio n. 2
0
class SubscribedChannel(sql.Model):
    __tablename__ = "subscribed_channels"

    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    channel_id = sql.Column(sql.String,
                            sql.ForeignKey('channels.id'),
                            primary_key=True)

    channel = sql.relationship('Channel')
    videos = sql.relationship(
        'SubscribedVideo',
        primaryjoin=
        "and_(SubscribedChannel.user_id==SubscribedVideo.user_id, SubscribedChannel.channel_id==SubscribedVideo.channel_id)",
        foreign_keys="[SubscribedVideo.user_id, SubscribedVideo.channel_id]")

    watched = sql.column_property(
        sql.select([sql.func.count(SubscribedVideo.channel_id)]).where(
            sql.and_(user_id == SubscribedVideo.user_id,
                     channel_id == SubscribedVideo.channel_id,
                     SubscribedVideo.watched.is_(True))))

    unwatched = sql.column_property(
        sql.select([sql.func.count(SubscribedVideo.channel_id)]).where(
            sql.and_(user_id == SubscribedVideo.user_id,
                     channel_id == SubscribedVideo.channel_id,
                     SubscribedVideo.watched.is_(False))))

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")
Esempio n. 3
0
class UserBook(sql.Model):
    __tablename__ = "user_books"

    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    book_id = sql.Column(sql.String,
                         sql.ForeignKey('books.id'),
                         primary_key=True)
    read = sql.Column(sql.Boolean, default=False)

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")

    book = sql.relationship('Book')
Esempio n. 4
0
class AddedMovie(sql.Model):
    __tablename__ = "added_movie"

    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    movie_id = sql.Column(sql.String,
                          sql.ForeignKey('movies.id'),
                          primary_key=True)
    watched = sql.Column(sql.Boolean, default=False)

    movie = sql.relationship('Movie')

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")
Esempio n. 5
0
class SubscribedVideo(sql.Model):
    __tablename__ = 'subscribed_videos'

    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    channel_id = sql.Column(sql.String,
                            sql.ForeignKey('channels.id'),
                            primary_key=True)
    video_id = sql.Column(sql.String,
                          sql.ForeignKey('videos.id'),
                          primary_key=True)
    watched = sql.Column(sql.Boolean, default=False)

    video = sql.relationship('Video')

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")
Esempio n. 6
0
class Watched(sql.Model):
    __tablename__ = 'watched'

    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    show_id = sql.Column(sql.Integer,
                         sql.ForeignKey('shows.id'),
                         primary_key=True)
    season_id = sql.Column(sql.Integer, sql.ForeignKey('seasons.id'))
    episode_id = sql.Column(sql.Integer,
                            sql.ForeignKey('episodes.id'),
                            primary_key=True)
    watched = sql.Column(sql.Boolean, default=False)
    hidden = sql.Column(sql.Boolean, default=False)
    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")

    show = sql.relationship('Show')
    episode = sql.relationship('Episode')
Esempio n. 7
0
class AddedMovieGroup(sql.Model):
    __tablename__ = "added_movie_groups"

    user_id = sql.Column(sql.Integer,
                         sql.ForeignKey('users.id'),
                         primary_key=True)
    movie_group_id = sql.Column(sql.Integer,
                                sql.ForeignKey('movie_groups.id'),
                                primary_key=True)

    movie_group = sql.relationship('MovieGroup')

    movies = sql.relationship(
        AddedMovie,
        primaryjoin=sql.and_(
            movie_group_id == movie_group_movies.c.movie_group_id,
            user_id == AddedMovie.user_id),
        secondary=movie_group_movies,
        secondaryjoin=sql.and_(
            user_id == AddedMovie.user_id,
            movie_group_id == movie_group_movies.c.movie_group_id,
            movie_group_movies.c.movie_id == AddedMovie.movie_id,
            AddedMovie.movie_id == Movie.id),
        order_by=[movie_group_movies.c.sequence, Movie.release])
Esempio n. 8
0
class Video(sql.Model):
    __tablename__ = 'videos'

    id = sql.Column(sql.String, primary_key=True)
    channel_id = sql.Column(sql.String, sql.ForeignKey('channels.id'))
    title = sql.Column(sql.String)
    description = sql.Column(sql.String)
    image = sql.Column(sql.String)
    publish_date = sql.Column(sql.DateTime)
    duration = sql.Column(sql.Integer)

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")
Esempio n. 9
0
class Season(sql.Model):
    __tablename__ = 'seasons'

    id = sql.Column(sql.Integer, primary_key=True)
    show_id = sql.Column(sql.Integer, sql.ForeignKey('shows.id'))
    number = sql.Column(sql.Integer)
    name = sql.Column(sql.String)
    episodeOrder = sql.Column(sql.Integer)
    premiereDate = sql.Column(sql.Date)
    endDate = sql.Column(sql.Date)
    image = sql.Column(sql.String)
    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")
Esempio n. 10
0
class Episode(sql.Model):
    __tablename__ = 'episodes'

    id = sql.Column(sql.Integer, primary_key=True)
    air_date = sql.Column(sql.DateTime)
    name = sql.Column(sql.String)
    number = sql.Column(sql.Integer)
    season = sql.Column(sql.Integer)
    summary = sql.Column(sql.String)
    run_time = sql.Column(sql.Integer)
    image = sql.Column(sql.String)
    show_id = sql.Column(sql.Integer, sql.ForeignKey('shows.id'))
    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")
Esempio n. 11
0
from api.extensions import sql

movie_group_movies = sql.Table(
    'movie_groups_movies',
    sql.Column('movie_group_id', sql.Integer,
               sql.ForeignKey('movie_groups.id')),
    sql.Column('movie_id', sql.String, sql.ForeignKey('movies.id')),
    sql.Column('sequence', sql.Integer))


class Movie(sql.Model):
    __tablename__ = 'movies'

    id = sql.Column(sql.String, primary_key=True)
    title = sql.Column(sql.String)
    release = sql.Column(sql.Date)
    rating = sql.Column(sql.String)
    runtime = sql.Column(sql.Integer)
    summary = sql.Column(sql.String)
    image = sql.Column(sql.String)

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")


class AddedMovie(sql.Model):
    __tablename__ = "added_movie"
Esempio n. 12
0
from api.extensions import sql

universe_shows = sql.Table(
    'universe_shows',
    sql.Column('universe_id', sql.Integer, sql.ForeignKey('universe.id')),
    sql.Column('show_id', sql.Integer, sql.ForeignKey('shows.id')))


class Universe(sql.Model):
    __tablename__ = 'universe'

    id = sql.Column(sql.Integer, primary_key=True)
    name = sql.Column(sql.String)
    summary = sql.Column(sql.String)

    ModifiedDate = sql.Column(sql.DateTime,
                              default=sql.func.now(),
                              onupdate=sql.func.now())
    ModifiedBy = sql.Column(sql.String, default="sqlAlchemy")
    CreatedDate = sql.Column(sql.DateTime, default=sql.func.now())
    CreatedBy = sql.Column(sql.String, default="sqlAlchemy")

    shows = sql.relationship("Show", secondary=universe_shows)