예제 #1
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer(), primary_key=True)

    nickname = db.Column(db.Unicode(), unique=True)
    email = db.Column(db.Unicode(), unique=True)
    password_hash = db.Column(db.Unicode())
예제 #2
0
class Book(db.Model):
    __tablename__ = 'books'

    id = db.Column(db.Integer(), primary_key=True)
    rus_title = db.Column(db.Unicode())
    eng_title = db.Column(db.Unicode())
    description = db.Column(db.Unicode())
    release_year = db.Column(db.Integer())
    cover_image = db.Column(db.Unicode())
    background_image = db.Column(db.Unicode())

    # enum props
    age_limit = db.Column(Enum(AgeLimit),
                          nullable=False,
                          default=AgeLimit.unlimited)
    translation_status = db.Column(Enum(TranslationStatus),
                                   nullable=False,
                                   default=TranslationStatus.processing)

    def __init__(self, **kw):
        super().__init__(**kw)
        self._genres = set()
        self._tags = set()

    @property
    def genres(self):
        return self._genres

    def add_genre(self, genre):
        self._genres.add(genre)
        genre._books.add(self)

    @property
    def tags(self):
        return self._tags

    def add_tag(self, tag):
        self._tags.add(tag)
        tag._books.add(self)

    @property
    def sections(self):
        return self._sections

    def add_section(self, section):
        self._sections.add(section)
        section._books.add(self)
예제 #3
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'))
예제 #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'))
예제 #5
0
class Tag(db.Model):
    __tablename__ = 'tags'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.Unicode(), unique=True)

    def __init__(self, **kw):
        super().__init__(**kw)
        self._books = set()

    @property
    def books(self):
        return self._books