From 631e1c32e1c23b24eda0c747f6bbd30cb394b791 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 19 Sep 2022 15:47:02 +0200 Subject: [PATCH 1/1] More author data in catalogue. --- requirements/notes | 4 + requirements/requirements.txt | 2 + src/catalogue/admin.py | 13 +- src/catalogue/locale/pl/LC_MESSAGES/django.mo | Bin 3327 -> 3607 bytes src/catalogue/locale/pl/LC_MESSAGES/django.po | 171 +++++++++++------- ...iption_pl_author_first_name_de_and_more.py | 88 +++++++++ src/catalogue/migrations/0034_notablebook.py | 27 +++ src/catalogue/models.py | 8 +- src/catalogue/translation.py | 13 ++ src/redakcja/settings/__init__.py | 10 + 10 files changed, 266 insertions(+), 70 deletions(-) create mode 100644 requirements/notes create mode 100644 src/catalogue/migrations/0033_author_description_pl_author_first_name_de_and_more.py create mode 100644 src/catalogue/migrations/0034_notablebook.py create mode 100644 src/catalogue/translation.py diff --git a/requirements/notes b/requirements/notes new file mode 100644 index 00000000..1795c502 --- /dev/null +++ b/requirements/notes @@ -0,0 +1,4 @@ + +Django 4 needs 3.8 +3.9 is fine +3.10 not compatible with lxml diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2f146c98..eba62b92 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -27,5 +27,7 @@ django-debug-toolbar==3.5.0 django-admin-numeric-filter @ git+https://github.com/lukasvinclav/django-admin-numeric-filter.git@83853dfcc8d354c7aea8020a075bbd83dc8ca171 djangorestframework==3.13.1 django-filter==22.1 +django-modeltranslation==0.18.4 +django-admin-ordering==0.15 sentry-sdk==1.8.0 diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 8d641545..47152ebb 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -6,13 +6,21 @@ from django.utils.html import escape, format_html from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ from admin_numeric_filter.admin import RangeNumericFilter, NumericFilterModelAdmin +from admin_ordering.admin import OrderableAdmin from fnpdjango.actions import export_as_csv_action +from modeltranslation.admin import TabbedTranslationAdmin from . import models import documents.models from .wikidata import WikidataAdminMixin -class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin): +class NotableBookInline(OrderableAdmin, admin.TabularInline): + model = models.NotableBook + raw_id_fields = ['book'] + ordering_field_hide_input = True + + +class AuthorAdmin(WikidataAdminMixin, TabbedTranslationAdmin): list_display = [ "first_name", "last_name", @@ -39,6 +47,9 @@ class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin): search_fields = ["first_name", "last_name", "wikidata"] prepopulated_fields = {"slug": ("first_name", "last_name")} autocomplete_fields = ["collections"] + inlines = [ + NotableBookInline, + ] admin.site.register(models.Author, AuthorAdmin) diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.mo b/src/catalogue/locale/pl/LC_MESSAGES/django.mo index 3c0c51d56546f913a9af22427ffc9bac05af110b..3dbf04bec5bdaef81f356104f7704cb34ebdbb8f 100644 GIT binary patch delta 1822 zcmY+ETWDNW6oz*+lVmbub7^dhP2*T=jcpTWk|vroY8%rBqYn~96zRjsbkdw=GDl`6 z6!S7*s8EHV9;1a+5S98+FO=q`R;1XDf_D&Ntcf$t! z9`gs`I{aO57aWHg|1`YTxsrR14<7d-F9lqNjqp`i4^KcIcgpL`IhW)^0Y)HW-6-sW_e1S`8Y>leNG_<7KG0zeD!sYRE#2#yEcsY@tDkv_mb>1;^nI^AACdI}A1PS*Q|+P=Sv^ za&WIfjXMD~?xgjfHl8znZu~Yz{WbAN8d~86(@{V{{*R``_*^_^0=$K6gW=# zv``z|05?Ll_d#8{Vb}~GgsNO=pLHC7Z8SUy6<`r+;F9^rjc-FuTrvLxV;L%u&y1^( z$Ng;n6{x#XLs_^gm85{~zjM84JGv7k(Kd8D8bS)9BiM=lYs2Q~Co1b$gByVNpj(lC z#{H;js-#SnRCVst`h#l0#?ZY;|5ANO=cj)}*>2R0ZbCBcR8{Cfs@5iSGunt`w;=7d zYIpOo!<@Zv#J=0Ke_fEO>CAPZ?n0Z9&N_i)DRf8WYwfia=+f>%x|}*+nU0P7`#;-) zcN^m0-HjstdMQzNIxI%IVteL_(?Q;i2Ek1Dd}N{V;k=hCWW8dL57*bd5Pn=Y5u3_q zGKs98&g2SVd;RW~S-(*5a|aSZF7Z&14RT)iNc}`-)=Os+!Bk?>&ljiN6IFMA#w$*T z$Lo(oDjnh0hNRB?QintSl-PP{PTy) z@6UK)Z{yKuvHaBBte2k8gyqJiFc%wJcPPl_ytTa22fgrQ?184qyf>4ev67ab3IB{e nx_Q>m94wI9Tt3)8pUL^2tG1Mv`O2sLa3a1K{kJ>(F23a-r{T{c delta 1556 zcmY+EO>9h26vuC?(;1zaqUxix+G6OaVP-m`s~RqE&^4^a`Tf=1$J1x3##z-P%GbJ_qUth zZ`=)o%bwFa&Se{rgbkpF$P*0xHj2i+`~A7pOeHp%&yP znfw}Cw7%qj{$}}7+b8Zt{hX04rN*rY{IowKPJ5;q>Uzz{b{7+DYe1*#Y3sSQy=lsMl)KSjO z(<)&EYJwP?4O1511XX!2oB=bi77jvX4ha#BH zrDXd4W$TJ4w2ju+KY~qianyyPNY-9Nq2;&>wt`kKV#%7Uqd%mJwCs#}-+T?;g32S_ z^~zJt1G^6F+@H-2We4{*wG8Zvy8i-uhN51lzt_9q@A5wSw|aenW8UXLW_mo9NW|jF zrbKd0I@KCajQ3B?lub#lX!9OawRvU1bKd3PnVEyR?15s^Vo%x9p$*<}sK=2 && n%10<=4) && (n" -"%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && n" -"%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n" -"X-Generator: Poedit 2.3\n" +"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : (n%10>=2 && n%10<=4) && " +"(n%100<12 || n%100>14) ? 1 : n!=1 && (n%10>=0 && n%10<=1) || (n%10>=5 && " +"n%10<=9) || (n%100>=12 && n%100<=14) ? 2 : 3);\n" +"X-Generator: Poedit 3.0.1\n" -#: catalogue/admin.py:62 +#: catalogue/admin.py:176 msgid "Identification" msgstr "Identyfikacja" -#: catalogue/admin.py:76 +#: catalogue/admin.py:190 msgid "Features" msgstr "Cechy" -#: catalogue/admin.py:86 +#: catalogue/admin.py:200 msgid "Plan" msgstr "Plan" +#: catalogue/admin.py:242 +#, fuzzy +#| msgid "title" +msgid "Title" +msgstr "tytuł" + +#: catalogue/admin.py:248 +msgid "Book" +msgstr "książka" + +#: catalogue/admin.py:258 catalogue/models.py:139 +msgid "scans source" +msgstr "źródło skanów" + #: catalogue/models.py:15 msgid "first name" msgstr "imię" @@ -56,200 +70,217 @@ msgid "nationality" msgstr "narodowość" #: catalogue/models.py:23 +msgid "year of birth" +msgstr "rok urodzenia" + +#: catalogue/models.py:24 +msgid "place of birth" +msgstr "miejsce urodzenia" + +#: catalogue/models.py:25 msgid "year of death" msgstr "rok śmierci" -#: catalogue/models.py:25 +#: catalogue/models.py:26 +msgid "place of death" +msgstr "miejsce śmierci" + +#: catalogue/models.py:28 msgid "status" msgstr "status" -#: catalogue/models.py:29 +#: catalogue/models.py:32 msgid "Alive" msgstr "Żyje" -#: catalogue/models.py:30 +#: catalogue/models.py:33 msgid "Dead" msgstr "Zmarły" -#: catalogue/models.py:31 +#: catalogue/models.py:34 msgid "Long dead" msgstr "Dawno zmarły" -#: catalogue/models.py:32 +#: catalogue/models.py:35 msgid "Unknown" msgstr "Nieznany" -#: catalogue/models.py:35 catalogue/models.py:126 +#: catalogue/models.py:38 catalogue/models.py:141 catalogue/models.py:207 +#: catalogue/models.py:225 msgid "notes" msgstr "notatki" -#: catalogue/models.py:36 catalogue/models.py:132 +#: catalogue/models.py:39 catalogue/models.py:147 msgid "gazeta link" msgstr "link do bazy gazety" -#: catalogue/models.py:37 +#: catalogue/models.py:40 msgid "culture.pl link" msgstr "link do bazy culture.pl" -#: catalogue/models.py:39 +#: catalogue/models.py:42 msgid "description" msgstr "opis" -#: catalogue/models.py:40 -msgid "description (de)" -msgstr "opis (de)" - -#: catalogue/models.py:41 -msgid "description (lt)" -msgstr "opis (lt)" - -#: catalogue/models.py:44 catalogue/models.py:128 catalogue/models.py:253 +#: catalogue/models.py:47 catalogue/models.py:143 catalogue/models.py:275 msgid "priority" msgstr "priorytet" -#: catalogue/models.py:45 catalogue/models.py:129 +#: catalogue/models.py:48 catalogue/models.py:144 msgid "Low" msgstr "Niski" -#: catalogue/models.py:45 catalogue/models.py:129 +#: catalogue/models.py:48 catalogue/models.py:144 msgid "Medium" msgstr "Średni" -#: catalogue/models.py:45 catalogue/models.py:129 +#: catalogue/models.py:48 catalogue/models.py:144 msgid "High" msgstr "Wysoki" -#: catalogue/models.py:47 catalogue/models.py:133 catalogue/models.py:208 -#: catalogue/models.py:260 +#: catalogue/models.py:50 catalogue/models.py:148 catalogue/models.py:230 +#: catalogue/models.py:282 msgid "collections" msgstr "kolekcje" -#: catalogue/models.py:50 +#: catalogue/models.py:53 msgid "author" msgstr "autor" -#: catalogue/models.py:51 catalogue/models.py:107 +#: catalogue/models.py:54 catalogue/models.py:122 msgid "authors" msgstr "autorzy" -#: catalogue/models.py:78 catalogue/models.py:185 catalogue/models.py:201 -#: catalogue/models.py:233 +#: catalogue/models.py:93 catalogue/models.py:205 catalogue/models.py:222 +#: catalogue/models.py:255 msgid "name" msgstr "nazwa" -#: catalogue/models.py:89 +#: catalogue/models.py:104 msgid "epoch" msgstr "epoka" -#: catalogue/models.py:90 catalogue/models.py:115 catalogue/models.py:257 +#: catalogue/models.py:105 catalogue/models.py:130 catalogue/models.py:279 msgid "epochs" msgstr "epoki" -#: catalogue/models.py:95 +#: catalogue/models.py:110 msgid "genre" msgstr "gatunek" -#: catalogue/models.py:96 catalogue/models.py:117 catalogue/models.py:259 +#: catalogue/models.py:111 catalogue/models.py:132 catalogue/models.py:281 msgid "genres" msgstr "gatunki" -#: catalogue/models.py:101 +#: catalogue/models.py:116 msgid "kind" msgstr "rodzaj" -#: catalogue/models.py:102 catalogue/models.py:116 catalogue/models.py:258 +#: catalogue/models.py:117 catalogue/models.py:131 catalogue/models.py:280 msgid "kinds" msgstr "rodzaje" -#: catalogue/models.py:113 +#: catalogue/models.py:128 msgid "translators" msgstr "tłumacze" -#: catalogue/models.py:118 +#: catalogue/models.py:133 msgid "title" msgstr "tytuł" -#: catalogue/models.py:119 +#: catalogue/models.py:134 msgid "language" msgstr "język" -#: catalogue/models.py:122 +#: catalogue/models.py:137 msgid "based on" msgstr "oparte na" -#: catalogue/models.py:124 -msgid "scans source" -msgstr "źródło skanów" - -#: catalogue/models.py:125 +#: catalogue/models.py:140 msgid "text source" msgstr "źródło tekstu" -#: catalogue/models.py:131 +#: catalogue/models.py:146 msgid "year of entry into PD" msgstr "rok wstąpienia do DP" -#: catalogue/models.py:135 +#: catalogue/models.py:150 msgid "estimated number of characters" msgstr "szacowana liczba znaków" -#: catalogue/models.py:136 +#: catalogue/models.py:151 msgid "estimated number of verses" msgstr "szacowana liczba wersów" -#: catalogue/models.py:137 +#: catalogue/models.py:152 msgid "source of estimates" msgstr "źródło szacunków" -#: catalogue/models.py:143 +#: catalogue/models.py:154 +msgid "free license" +msgstr "wolna licencja" + +#: catalogue/models.py:155 +msgid "missing on Polona" +msgstr "brak na Polonie" + +#: catalogue/models.py:159 msgid "book" msgstr "książka" -#: catalogue/models.py:144 +#: catalogue/models.py:160 msgid "books" msgstr "książki" -#: catalogue/models.py:186 +#: catalogue/models.py:190 +msgid "Author" +msgstr "autor" + +#: catalogue/models.py:195 +msgid "Translator" +msgstr "tłumacze" + +#: catalogue/models.py:206 msgid "parent" msgstr "rodzic" -#: catalogue/models.py:190 +#: catalogue/models.py:211 msgid "collection category" msgstr "kategoria kolekcji" -#: catalogue/models.py:191 +#: catalogue/models.py:212 msgid "collection categories" msgstr "kategorie kolekcji" -#: catalogue/models.py:203 +#: catalogue/models.py:224 msgid "category" msgstr "kategoria" -#: catalogue/models.py:207 +#: catalogue/models.py:229 msgid "collection" msgstr "kolekcja" -#: catalogue/models.py:237 catalogue/models.py:256 +#: catalogue/models.py:259 catalogue/models.py:278 msgid "work type" msgstr "rodzaj pracy" -#: catalogue/models.py:238 +#: catalogue/models.py:260 msgid "work types" msgstr "rodzaje prac" -#: catalogue/models.py:254 +#: catalogue/models.py:276 msgid "per normalized page" msgstr "za stronę maszynopisu" -#: catalogue/models.py:255 +#: catalogue/models.py:277 msgid "per verse" msgstr "za wers" -#: catalogue/models.py:264 +#: catalogue/models.py:286 msgid "work rate" msgstr "stawka" -#: catalogue/models.py:265 +#: catalogue/models.py:287 msgid "work rates" msgstr "stawki" @@ -279,3 +310,9 @@ msgstr[3] "" #: catalogue/wikidata.py:18 msgid "If you have a Wikidata ID, like \"Q1337\", enter it and save." msgstr "Jeśli masz identyfikator Wikidanych , jak „Q1337”, wklej go i zapisz." + +#~ msgid "description (de)" +#~ msgstr "opis (de)" + +#~ msgid "description (lt)" +#~ msgstr "opis (lt)" diff --git a/src/catalogue/migrations/0033_author_description_pl_author_first_name_de_and_more.py b/src/catalogue/migrations/0033_author_description_pl_author_first_name_de_and_more.py new file mode 100644 index 00000000..46db716b --- /dev/null +++ b/src/catalogue/migrations/0033_author_description_pl_author_first_name_de_and_more.py @@ -0,0 +1,88 @@ +# Generated by Django 4.0.6 on 2022-09-19 15:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0032_book_free_license_book_polona_missing'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='description_pl', + field=models.TextField(blank=True, null=True, verbose_name='description'), + ), + migrations.AddField( + model_name='author', + name='first_name_de', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='first name'), + ), + migrations.AddField( + model_name='author', + name='first_name_lt', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='first name'), + ), + migrations.AddField( + model_name='author', + name='first_name_pl', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='first name'), + ), + migrations.AddField( + model_name='author', + name='last_name_de', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='last name'), + ), + migrations.AddField( + model_name='author', + name='last_name_lt', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='last name'), + ), + migrations.AddField( + model_name='author', + name='last_name_pl', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='last name'), + ), + migrations.AddField( + model_name='author', + name='place_of_birth_de', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='place of birth'), + ), + migrations.AddField( + model_name='author', + name='place_of_birth_lt', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='place of birth'), + ), + migrations.AddField( + model_name='author', + name='place_of_birth_pl', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='place of birth'), + ), + migrations.AddField( + model_name='author', + name='place_of_death_de', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='place of death'), + ), + migrations.AddField( + model_name='author', + name='place_of_death_lt', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='place of death'), + ), + migrations.AddField( + model_name='author', + name='place_of_death_pl', + field=models.CharField(blank=True, max_length=255, null=True, verbose_name='place of death'), + ), + migrations.AlterField( + model_name='author', + name='description_de', + field=models.TextField(blank=True, null=True, verbose_name='description'), + ), + migrations.AlterField( + model_name='author', + name='description_lt', + field=models.TextField(blank=True, null=True, verbose_name='description'), + ), + ] diff --git a/src/catalogue/migrations/0034_notablebook.py b/src/catalogue/migrations/0034_notablebook.py new file mode 100644 index 00000000..611b5e1b --- /dev/null +++ b/src/catalogue/migrations/0034_notablebook.py @@ -0,0 +1,27 @@ +# Generated by Django 4.0.6 on 2022-09-19 15:35 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0033_author_description_pl_author_first_name_de_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='NotableBook', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('ordering', models.PositiveIntegerField(default=0, verbose_name='ordering')), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalogue.author')), + ('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='catalogue.book')), + ], + options={ + 'ordering': ['ordering'], + 'abstract': False, + }, + ), + ] diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 4568af10..d0698808 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -4,6 +4,7 @@ from django.apps import apps from django.db import models from django.urls import reverse from django.utils.translation import gettext_lazy as _ +from admin_ordering.models import OrderableModel from wikidata.client import Client from .constants import WIKIDATA from .wikidata import WikidataMixin @@ -39,8 +40,6 @@ class Author(WikidataMixin, models.Model): culturepl_link = models.CharField(_("culture.pl link"), max_length=255, blank=True) description = models.TextField(_("description"), blank=True) - description_de = models.TextField(_("description (de)"), blank=True) - description_lt = models.TextField(_("description (lt)"), blank=True) priority = models.PositiveSmallIntegerField( _("priority"), @@ -83,6 +82,11 @@ class Author(WikidataMixin, models.Model): return None +class NotableBook(OrderableModel): + author = models.ForeignKey(Author, models.CASCADE) + book = models.ForeignKey('Book', models.CASCADE) + + class Category(WikidataMixin, models.Model): name = models.CharField(_("name"), max_length=255) slug = models.SlugField(max_length=255, unique=True) diff --git a/src/catalogue/translation.py b/src/catalogue/translation.py new file mode 100644 index 00000000..0ee80711 --- /dev/null +++ b/src/catalogue/translation.py @@ -0,0 +1,13 @@ +from modeltranslation.translator import register, TranslationOptions +from . import models + + +@register(models.Author) +class AuthorTranslationOptions(TranslationOptions): + fields = ( + 'first_name', + 'last_name', + 'place_of_birth', + 'place_of_death', + 'description', + ) diff --git a/src/redakcja/settings/__init__.py b/src/redakcja/settings/__init__.py index 3286f073..ecebe40e 100644 --- a/src/redakcja/settings/__init__.py +++ b/src/redakcja/settings/__init__.py @@ -69,6 +69,8 @@ if CAS_SERVER_URL: ROOT_URLCONF = 'redakcja.urls' INSTALLED_APPS = ( + 'modeltranslation', + 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', @@ -89,6 +91,7 @@ INSTALLED_APPS = ( 'bootstrap4', 'rest_framework', 'django_filters', + 'admin_ordering', 'redakcja.api', 'catalogue', @@ -290,6 +293,13 @@ REST_FRAMEWORK = { } +LANGUAGES = [ + ('pl', 'polski'), + ('de', 'Deutsch'), + ('lt', 'lietuvių'), +] + + TEST_INTEGRATION = False -- 2.20.1