Esempio n. 1
0
class BookPublisherAssocciation(db.Model):
    __tablename__ = 'books_publishers'
    __table_args__ = (db.ForeignKeyConstraint(['book_id'], ['books.id'],
                                              onupdate="CASCADE",
                                              ondelete="CASCADE"), )

    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'))
    publisher_id = db.Column(db.Integer, db.ForeignKey('publishers.id'))
Esempio n. 2
0
class Season(db.Model):
    __tablename__ = 'seasons'
    __table_args__ = (db.ForeignKeyConstraint(['book_id'], ['books.id'],
                                              onupdate="CASCADE",
                                              ondelete="CASCADE"), )

    id = db.Column(db.Integer(), primary_key=True)
    number = db.Column(db.Unicode())
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'))
Esempio n. 3
0
class BookReleaseFormatAssocciation(db.Model):
    __tablename__ = 'books_release_formates'
    __table_args__ = (db.ForeignKeyConstraint(['book_id'], ['books.id'],
                                              onupdate="CASCADE",
                                              ondelete="CASCADE"), )

    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'))

    release_format = db.Column(Enum(ReleaseFormat),
                               nullable=False,
                               default=ReleaseFormat.web)
Esempio n. 4
0
class Episode(db.Model):
    __tablename__ = 'episodes'
    __table_args__ = (db.ForeignKeyConstraint(['season_id'], ['seasons.id'],
                                              onupdate="CASCADE",
                                              ondelete="CASCADE"), )

    id = db.Column(db.Integer(), primary_key=True)
    number = db.Column(db.Unicode())
    name = db.Column(db.Unicode())
    pages = db.Column(db.JSON)
    translator_id = db.Column(db.Integer, db.ForeignKey('translators.id'))
    season_id = db.Column(db.Integer, db.ForeignKey('seasons.id'))

    @staticmethod
    async def upload(episode, book_id):
        season_number = episode.get('seasonNumber')
        episode_number = episode.get('episodeNumber')
        episode_name = episode.get('episodeName')
        episode_file = episode.get('file')
        translator_id = episode.get('translator_id')

        filename = episode_file.filename
        content = await episode_file.read()

        season = await Season.query.where(
            and_(Season.book_id == book_id,
                 Season.number == season_number)).gino.first()

        if not season:
            season = await Season.create(number=season_number, book_id=book_id)

        upload_data = unzip_episode(content)
        await Episode.create(
            name=episode_name,
            number=episode_number,
            season_id=season.id,
            translator_id=translator_id,
            pages=upload_data,
        )

    def clear(self):
        remove_episode(self.pages.get('uuid'))