add other_title to Edition
This commit is contained in:
parent
e6292a350a
commit
11b2c740a2
5 changed files with 28 additions and 18 deletions
|
@ -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 typing import TYPE_CHECKING
|
||||||
|
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
@ -141,6 +142,7 @@ class Edition(Item):
|
||||||
"pub_month",
|
"pub_month",
|
||||||
"language",
|
"language",
|
||||||
"orig_title",
|
"orig_title",
|
||||||
|
"other_title",
|
||||||
"translator",
|
"translator",
|
||||||
"series",
|
"series",
|
||||||
"imprint",
|
"imprint",
|
||||||
|
@ -166,6 +168,13 @@ class Edition(Item):
|
||||||
orig_title = jsondata.CharField(
|
orig_title = jsondata.CharField(
|
||||||
_("original title"), null=True, blank=True, max_length=500
|
_("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(
|
author = jsondata.JSONField(
|
||||||
verbose_name=_("author"),
|
verbose_name=_("author"),
|
||||||
null=False,
|
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_title if t["text"]]
|
||||||
titles += [t["text"] for t in self.localized_subtitle 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 += [self.orig_title] if self.orig_title else []
|
||||||
|
titles += [t for t in self.other_title if t] # type: ignore
|
||||||
return list(set(titles))
|
return list(set(titles))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -296,6 +306,13 @@ class Edition(Item):
|
||||||
.order_by("-metadata__pub_year")
|
.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
|
@property
|
||||||
def title_deco(self):
|
def title_deco(self):
|
||||||
a = [str(i) for i in [self.pub_house, self.pub_year] if i]
|
a = [str(i) for i in [self.pub_house, self.pub_year] if i]
|
||||||
|
|
|
@ -308,9 +308,13 @@ class ArrayField(JSONFieldMixin, DJANGO_ArrayField):
|
||||||
# kwargs["help_text"] = _("comma separated list of values")
|
# kwargs["help_text"] = _("comma separated list of values")
|
||||||
# super().__init__(*args, **kwargs)
|
# 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:
|
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 []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,6 @@ def _EditForm(item_model):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.migrate_initial()
|
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):
|
def migrate_initial(self):
|
||||||
if self.initial and self.instance and self.instance.pk:
|
if self.initial and self.instance and self.instance.pk:
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -15,15 +15,7 @@
|
||||||
{% if item.pub_month %}- {{ item.pub_month }}{% endif %}
|
{% if item.pub_month %}- {{ item.pub_month }}{% endif %}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if item.release_date %}<span>{{ item.release_date }}</span>{% endif %}
|
{% include '_people.html' with people=item.additional_title role='other title' max=2 %}
|
||||||
{% 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 %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock brief %}
|
{% endblock brief %}
|
||||||
{% block full %}
|
{% block full %}
|
||||||
|
|
|
@ -21,13 +21,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div>{% include '_people.html' with people=item.author role='author' max=5 %}</div>
|
<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>{% include '_people.html' with people=item.translator role='translator' max=5 %}</div>
|
||||||
<div>
|
|
||||||
<div>
|
<div>
|
||||||
{% if item.format %}
|
{% if item.format %}
|
||||||
{% trans 'book format' %}: {{ item.get_format_display }}
|
{% trans 'book format' %}: {{ item.get_format_display }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div>{% include '_people.html' with people=item.additional_title role='other title' max=99 %}</div>
|
||||||
<div>
|
<div>
|
||||||
{% if item.pub_house %}
|
{% if item.pub_house %}
|
||||||
{% trans 'publishing house' %}: {{ item.pub_house }}
|
{% trans 'publishing house' %}: {{ item.pub_house }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue