X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/acf3c41fb0ffe8e451b1e465b00e9998f2b027ac..cc489b0c8d9ed514fddd5ccb81c9c1f62666663f:/src/catalogue/admin.py?ds=inline diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 00617cb6..8ce330ce 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -2,6 +2,9 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.contrib import admin +from django.utils.translation import gettext_lazy as _ +from admin_numeric_filter.admin import RangeNumericFilter, NumericFilterModelAdmin +from fnpdjango.actions import export_as_csv_action from . import models from .wikidata import WikidataAdminMixin @@ -12,11 +15,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"] @@ -25,7 +30,7 @@ class AuthorAdmin(WikidataAdminMixin, admin.ModelAdmin): admin.site.register(models.Author, AuthorAdmin) -class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): +class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin): list_display = [ "title", "authors_str", @@ -35,15 +40,28 @@ class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): "priority", "wikidata_link", ] - search_fields = ["title", "wikidata"] - autocomplete_fields = ["authors", "translators", "based_on", "collections"] + search_fields = ["title", "wikidata", "authors__first_name", "authors__last_name", "translators__first_name", "translators__last_name"] + autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"] prepopulated_fields = {"slug": ("title",)} - list_filter = ["language", "pd_year", "collections"] - readonly_fields = ["wikidata_link"] + list_filter = [ + "language", + "based_on__language", + ("pd_year", RangeNumericFilter), + "collections", + "collections__category", + "epochs", "kinds", "genres", + "priority", + "authors__gender", "authors__nationality", + "translators__gender", "translators__nationality", + "document_book__chunk__stage", + "document_book__chunk__user", + ] + readonly_fields = ["wikidata_link", "estimated_costs"] + actions = [export_as_csv_action()] fieldsets = [ (None, {"fields": [("wikidata", "wikidata_link")]}), ( - "Identification", + _("Identification"), { "fields": [ "title", @@ -57,7 +75,17 @@ class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): }, ), ( - "Plan", + _("Features"), + { + "fields": [ + "epochs", + "genres", + "kinds", + ] + }, + ), + ( + _("Plan"), { "fields": [ "scans_source", @@ -65,6 +93,8 @@ class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): "priority", "collections", "notes", + ("estimated_chars", "estimated_verses", "estimate_source"), + "estimated_costs", ] }, ), @@ -76,10 +106,22 @@ class BookAdmin(WikidataAdminMixin, admin.ModelAdmin): qs = qs.prefetch_related("authors", "translators") return qs + def estimated_costs(self, obj): + return "\n".join( + "{}: {} zł".format( + work_type.name, + cost or '—' + ) + for work_type, cost in obj.get_estimated_costs().items() + ) + admin.site.register(models.Book, BookAdmin) +admin.site.register(models.CollectionCategory) + + class AuthorInline(admin.TabularInline): model = models.Author.collections.through autocomplete_fields = ["author"] @@ -95,7 +137,40 @@ class CollectionAdmin(admin.ModelAdmin): autocomplete_fields = [] prepopulated_fields = {"slug": ("name",)} search_fields = ["name"] + fields = ['name', 'slug', 'category', 'notes', 'estimated_costs'] + readonly_fields = ['estimated_costs'] inlines = [AuthorInline, BookInline] + def estimated_costs(self, obj): + return "\n".join( + "{}: {} zł".format( + work_type.name, + cost or '—' + ) + for work_type, cost in obj.get_estimated_costs().items() + ) + 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) + + + +class WorkRateInline(admin.TabularInline): + model = models.WorkRate + autocomplete_fields = ['kinds', 'genres', 'epochs', 'collections'] + + +class WorkTypeAdmin(admin.ModelAdmin): + inlines = [WorkRateInline] + +admin.site.register(models.WorkType, WorkTypeAdmin) +