mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2025-06-22 06:38:22 +02:00
Split comic strips and mangas
This commit is contained in:
0
media/management/commands/__init__.py
Normal file
0
media/management/commands/__init__.py
Normal file
50
media/management/commands/split_media_types.py
Normal file
50
media/management/commands/split_media_types.py
Normal file
@ -0,0 +1,50 @@
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from media.forms import MediaAdminForm
|
||||
from media.models import Media, Manga
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--view-only', action="store_true",
|
||||
help="Display only modifications. "
|
||||
+ "Only useful for debug.")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
converted = 0
|
||||
|
||||
for media in Media.objects.all():
|
||||
self.stdout.write(str(media))
|
||||
form = MediaAdminForm(instance=media, data={"isbn": media.isbn, "_isbn": True, })
|
||||
form.full_clean()
|
||||
|
||||
if not "format" in form.cleaned_data:
|
||||
self.stdout.write("Format not specified. Assume it is a comic strip.")
|
||||
continue
|
||||
|
||||
format = form.cleaned_data["format"]
|
||||
self.stdout.write("Format: {}".format(format))
|
||||
|
||||
if not options["view_only"]:
|
||||
if format == "manga":
|
||||
self.stdout.write(self.style.WARNING("This media is a manga. Transfer it into a new object..."))
|
||||
manga = Manga.objects.create(
|
||||
isbn=media.isbn,
|
||||
title=media.title,
|
||||
subtitle=media.subtitle,
|
||||
external_url=media.external_url,
|
||||
side_identifier=media.side_identifier,
|
||||
number_of_pages=media.number_of_pages,
|
||||
publish_date=media.publish_date,
|
||||
)
|
||||
|
||||
manga.authors.set(media.authors.all())
|
||||
manga.save()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS("Manga successfully saved. Deleting old medium..."))
|
||||
|
||||
media.delete()
|
||||
self.stdout.write(self.style.SUCCESS("Medium deleted"))
|
||||
|
||||
converted += 1
|
||||
self.stdout.write(self.style.SUCCESS("Successfully saved {:d} mangas".format(converted)))
|
Reference in New Issue
Block a user