diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 53cf94ff4..6c29ac058 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -27,7 +27,7 @@ class Author(BookDataModel): # idk probably other keys would be useful here? born = fields.DateTimeField(blank=True, null=True) died = fields.DateTimeField(blank=True, null=True) - name = fields.CharField(max_length=255, deduplication_field=True) + name = fields.CharField(max_length=255) aliases = fields.ArrayField( models.CharField(max_length=255), blank=True, default=list ) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 361079906..7d14f88f9 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -296,7 +296,7 @@ class ManyToManyField(ActivitypubFieldMixin, models.ManyToManyField): super().__init__(*args, **kwargs) def set_field_from_activity(self, instance, data, overwrite=True): - """helper function for assinging a value to the field""" + """helper function for assigning a value to the field""" if not overwrite and getattr(instance, self.name).exists(): return False @@ -398,7 +398,11 @@ class ImageField(ActivitypubFieldMixin, models.ImageField): if formatted is None or formatted is MISSING: return False - if not overwrite and hasattr(instance, self.name): + if ( + not overwrite + and hasattr(instance, self.name) + and getattr(instance, self.name) + ): return False getattr(instance, self.name).save(*formatted, save=save) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 8224a2787..32465d6ed 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -317,15 +317,21 @@ def save_and_cleanup(image, instance=None): """Save and close the file""" if not isinstance(instance, (models.Book, models.User, models.SiteSettings)): return False - uuid = uuid4() - file_name = f"{instance.id}-{uuid}.jpg" image_buffer = BytesIO() try: try: - old_path = instance.preview_image.name + file_name = instance.preview_image.name except ValueError: - old_path = None + file_name = None + + if not file_name or file_name == "": + uuid = uuid4() + file_name = f"{instance.id}-{uuid}.jpg" + + # Clean up old file before saving + if file_name and default_storage.exists(file_name): + default_storage.delete(file_name) # Save image.save(image_buffer, format="jpeg", quality=75) @@ -345,10 +351,6 @@ def save_and_cleanup(image, instance=None): else: instance.save(update_fields=["preview_image"]) - # Clean up old file after saving - if old_path and default_storage.exists(old_path): - default_storage.delete(old_path) - finally: image_buffer.close() return True diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index 6a67b50b3..b066c6ca4 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -2,6 +2,7 @@ {% load i18n %} {% load markdown %} {% load humanize %} +{% load utilities %} {% block title %}{{ author.name }}{% endblock %} @@ -25,7 +26,7 @@
- {% if author.aliases or author.born or author.died or author.wikipedia_link or author.openlibrary_key or author.inventaire_id %} + {% if author.aliases or author.born or author.died or author.wikipedia_link or author.openlibrary_key or author.inventaire_id or author.isni %}
@@ -63,6 +64,14 @@

{% endif %} + {% if author.isni %} +

+ + {% trans "View ISNI record" %} + +

+ {% endif %} + {% if author.openlibrary_key %}

diff --git a/bookwyrm/templates/book/edit/edit_book.html b/bookwyrm/templates/book/edit/edit_book.html index fc11208fd..3d41058e3 100644 --- a/bookwyrm/templates/book/edit/edit_book.html +++ b/bookwyrm/templates/book/edit/edit_book.html @@ -1,6 +1,7 @@ {% extends 'layout.html' %} {% load i18n %} {% load humanize %} +{% load utilities %} {% block title %}{% if book %}{% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %}{% else %}{% trans "Add Book" %}{% endif %}{% endblock %} @@ -52,19 +53,29 @@ {% for author in author_matches %}

- {% blocktrans with name=author.name %}Is "{{ name }}" an existing author?{% endblocktrans %} + {% blocktrans with name=author.name %}Is "{{ name }}" one of these authors?{% endblocktrans %} {% with forloop.counter0 as counter %} {% for match in author.matches %} -

- {% blocktrans with book_title=match.book_set.first.title %}Author of {{ book_title }}{% endblocktrans %} +

+ {% with book_title=match.book_set.first.title alt_title=match.bio %} + {% if book_title %} + {% trans "Author of " %}{{ book_title }} + {% else %} + {% if alt_title %}{% trans "Author of " %}{{ alt_title }}{% else %} {% trans "Find more information at isni.org" %}{% endif %} + {% endif %} + {% endwith %}

+

+ {{ author.existing_isnis|get_isni_bio:match }} +

+ {{ author.existing_isnis|get_isni:match }} {% endfor %} -