Catalogue improvements.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 19 Sep 2022 10:40:27 +0000 (12:40 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 19 Sep 2022 10:40:27 +0000 (12:40 +0200)
src/catalogue/admin.py
src/catalogue/migrations/0031_author_place_of_birth_author_place_of_death_and_more.py [new file with mode: 0644]
src/catalogue/migrations/0032_book_free_license_book_polona_missing.py [new file with mode: 0644]
src/catalogue/models.py

index 54c232f..8d64154 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from django.contrib import admin
 # 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
 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",
     ]
         "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")}
     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",
         "authors__gender", "authors__nationality",
         "translators__gender", "translators__nationality",
         "document_book__chunk__stage",
-        #"document_book__chunk__user",
 
         LicenseFilter,
         CoverLicenseFilter,
 
         LicenseFilter,
         CoverLicenseFilter,
+        'free_license',
+        'polona_missing',
     ]
     list_per_page = 1000000
 
     ]
     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")]}),
         (
     fieldsets = [
         (None, {"fields": [("wikidata", "wikidata_link")]}),
         (
@@ -153,7 +189,8 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin):
             _("Plan"),
             {
                 "fields": [
             _("Plan"),
             {
                 "fields": [
-                    "scans_source",
+                    ("free_license", "polona_missing"),
+                    ("scans_source", "scans_source_link"),
                     "text_source",
                     "priority",
                     "collections",
                     "text_source",
                     "priority",
                     "collections",
@@ -199,6 +236,16 @@ class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin):
             return mark_safe('<a style="position: absolute" href="{}"><img height="100" width="70" src="/cover/preview/{}/?height=100&width=70"></a>'.format(book.get_absolute_url(), book.slug))
     documents_book_link.short_description = _('Book')
 
             return mark_safe('<a style="position: absolute" href="{}"><img height="100" width="70" src="/cover/preview/{}/?height=100&width=70"></a>'.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(
+                '<a href="{url}" target="_blank">{url}</a>',
+                url=obj.scans_source,
+            )
+        else:
+            return ""
+    scans_source_link.short_description = _('scans source')
+
 
 admin.site.register(models.Book, BookAdmin)
 
 
 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 (file)
index 0000000..b1ecc81
--- /dev/null
@@ -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 (file)
index 0000000..dd9a6fa
--- /dev/null
@@ -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'),
+        ),
+    ]
index b0d3697..4568af1 100644 (file)
@@ -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)
 
     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)
     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,
     status = models.PositiveSmallIntegerField(
         _("status"), 
         null=True,
@@ -58,7 +61,10 @@ class Author(WikidataMixin, models.Model):
         notes = "description"
 
     def __str__(self):
         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])
 
     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)
 
     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')
     class Meta:
         ordering = ("title",)
         verbose_name = _('book')