fix for isbn import
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 26 Sep 2023 11:51:49 +0000 (13:51 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 26 Sep 2023 11:51:49 +0000 (13:51 +0200)
src/isbn/migrations/0005_alter_isbn_form.py [new file with mode: 0644]
src/isbn/models.py

diff --git a/src/isbn/migrations/0005_alter_isbn_form.py b/src/isbn/migrations/0005_alter_isbn_form.py
new file mode 100644 (file)
index 0000000..e106762
--- /dev/null
@@ -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,
+        ),
+    ]
index 9db0513..14e973d 100644 (file)
@@ -98,7 +98,7 @@ class Isbn(models.Model):
         max_length=32, choices=[
             (form, form)
             for form, config in FORMS
         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)
     )
     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,
                     )
                     isbn, created = pool.isbn_set.get_or_create(
                         suffix=suffix,
                     )
+                    add_note = False
                     if isbn.book is None:
                         isbn.book = catalogue_book
                     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
                         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'])