--- /dev/null
+# Generated by Django 4.0.8 on 2024-05-20 12:31
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('catalogue', '0046_alter_book_options_alter_bookmedia_options_and_more'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='book',
+ name='translators',
+ field=models.ManyToManyField(to='catalogue.tag'),
+ ),
+ ]
tagged = managers.ModelTaggedItemManager(Tag)
tags = managers.TagDescriptor(Tag)
tag_relations = GenericRelation(Tag.intermediary_table_model)
+ translators = models.ManyToManyField(Tag)
html_built = django.dispatch.Signal()
published = django.dispatch.Signal()
def genre_unicode(self):
return self.tag_unicode('genre')
- def translators(self):
- translators = self.get_extra_info_json().get('translators') or []
- return [
- '\xa0'.join(reversed(translator.split(', ', 1))) for translator in translators
- ]
-
def translator(self):
translators = self.get_extra_info_json().get('translators')
if not translators:
meta_tags = Tag.tags_from_info(book_info)
- for tag in meta_tags:
+ for tag, relationship in meta_tags:
if not tag.for_books:
tag.for_books = True
tag.save()
- book.tags = set(meta_tags + book_shelves)
+ just_tags = [t for (t, rel) in meta_tags if not rel]
+ book.tags = set(just_tags + book_shelves)
book.save() # update sort_key_author
+ book.translators.set([t for (t, rel) in meta_tags if rel == 'translator'])
+
cover_changed = old_cover != book.cover_info()
obsolete_children = set(b for b in book.children.all()
if b not in children)
from slugify import slugify
from sortify import sortify
meta_tags = []
- categories = (('kinds', 'kind'), ('genres', 'genre'), ('authors', 'author'), ('epochs', 'epoch'))
- for field_name, category in categories:
+ categories = (
+ # BookInfo field names, Tag category, relationship
+ ('kinds', 'kind', None),
+ ('genres', 'genre', None),
+ ('epochs', 'epoch', None),
+ ('authors', 'author', None),
+ ('translators', 'author', 'translator'),
+ )
+ for field_name, category, relationship in categories:
try:
tag_names = getattr(info, field_name)
except (AttributeError, KeyError): # TODO: shouldn't be KeyError here at all.
- try:
- tag_names = [getattr(info, category)]
- except KeyError:
- # For instance, Pictures do not have 'genre' field.
- continue
+ # For instance, Pictures do not have 'genre' field.
+ continue
for tag_name in tag_names:
lang = getattr(tag_name, 'lang', None) or settings.LANGUAGE_CODE
tag_sort_key = tag_name
tag.sort_key = sortify(tag_sort_key.lower())
tag.save()
- meta_tags.append(tag)
+ meta_tags.append((tag, relationship))
else:
- meta_tags.append(tag)
+ meta_tags.append((tag, relationship))
return meta_tags
<p>{% for author in book.authors %}<a href="{{ author.get_absolute_url }}">{{ author.name }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
</p>
<h1><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></h1>
- {% with translators=book.translators %}
- {% if translators %}
+ {% if book.translators.exists %}
<p class="l-header__translators">
- {% if translators.0 != 'tłumacz nieznany' %}
- {% trans "tłum." %}
- {% endif %}
- {% for translator in translators %}
- {{ translator }}{% if not forloop.last %}, {% endif %}
+ {% for translator in book.translators.all %}
+ {% if forloop.first and translator.name != 'tłumacz nieznany' %}
+ {% trans "tłum." %}
+ {% endif %}
+ <a href="{{ translator.get_absolute_url }}">
+ {{ translator }}</a>{% if not forloop.last %}, {% endif %}
{% endfor %}
</p>
{% endif %}
- {% endwith %}
</div>
{% paginate %}
</div>
+ {% if translation_list %}
+ <div class="l-section l-section--col">
+ <h2 class="header">Tłumaczenia</h2>
+ <div class="l-books__grid" id="book-list">
+ {% for book in translation_list %}
+ {% include "catalogue/book_box.html" %}
+ {% endfor %}
+ </div>
+ </div>
+ {% endif %}
+
{% if main_tag %}
<section class="l-section">
<div class="l-author">
<p class="l-text_header_author">{% for author in book.authors %}<a href="{{ author.get_absolute_url }}">{{ author.name }}</a>{% if not forloop.last %}, {% endif %}{% endfor %}
</p>
<h1 class="l-text_header_title"><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></h1>
- {% with translators=book.translators %}
- {% if translators %}
- <p class="l-header__translators">
- {% if translators.0 != 'tłumacz nieznany' %}
+ {% if book.translators.exists %}
+ <p class="l-header__translators">
+ {% for translator in book.translators.all %}
+ {% if forloop.first and translator.name != 'tłumacz nieznany' %}
{% trans "tłum." %}
{% endif %}
- {% for translator in translators %}
- {{ translator }}{% if not forloop.last %}, {% endif %}
- {% endfor %}
- </p>
- {% endif %}
- {% endwith %}
+ <a href="{{ translator.get_absolute_url }}">
+ {{ translator }}</a>{% if not forloop.last %}, {% endif %}
+ {% endfor %}
+ </p>
+ {% endif %}
<div style="margin-top:1em;">
{% content_warning book %}
</div>
t for t in self.ctx['tags']
if t is not self.ctx['main_tag']
]
+ if len(self.ctx['tags']) == 1 and self.ctx['main_tag'].category == 'author':
+ self.ctx['translation_list'] = self.ctx['main_tag'].book_set.all()
def get_queryset(self):
qs = Book.tagged.with_all(self.ctx['work_tags']).filter(findable=True)
picture.title = str(picture_xml.picture_info.title)
picture.extra_info = json.dumps(picture_xml.picture_info.to_dict())
- picture_tags = set(catalogue.models.Tag.tags_from_info(picture_xml.picture_info))
+ picture_tags = set([t for (t, rel) in catalogue.models.Tag.tags_from_info(picture_xml.picture_info)])
for tag in picture_tags:
if not tag.for_pictures:
tag.for_pictures = True