From: Radek Czajka Date: Mon, 19 Sep 2022 10:40:27 +0000 (+0200) Subject: Catalogue improvements. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/022b1747124fb6b6314c4eccf98d5bf89dff5d25 Catalogue improvements. --- diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 54c232f8..8d641545 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -2,7 +2,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.contrib import admin -from django.utils.html import escape +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 @@ -24,7 +24,17 @@ class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin): "wikidata_link", "slug", ] - list_filter = ["year_of_death", "priority", "collections", "status", "gender", "nationality"] + list_display_links = [ + "first_name", "last_name" + ] + list_filter = [ + ("year_of_death", RangeNumericFilter), + "priority", + "collections", + "status", + "gender", + "nationality", + ] list_per_page = 10000000 search_fields = ["first_name", "last_name", "wikidata"] prepopulated_fields = {"slug": ("first_name", "last_name")} @@ -114,15 +124,41 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): "authors__gender", "authors__nationality", "translators__gender", "translators__nationality", "document_book__chunk__stage", - #"document_book__chunk__user", LicenseFilter, CoverLicenseFilter, + 'free_license', + 'polona_missing', ] list_per_page = 1000000 - readonly_fields = ["wikidata_link", "estimated_costs", "documents_book_link"] - actions = [export_as_csv_action()] + readonly_fields = [ + "wikidata_link", + "estimated_costs", + "documents_book_link", + "scans_source_link", + ] + actions = [export_as_csv_action( + fields=[ + "id", + "wikidata", + "slug", + "title", + "authors_str", # authors? + "translators_str", # translators? + "language", + "based_on", + "scans_source", + "text_source", + "notes", + "priority", + "pd_year", + "gazeta_link", + "estimated_chars", + "estimated_verses", + "estimate_source" + ] + )] fieldsets = [ (None, {"fields": [("wikidata", "wikidata_link")]}), ( @@ -153,7 +189,8 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): _("Plan"), { "fields": [ - "scans_source", + ("free_license", "polona_missing"), + ("scans_source", "scans_source_link"), "text_source", "priority", "collections", @@ -199,6 +236,16 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): return mark_safe(''.format(book.get_absolute_url(), book.slug)) documents_book_link.short_description = _('Book') + def scans_source_link(self, obj): + if obj.scans_source: + return format_html( + '{url}', + url=obj.scans_source, + ) + else: + return "" + scans_source_link.short_description = _('scans source') + admin.site.register(models.Book, BookAdmin) diff --git a/src/catalogue/migrations/0031_author_place_of_birth_author_place_of_death_and_more.py b/src/catalogue/migrations/0031_author_place_of_birth_author_place_of_death_and_more.py new file mode 100644 index 00000000..b1ecc81c --- /dev/null +++ b/src/catalogue/migrations/0031_author_place_of_birth_author_place_of_death_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.0.6 on 2022-09-19 12:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0030_auto_20210706_1408'), + ] + + operations = [ + migrations.AddField( + model_name='author', + name='place_of_birth', + field=models.CharField(blank=True, max_length=255, verbose_name='place of birth'), + ), + migrations.AddField( + model_name='author', + name='place_of_death', + field=models.CharField(blank=True, max_length=255, verbose_name='place of death'), + ), + migrations.AddField( + model_name='author', + name='year_of_birth', + field=models.SmallIntegerField(blank=True, null=True, verbose_name='year of birth'), + ), + ] diff --git a/src/catalogue/migrations/0032_book_free_license_book_polona_missing.py b/src/catalogue/migrations/0032_book_free_license_book_polona_missing.py new file mode 100644 index 00000000..dd9a6fa6 --- /dev/null +++ b/src/catalogue/migrations/0032_book_free_license_book_polona_missing.py @@ -0,0 +1,23 @@ +# Generated by Django 4.0.6 on 2022-09-19 12:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0031_author_place_of_birth_author_place_of_death_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='book', + name='free_license', + field=models.BooleanField(default=False, verbose_name='free license'), + ), + migrations.AddField( + model_name='book', + name='polona_missing', + field=models.BooleanField(default=False, verbose_name='missing on Polona'), + ), + ] diff --git a/src/catalogue/models.py b/src/catalogue/models.py index b0d3697b..4568af10 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -19,7 +19,10 @@ class Author(WikidataMixin, models.Model): gender = models.CharField(_("gender"), max_length=255, blank=True) nationality = models.CharField(_("nationality"), max_length=255, blank=True) + year_of_birth = models.SmallIntegerField(_("year of birth"), null=True, blank=True) + place_of_birth = models.CharField(_('place of birth'), max_length=255, blank=True) year_of_death = models.SmallIntegerField(_("year of death"), null=True, blank=True) + place_of_death = models.CharField(_('place of death'), max_length=255, blank=True) status = models.PositiveSmallIntegerField( _("status"), null=True, @@ -58,7 +61,10 @@ class Author(WikidataMixin, models.Model): notes = "description" def __str__(self): - return f"{self.first_name} {self.last_name}" + name = f"{self.first_name} {self.last_name}" + if self.year_of_death is not None: + name += f' (zm. {self.year_of_death})' + return name def get_absolute_url(self): return reverse("catalogue_author", args=[self.slug]) @@ -139,6 +145,9 @@ class Book(WikidataMixin, models.Model): estimated_verses = models.IntegerField(_("estimated number of verses"), null=True, blank=True) estimate_source = models.CharField(_("source of estimates"), max_length=2048, blank=True) + free_license = models.BooleanField(_('free license'), default=False) + polona_missing = models.BooleanField(_('missing on Polona'), default=False) + class Meta: ordering = ("title",) verbose_name = _('book')