add other_title to Edition

This commit is contained in:
Your Name 2025-01-01 10:49:58 -05:00 committed by Henri Dickson
parent e6292a350a
commit 11b2c740a2
5 changed files with 28 additions and 18 deletions

View file

@ -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]

View file

@ -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 []

View file

@ -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': <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 (

View file

@ -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 %}

View file

@ -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 }}