From: Radek Czajka Date: Tue, 26 Sep 2023 11:51:49 +0000 (+0200) Subject: fix for isbn import X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/2bde30d633af49f2d3d40305e30df68c04dc0786?ds=sidebyside fix for isbn import --- diff --git a/src/isbn/migrations/0005_alter_isbn_form.py b/src/isbn/migrations/0005_alter_isbn_form.py new file mode 100644 index 00000000..e106762d --- /dev/null +++ b/src/isbn/migrations/0005_alter_isbn_form.py @@ -0,0 +1,32 @@ +# Generated by Django 4.1.9 on 2023-09-26 13:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("isbn", "0004_alter_isbn_form"), + ] + + operations = [ + migrations.AlterField( + model_name="isbn", + name="form", + field=models.CharField( + blank=True, + choices=[ + ("html", "html"), + ("txt", "txt"), + ("pdf", "pdf"), + ("epub", "epub"), + ("mobi", "mobi"), + ("mp3", "mp3"), + ("paperback", "paperback"), + ], + default="", + max_length=32, + ), + preserve_default=False, + ), + ] diff --git a/src/isbn/models.py b/src/isbn/models.py index 9db0513c..14e973d8 100644 --- a/src/isbn/models.py +++ b/src/isbn/models.py @@ -98,7 +98,7 @@ class Isbn(models.Model): max_length=32, choices=[ (form, form) for form, config in FORMS - ], null=True, blank=True + ], blank=True ) bn_data = models.TextField(blank=True) wl_data = models.TextField(blank=True) @@ -139,12 +139,15 @@ class Isbn(models.Model): isbn, created = pool.isbn_set.get_or_create( suffix=suffix, ) + add_note = False if isbn.book is None: isbn.book = catalogue_book - else: - assert isbn.book is catalogue_book - if isbn.form is None: + elif isbn.book is not catalogue_book: + add_note = True + if not isbn.form: isbn.form = form - else: - assert isbn.form == form - isbn.save(update_fields=['book', 'form']) + elif isbn.form != form: + add_note = True + if add_note: + isbn.notes += '\n\n' + catalogue_book.slug + ' ' + form + isbn.save(update_fields=['book', 'form', 'notes'])