From 83ad45644b1fb7ac71f68bc5429cb502d519126d Mon Sep 17 00:00:00 2001 From: axiomizer Date: Thu, 3 Aug 2023 18:01:02 -0400 Subject: [PATCH] Make hyphenated ISBN a property on the book model --- bookwyrm/models/book.py | 6 ++++++ bookwyrm/templates/book/book_identifiers.html | 2 +- bookwyrm/views/books/books.py | 2 -- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 13de59a8c..8cb47e5c8 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -15,6 +15,7 @@ from model_utils.managers import InheritanceManager from imagekit.models import ImageSpecField from bookwyrm import activitypub +from bookwyrm.isbn.isbn import hyphenator_singleton as hyphenator from bookwyrm.preview_images import generate_edition_preview_image_task from bookwyrm.settings import ( DOMAIN, @@ -321,6 +322,11 @@ class Edition(Book): serialize_reverse_fields = [("file_links", "fileLinks", "-created_date")] deserialize_reverse_fields = [("file_links", "fileLinks")] + @property + def hyphenated_isbn13(self): + """generate the hyphenated version of the ISBN-13""" + return hyphenator.hyphenate(self.isbn_13) + def get_rank(self): """calculate how complete the data is on this edition""" rank = 0 diff --git a/bookwyrm/templates/book/book_identifiers.html b/bookwyrm/templates/book/book_identifiers.html index db4582065..d976f72c2 100644 --- a/bookwyrm/templates/book/book_identifiers.html +++ b/bookwyrm/templates/book/book_identifiers.html @@ -6,7 +6,7 @@ {% if book.isbn_13 %}
{% trans "ISBN:" %}
-
{{ hyphenated_isbn13 }}
+
{{ book.hyphenated_isbn13 }}