diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 53cf94ff..6c29ac05 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 36107990..7d14f88f 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 8224a278..32465d6e 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/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index a5f7d7e9..d656ed18 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -45,6 +45,13 @@ let BookWyrm = new class { 'change', this.disableIfTooLarge.bind(this) )); + + document.querySelectorAll('[data-duplicate]') + .forEach(node => node.addEventListener( + 'click', + this.duplicateInput.bind(this) + + )) } /** @@ -403,4 +410,24 @@ let BookWyrm = new class { ); } } + + duplicateInput (event ) { + const trigger = event.currentTarget; + const input_id = trigger.dataset['duplicate'] + const orig = document.getElementById(input_id); + const parent = orig.parentNode; + const new_count = parent.querySelectorAll("input").length + 1 + + let input = orig.cloneNode(); + + input.id += ("-" + (new_count)) + input.value = "" + + let label = parent.querySelector("label").cloneNode(); + + label.setAttribute("for", input.id) + + parent.appendChild(label) + parent.appendChild(input) + } }(); diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js index 2a50bfcb..418b7dee 100644 --- a/bookwyrm/static/js/status_cache.js +++ b/bookwyrm/static/js/status_cache.js @@ -187,6 +187,7 @@ let StatusCache = new class { .forEach(item => BookWyrm.addRemoveClass(item, "is-hidden", false)); // Remove existing disabled states + button.querySelectorAll("[data-shelf-dropdown-identifier] button") .forEach(item => item.disabled = false); diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index 6a67b50b..b066c6ca 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/book.html b/bookwyrm/templates/book/book.html index 36241ee2..713e7abe 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -153,12 +153,21 @@ {# user's relationship to the book #}

+ {% if user_shelfbooks.count > 0 %} +

+ {% trans "You have shelved this edition in:" %} +

+
+ {% endif %} {% for shelf in other_edition_shelves %}

{% blocktrans with book_path=shelf.book.local_path shelf_path=shelf.shelf.local_path shelf_name=shelf.shelf.name %}A different edition of this book is on your {{ shelf_name }} shelf.{% endblocktrans %} diff --git a/bookwyrm/templates/book/edit/edit_book.html b/bookwyrm/templates/book/edit/edit_book.html index fc11208f..3d41058e 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 %} -
{% endif %}
- - - {% trans "Separate multiple values with commas." %} + + {% for author in add_author %} + + + {% empty %} + + + {% endfor %}
+
diff --git a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html index 3c127160..a35ed9e0 100644 --- a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html @@ -9,10 +9,11 @@ Finish "{{ book_title }}" {% endblock %} {% block modal-form-open %} -
+ {% csrf_token %} + {% endblock %} {% block reading-dates %} diff --git a/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html index cd0b64f3..423f77eb 100644 --- a/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/start_reading_modal.html @@ -9,8 +9,9 @@ Start "{{ book_title }}" {% endblock %} {% block modal-form-open %} - + + {% csrf_token %} {% endblock %} diff --git a/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html b/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html index d1f06d8f..2fb976bf 100644 --- a/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/want_to_read_modal.html @@ -9,8 +9,9 @@ Want to Read "{{ book_title }}" {% endblock %} {% block modal-form-open %} - + + {% csrf_token %} {% endblock %} diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html index ca5a39f6..4b32f5a8 100644 --- a/bookwyrm/templates/snippets/shelf_selector.html +++ b/bookwyrm/templates/snippets/shelf_selector.html @@ -1,29 +1,88 @@ {% extends 'components/dropdown.html' %} {% load i18n %} +{% load bookwyrm_tags %} +{% load utilities %} + {% block dropdown-trigger %} {% trans "Move book" %} {% endblock %} {% block dropdown-list %} +{% with book.id|uuid as uuid %} +{% active_shelf book as active_shelf %} +{% latest_read_through book request.user as readthrough %} + {% for shelf in user_shelves %} + +{% if shelf.editable %}
+{% else%} +{% comparison_bool shelf.identifier active_shelf.shelf.identifier as is_current %} +{% with button_class="is-fullwidth is-small shelf-option is-radiusless is-white" %} + +{% endwith %} +{% endif %} {% endfor %} - + +{% if shelf.identifier == 'all' %} +{% for shelved_in in book.shelves.all %} + +{% endfor %} +{% else %} + + +{% endif %} + +{% include 'snippets/reading_modals/want_to_read_modal.html' with book=active_shelf.book controls_text="want_to_read" controls_uid=uuid move_from=current.id refresh=True %} + +{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book controls_text="start_reading" controls_uid=uuid move_from=current.id refresh=True %} + +{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book controls_text="finish_reading" controls_uid=uuid move_from=current.id readthrough=readthrough refresh=True %} + +{% endwith %} {% endblock %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html index 32319f86..8c1881ce 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html @@ -32,7 +32,7 @@ {% elif shelf.editable %} -
+ {% csrf_token %}