Skip to content

Commit

Permalink
add other_title to Edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Jan 1, 2025
1 parent e6292a3 commit 11b2c74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
17 changes: 17 additions & 0 deletions catalog/book/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

from functools import cached_property
from typing import TYPE_CHECKING

from django.core.validators import MaxValueValidator, MinValueValidator
Expand Down Expand Up @@ -141,6 +142,7 @@ class BookFormat(models.TextChoices):
"pub_month",
"language",
"orig_title",
"other_title",
"translator",
"series",
"imprint",
Expand All @@ -166,6 +168,13 @@ class BookFormat(models.TextChoices):
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,
Expand Down Expand Up @@ -220,6 +229,7 @@ def to_indexable_titles(self) -> list[str]:
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
Expand Down Expand Up @@ -296,6 +306,13 @@ def sibling_items(self):
.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]
Expand Down
8 changes: 6 additions & 2 deletions catalog/common/jsondata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []


Expand Down
2 changes: 0 additions & 2 deletions catalog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.migrate_initial()

# {'id': 547, 'primary_lookup_id_type': 'imdb', 'primary_lookup_id_value': 'tt0056923', 'cover': <ImageFieldFile: item/tmdb_movie/2024/01/12/10973d2b-1d20-4e37-8c3c-ecc89e671a80.jpg>, '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 (
Expand Down
10 changes: 1 addition & 9 deletions catalog/templates/_item_card_metadata_edition.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@
{% if item.pub_month %}- {{ item.pub_month }}{% endif %}
</span>
{% endif %}
{% if item.release_date %}<span>{{ item.release_date }}</span>{% 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 %}
<span>{{ item.show.type.label }}: <a href="{{ item.show.url }}">{{ item.show.display_title }}</a></span>
{% endif %}
{% include '_people.html' with people=item.additional_title role='other title' max=2 %}
</div>
{% endblock brief %}
{% block full %}
Expand Down
9 changes: 4 additions & 5 deletions catalog/templates/edition.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
<div>{% include '_people.html' with people=item.author role='author' max=5 %}</div>
<div>{% include '_people.html' with people=item.translator role='translator' max=5 %}</div>
<div>
<div>
{% if item.format %}
{% trans 'book format' %}: {{ item.get_format_display }}
{% endif %}
</div>
{% if item.format %}
{% trans 'book format' %}: {{ item.get_format_display }}
{% endif %}
</div>
<div>{% include '_people.html' with people=item.additional_title role='other title' max=99 %}</div>
<div>
{% if item.pub_house %}
{% trans 'publishing house' %}: {{ item.pub_house }}
Expand Down

0 comments on commit 11b2c74

Please sign in to comment.