From: Radek Czajka Date: Tue, 27 Oct 2020 13:26:52 +0000 (+0100) Subject: Add more properties in catalogue. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/8851e7c8a2e324d6576656f45a08dc90d2c3dd98?ds=sidebyside Add more properties in catalogue. --- diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 00617cb6..608d625d 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -2,6 +2,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.contrib import admin +from django.utils.translation import gettext_lazy as _ from . import models from .wikidata import WikidataAdminMixin @@ -12,11 +13,13 @@ class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin): "last_name", "status", "year_of_death", + "gender", + "nationality", "priority", "wikidata_link", "slug", ] - list_filter = ["year_of_death", "priority", "collections", "status"] + list_filter = ["year_of_death", "priority", "collections", "status", "gender", "nationality"] search_fields = ["first_name", "last_name", "wikidata"] prepopulated_fields = {"slug": ("first_name", "last_name")} autocomplete_fields = ["collections"] @@ -36,14 +39,14 @@ class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): "wikidata_link", ] search_fields = ["title", "wikidata"] - autocomplete_fields = ["authors", "translators", "based_on", "collections"] + autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"] prepopulated_fields = {"slug": ("title",)} list_filter = ["language", "pd_year", "collections"] readonly_fields = ["wikidata_link"] fieldsets = [ (None, {"fields": [("wikidata", "wikidata_link")]}), ( - "Identification", + _("Identification"), { "fields": [ "title", @@ -57,7 +60,17 @@ class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): }, ), ( - "Plan", + _("Features"), + { + "fields": [ + "epochs", + "genres", + "kinds", + ] + }, + ), + ( + _("Plan"), { "fields": [ "scans_source", @@ -99,3 +112,11 @@ class CollectionAdmin(admin.ModelAdmin): admin.site.register(models.Collection, CollectionAdmin) + + +class CategoryAdmin(admin.ModelAdmin): + search_fields = ["name"] + +admin.site.register(models.Epoch, CategoryAdmin) +admin.site.register(models.Genre, CategoryAdmin) +admin.site.register(models.Kind, CategoryAdmin) diff --git a/src/catalogue/constants.py b/src/catalogue/constants.py index 88d0e338..5bb775ac 100644 --- a/src/catalogue/constants.py +++ b/src/catalogue/constants.py @@ -2,6 +2,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # class WIKIDATA: + GENDER = "P21" AUTHOR = "P50" LANGUAGE = "P407" DATE_OF_DEATH = "P570" diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.mo b/src/catalogue/locale/pl/LC_MESSAGES/django.mo index eb7cf859..da3bb293 100644 Binary files a/src/catalogue/locale/pl/LC_MESSAGES/django.mo and b/src/catalogue/locale/pl/LC_MESSAGES/django.mo differ diff --git a/src/catalogue/locale/pl/LC_MESSAGES/django.po b/src/catalogue/locale/pl/LC_MESSAGES/django.po index 3b3d06bb..2bf50562 100644 --- a/src/catalogue/locale/pl/LC_MESSAGES/django.po +++ b/src/catalogue/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,10 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-04-20 16:44+0200\n" -"PO-Revision-Date: 2020-04-20 16:52+0200\n" +"POT-Creation-Date: 2020-10-27 14:25+0100\n" +"PO-Revision-Date: 2020-10-27 14:25+0100\n" +"Last-Translator: \n" +"Language-Team: \n" "Language: pl\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -16,47 +18,111 @@ msgstr "" "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" -"Last-Translator: \n" -"Language-Team: \n" -"X-Generator: Poedit 2.2.4\n" +"X-Generator: Poedit 2.3\n" + +#: catalogue/admin.py:49 +msgid "Identification" +msgstr "Identyfikacja" -#: models.py:22 +#: catalogue/admin.py:63 +msgid "Features" +msgstr "Cechy" + +#: catalogue/admin.py:73 +msgid "Plan" +msgstr "Plan" + +#: catalogue/models.py:26 msgid "Alive" msgstr "Żyje" -#: models.py:23 +#: catalogue/models.py:27 msgid "Dead" msgstr "Zmarły" -#: models.py:24 +#: catalogue/models.py:28 msgid "Long dead" msgstr "Dawno zmarły" -#: models.py:25 +#: catalogue/models.py:29 msgid "Unknown" msgstr "Nieznany" -#: models.py:37 models.py:83 +#: catalogue/models.py:41 catalogue/models.py:120 msgid "Low" msgstr "Niski" -#: models.py:37 models.py:83 +#: catalogue/models.py:41 catalogue/models.py:120 msgid "Medium" msgstr "Średni" -#: models.py:37 models.py:83 +#: catalogue/models.py:41 catalogue/models.py:120 msgid "High" msgstr "Wysoki" -#: templates/catalogue/catalogue.html:7 templates/catalogue/catalogue.html:13 +#: catalogue/models.py:46 +msgid "author" +msgstr "autor" + +#: catalogue/models.py:47 +msgid "authors" +msgstr "autorzy" + +#: catalogue/models.py:83 +msgid "epoch" +msgstr "epoka" + +#: catalogue/models.py:84 +msgid "epochs" +msgstr "epoki" + +#: catalogue/models.py:89 +msgid "genre" +msgstr "gatunek" + +#: catalogue/models.py:90 +msgid "genres" +msgstr "gatunki" + +#: catalogue/models.py:95 +msgid "kind" +msgstr "rodzaj" + +#: catalogue/models.py:96 +msgid "kinds" +msgstr "rodzaje" + +#: catalogue/models.py:130 +msgid "book" +msgstr "książka" + +#: catalogue/models.py:131 +msgid "books" +msgstr "książki" + +#: catalogue/models.py:170 +msgid "collection" +msgstr "kolekcja" + +#: catalogue/models.py:171 +msgid "collections" +msgstr "kolekcje" + +#: catalogue/templates/catalogue/author_detail.html:7 +#: catalogue/templates/catalogue/author_detail.html:13 +#: catalogue/templates/catalogue/book_detail.html:7 +#: catalogue/templates/catalogue/book_detail.html:13 +#: catalogue/templates/catalogue/catalogue.html:7 +#: catalogue/templates/catalogue/catalogue.html:13 msgid "Catalogue" msgstr "Katalog" -#: templates/catalogue/catalogue.html:67 +#: catalogue/templates/catalogue/author_detail.html:66 +#: catalogue/templates/catalogue/catalogue.html:67 msgid "trans." msgstr "tłum." -#: templates/catalogue/catalogue.html:90 +#: catalogue/templates/catalogue/catalogue.html:90 #, python-format msgid "%(c)s author" msgid_plural "%(c)s authors" @@ -65,7 +131,6 @@ msgstr[1] "%(c)s autorów" msgstr[2] "%(c)s autorów" msgstr[3] "" -#: wikidata.py:18 +#: 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." +msgstr "Jeśli masz identyfikator Wikidanych , jak „Q1337”, wklej go i zapisz." diff --git a/src/catalogue/migrations/0019_auto_20201027_1331.py b/src/catalogue/migrations/0019_auto_20201027_1331.py new file mode 100644 index 00000000..bda87224 --- /dev/null +++ b/src/catalogue/migrations/0019_auto_20201027_1331.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.4 on 2020-10-27 13:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0018_auto_20200417_1859'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='gender', + field=models.CharField(blank=True, max_length=255), + ), + migrations.AddField( + model_name='author', + name='nationality', + field=models.CharField(blank=True, max_length=255), + ), + ] diff --git a/src/catalogue/migrations/0020_auto_20201027_1416.py b/src/catalogue/migrations/0020_auto_20201027_1416.py new file mode 100644 index 00000000..274c4797 --- /dev/null +++ b/src/catalogue/migrations/0020_auto_20201027_1416.py @@ -0,0 +1,64 @@ +# Generated by Django 3.0.4 on 2020-10-27 14:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0019_auto_20201027_1331'), + ] + + operations = [ + migrations.CreateModel( + name='Epoch', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('wikidata', models.CharField(blank=True, help_text='If you have a Wikidata ID, like "Q1337", enter it and save.', max_length=255)), + ('name', models.CharField(max_length=255)), + ('slug', models.SlugField(max_length=255, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Genre', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('wikidata', models.CharField(blank=True, help_text='If you have a Wikidata ID, like "Q1337", enter it and save.', max_length=255)), + ('name', models.CharField(max_length=255)), + ('slug', models.SlugField(max_length=255, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Kind', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('wikidata', models.CharField(blank=True, help_text='If you have a Wikidata ID, like "Q1337", enter it and save.', max_length=255)), + ('name', models.CharField(max_length=255)), + ('slug', models.SlugField(max_length=255, unique=True)), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='book', + name='epochs', + field=models.ManyToManyField(blank=True, to='catalogue.Epoch'), + ), + migrations.AddField( + model_name='book', + name='genres', + field=models.ManyToManyField(blank=True, to='catalogue.Genre'), + ), + migrations.AddField( + model_name='book', + name='kinds', + field=models.ManyToManyField(blank=True, to='catalogue.Kind'), + ), + ] diff --git a/src/catalogue/migrations/0021_auto_20201027_1422.py b/src/catalogue/migrations/0021_auto_20201027_1422.py new file mode 100644 index 00000000..0f77d780 --- /dev/null +++ b/src/catalogue/migrations/0021_auto_20201027_1422.py @@ -0,0 +1,37 @@ +# Generated by Django 3.0.4 on 2020-10-27 14:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0020_auto_20201027_1416'), + ] + + operations = [ + migrations.AlterModelOptions( + name='author', + options={'ordering': ('last_name', 'first_name', 'year_of_death'), 'verbose_name': 'author', 'verbose_name_plural': 'authors'}, + ), + migrations.AlterModelOptions( + name='book', + options={'ordering': ('title',), 'verbose_name': 'book', 'verbose_name_plural': 'books'}, + ), + migrations.AlterModelOptions( + name='collection', + options={'verbose_name': 'collection', 'verbose_name_plural': 'collections'}, + ), + migrations.AlterModelOptions( + name='epoch', + options={'verbose_name': 'author', 'verbose_name_plural': 'authors'}, + ), + migrations.AlterModelOptions( + name='genre', + options={'verbose_name': 'genre', 'verbose_name_plural': 'genres'}, + ), + migrations.AlterModelOptions( + name='kind', + options={'verbose_name': 'kind', 'verbose_name_plural': 'kinds'}, + ), + ] diff --git a/src/catalogue/migrations/0022_auto_20201027_1424.py b/src/catalogue/migrations/0022_auto_20201027_1424.py new file mode 100644 index 00000000..434e7451 --- /dev/null +++ b/src/catalogue/migrations/0022_auto_20201027_1424.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.4 on 2020-10-27 14:24 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0021_auto_20201027_1422'), + ] + + operations = [ + migrations.AlterModelOptions( + name='epoch', + options={'verbose_name': 'epoch', 'verbose_name_plural': 'epochs'}, + ), + ] diff --git a/src/catalogue/models.py b/src/catalogue/models.py index 0863c1e3..682e97bc 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -2,6 +2,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 wikidata.client import Client from .constants import WIKIDATA from .utils import UnrelatedManager from .wikidata import WikidataMixin @@ -15,6 +16,8 @@ class Author(WikidataMixin, models.Model): name_de = models.CharField(max_length=255, blank=True) name_lt = models.CharField(max_length=255, blank=True) + gender = models.CharField(max_length=255, blank=True) + nationality = models.CharField(max_length=255, blank=True) year_of_death = models.SmallIntegerField(null=True, blank=True) status = models.PositiveSmallIntegerField( null=True, @@ -40,12 +43,15 @@ class Author(WikidataMixin, models.Model): collections = models.ManyToManyField("Collection", blank=True) class Meta: + verbose_name = _('author') + verbose_name_plural = _('authors') ordering = ("last_name", "first_name", "year_of_death") class Wikidata: first_name = WIKIDATA.GIVEN_NAME last_name = WIKIDATA.LAST_NAME year_of_death = WIKIDATA.DATE_OF_DEATH + gender = WIKIDATA.GENDER notes = "description" def __str__(self): @@ -63,6 +69,33 @@ class Author(WikidataMixin, models.Model): else: return None + +class Category(WikidataMixin, models.Model): + name = models.CharField(max_length=255) + slug = models.SlugField(max_length=255, unique=True) + + class Meta: + abstract = True + + +class Epoch(Category): + class Meta: + verbose_name = _('epoch') + verbose_name_plural = _('epochs') + + +class Genre(Category): + class Meta: + verbose_name = _('genre') + verbose_name_plural = _('genres') + + +class Kind(Category): + class Meta: + verbose_name = _('kind') + verbose_name_plural = _('kinds') + + class Book(WikidataMixin, models.Model): slug = models.SlugField(max_length=255, blank=True, null=True, unique=True) authors = models.ManyToManyField(Author, blank=True) @@ -72,6 +105,9 @@ class Book(WikidataMixin, models.Model): related_query_name="translated_book", blank=True, ) + epochs = models.ManyToManyField(Epoch, blank=True) + kinds = models.ManyToManyField(Kind, blank=True) + genres = models.ManyToManyField(Genre, blank=True) title = models.CharField(max_length=255, blank=True) language = models.CharField(max_length=255, blank=True) based_on = models.ForeignKey( @@ -91,6 +127,8 @@ class Book(WikidataMixin, models.Model): class Meta: ordering = ("title",) + verbose_name = _('book') + verbose_name_plural = _('books') class Wikidata: authors = WIKIDATA.AUTHOR @@ -128,5 +166,10 @@ class Collection(models.Model): name = models.CharField(max_length=255) slug = models.SlugField(max_length=255, unique=True) + class Meta: + verbose_name = _('collection') + verbose_name_plural = _('collections') + def __str__(self): return self.name +