From 8c8692b8d25fab06cef1683461be965f5a288668 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 2 Oct 2020 17:12:02 +0200 Subject: [PATCH] Better roman import --- media/forms.py | 2 ++ media/management/commands/import_future_media.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/media/forms.py b/media/forms.py index e5b19a0..40d8efe 100644 --- a/media/forms.py +++ b/media/forms.py @@ -135,6 +135,8 @@ class MediaAdminForm(ModelForm): self.cleaned_data['number_of_pages'] = 0 if 'publishedDate' in info: + if "-" not in info["publishedDate"]: + info["publishedDate"] += "-01-01" self.cleaned_data['publish_date'] = info['publishedDate'] if 'authors' not in self.cleaned_data \ diff --git a/media/management/commands/import_future_media.py b/media/management/commands/import_future_media.py index d028b4e..35f1a7e 100644 --- a/media/management/commands/import_future_media.py +++ b/media/management/commands/import_future_media.py @@ -24,9 +24,9 @@ class Command(BaseCommand): continue if cl.objects.filter(isbn=isbn).exists(): - self.stderr.write(self.style.WARNING( - "ISBN {isbn} already exists".format(isbn=isbn) - )) + self.stderr.write(self.style.WARNING(f"ISBN {isbn} for type {type_str} already exists, remove it")) + future_medium.delete() + continue form = MediaAdminForm(instance=cl(), data={"isbn": isbn, "_isbn": True, }) @@ -35,6 +35,8 @@ class Command(BaseCommand): try: form.full_clean() + if hasattr(form.instance, "subtitle") and not form.instance.subtitle: + form.instance.subtitle = "" form.save() future_medium.delete() self.stdout.write(self.style.SUCCESS(