예제 #1
0
파일: forms.py 프로젝트: 32x32/fufufuu
    def save(self):
        manga = super().save(commit=False)

        cd = self.cleaned_data

        tank_name, tank_chapter = cd.get('tank'), cd.get('tank_chapter')
        if tank_name and tank_chapter:
            manga.tank = get_or_create_tag_by_name_or_alias(TagType.TANK, tank_name, self.request.user)
            manga.tank_chapter = tank_chapter
        else:
            manga.tank = None
            manga.tank_chapter = None

        collection_name, collection_part = cd.get('collection'), cd.get('collection_part')
        if collection_name and collection_part:
            manga.collection = get_or_create_tag_by_name_or_alias(TagType.COLLECTION, collection_name, self.request.user)
            manga.collection_part = collection_part
        else:
            manga.collection = None
            manga.collection_part = None

        if self.html:
            manga.html = self.html

        if cd.get('action') == MangaAction.PUBLISH:
            manga.status = MangaStatus.PUBLISHED
            manga.published_on = timezone.now()
            send_email_alert(
                subject='[Fufufuu] Published: {}'.format(manga.title),
                message=manga.info_text,
            )

        manga.save(self.request.user)
        manga.tags.clear()
        manga.tags.add(*self.get_tag_list())

        if manga.status == MangaStatus.PUBLISHED:
            MangaArchiveGenerator.generate(manga)

        if manga.tank and not manga.tank.cover:
            manga.tank.set_default_cover()
        if manga.collection and not manga.collection.cover:
            manga.collection.set_default_cover()

        return manga
예제 #2
0
파일: forms.py 프로젝트: 32x32/fufufuu
    def save(self):
        report_manga = super().save(commit=False)
        report_manga.manga = self.manga
        report_manga.ip_address = get_ip_address(self.request)

        if self.request.user.is_authenticated():
            report_manga.created_by = self.request.user
            report_manga.weight = self.request.user.report_weight
        else:
            report_manga.weight = self.ANONYMOUS_USER_REPORT_WEIGHT

        report_manga.save()

        total_weight = ReportManga.open.filter(manga=self.manga).aggregate(total_weight=Sum('weight')).get('total_weight', 0)
        if total_weight >= self.PENDING_WEIGHT:
            self.manga.status = MangaStatus.PENDING
            self.manga.save(self.manga.updated_by)

        send_email_alert(
            subject='[Fufufuu] Reported: {}'.format(self.manga.title),
            message=report_manga.email_text,
        )

        return report_manga