From 11b2c740a23934e5e6dba6041f0f5742e6bb7205 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 1 Jan 2025 10:49:58 -0500 Subject: [PATCH] add other_title to Edition --- catalog/book/models.py | 17 +++++++++++++++++ catalog/common/jsondata.py | 8 ++++++-- catalog/forms.py | 2 -- .../templates/_item_card_metadata_edition.html | 10 +--------- catalog/templates/edition.html | 9 ++++----- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/catalog/book/models.py b/catalog/book/models.py index d3864d72..0e8c1646 100644 --- a/catalog/book/models.py +++ b/catalog/book/models.py @@ -17,6 +17,7 @@ work data seems asymmetric (a book links to a work, but may not listed in that w """ +from functools import cached_property from typing import TYPE_CHECKING from django.core.validators import MaxValueValidator, MinValueValidator @@ -141,6 +142,7 @@ class Edition(Item): "pub_month", "language", "orig_title", + "other_title", "translator", "series", "imprint", @@ -166,6 +168,13 @@ class Edition(Item): orig_title = jsondata.CharField( _("original title"), null=True, blank=True, max_length=500 ) + other_title = jsondata.ArrayField( + base_field=models.CharField(blank=True, default="", max_length=500), + verbose_name=_("other title"), + null=True, + blank=True, + default=list, + ) author = jsondata.JSONField( verbose_name=_("author"), null=False, @@ -220,6 +229,7 @@ class Edition(Item): titles = [t["text"] for t in self.localized_title if t["text"]] titles += [t["text"] for t in self.localized_subtitle if t["text"]] titles += [self.orig_title] if self.orig_title else [] + titles += [t for t in self.other_title if t] # type: ignore return list(set(titles)) @property @@ -296,6 +306,13 @@ class Edition(Item): .order_by("-metadata__pub_year") ) + @cached_property + def additional_title(self) -> list[str]: + title = self.display_title + return [ + t["text"] for t in self.localized_title if t["text"] != title + ] + self.other_title # type: ignore + @property def title_deco(self): a = [str(i) for i in [self.pub_house, self.pub_year] if i] diff --git a/catalog/common/jsondata.py b/catalog/common/jsondata.py index 7a396411..8287eeea 100644 --- a/catalog/common/jsondata.py +++ b/catalog/common/jsondata.py @@ -308,9 +308,13 @@ class ArrayField(JSONFieldMixin, DJANGO_ArrayField): # kwargs["help_text"] = _("comma separated list of values") # super().__init__(*args, **kwargs) - def from_json(self, value): # backward compatible with dirty legacy data + def from_json(self: "fields.Field", value): # type:ignore if value: - return value if isinstance(value, list) else [value] + if isinstance(value, list): + return value + else: # backward compatible with dirty legacy data + logger.error(f"ArrayField has irregular value: {self.name}: {value}") + return [value] return [] diff --git a/catalog/forms.py b/catalog/forms.py index 2cb49876..715bbf3c 100644 --- a/catalog/forms.py +++ b/catalog/forms.py @@ -44,8 +44,6 @@ def _EditForm(item_model): super().__init__(*args, **kwargs) self.migrate_initial() - # {'id': 547, 'primary_lookup_id_type': 'imdb', 'primary_lookup_id_value': 'tt0056923', 'cover': , 'orig_title': 'Charade', 'other_title': [], 'director': ['Stanley Donen'], 'playwright': ['Peter Stone'], 'actor': ['Cary Grant', 'Audrey Hepburn', 'Walter Matthau', 'James Coburn', 'George Kennedy', 'Dominique Minot', 'Ned Glass', 'Jacques Marin', 'Paul Bonifas', 'Thomas Chelimsky', 'Marc Arian', 'Claudine Berg', 'Marcel Bernier', 'Albert Daumergue', 'Raoul Delfosse', 'Stanley Donen', 'Jean Gold', 'Chantal Goya', 'Clément Harari', 'Monte Landis', 'Bernard Musson', 'Antonio Passalia', 'Jacques Préboist', 'Peter Stone', 'Michel Thomass', 'Roger Trapp', 'Louis Viret'], 'genre': ['喜剧', '悬疑', '爱情'], 'showtime': [{'time': '1963-12-05', 'region': ''}], 'site': '', 'area': [], 'language': ['English', 'Français', 'Deutsch', 'Italiano'], 'year': 1963, 'duration': '', 'localized_title': [], 'localized_description': []} - def migrate_initial(self): if self.initial and self.instance and self.instance.pk: if ( diff --git a/catalog/templates/_item_card_metadata_edition.html b/catalog/templates/_item_card_metadata_edition.html index 30123ebb..1b3d2841 100644 --- a/catalog/templates/_item_card_metadata_edition.html +++ b/catalog/templates/_item_card_metadata_edition.html @@ -15,15 +15,7 @@ {% if item.pub_month %}- {{ item.pub_month }}{% endif %} {% endif %} - {% if item.release_date %}{{ item.release_date }}{% endif %} - {% include '_people.html' with people=item.genre role='' max=2 %} - {% include '_people.html' with people=item.troupe role='' max=2 %} - {% include '_people.html' with people=item.location role='' max=2 %} - {% comment %} {% include '_people.html' with people=item.language role='' max=5 %} {% endcomment %} - {% include '_people.html' with people=item.platform role='' max=5 %} - {% if item.show %} - {{ item.show.type.label }}: {{ item.show.display_title }} - {% endif %} + {% include '_people.html' with people=item.additional_title role='other title' max=2 %} {% endblock brief %} {% block full %} diff --git a/catalog/templates/edition.html b/catalog/templates/edition.html index 32d41358..d988044d 100644 --- a/catalog/templates/edition.html +++ b/catalog/templates/edition.html @@ -22,12 +22,11 @@
{% include '_people.html' with people=item.author role='author' max=5 %}
{% include '_people.html' with people=item.translator role='translator' max=5 %}
-
- {% if item.format %} - {% trans 'book format' %}: {{ item.get_format_display }} - {% endif %} -
+ {% if item.format %} + {% trans 'book format' %}: {{ item.get_format_display }} + {% endif %}
+
{% include '_people.html' with people=item.additional_title role='other title' max=99 %}
{% if item.pub_house %} {% trans 'publishing house' %}: {{ item.pub_house }}