-class BookAdmin(WikidataAdminMixin, admin.ModelAdmin):
- list_display = ["title", 'authors_str', 'translators_str', 'language', 'pd_year', 'priority', 'wikidata_link']
- search_fields = ["title", 'wikidata']
- autocomplete_fields = ["authors", "translators", "based_on", 'collections']
+class LicenseFilter(admin.SimpleListFilter):
+ title = 'Licencja'
+ parameter_name = 'book_license'
+ license_url_field = 'document_book__dc__license'
+ license_name_field = 'document_book__dc__license_description'
+
+ def lookups(self, requesrt, model_admin):
+ return [
+ ('cc', 'CC'),
+ ('fal', 'FAL'),
+ ('pd', 'domena publiczna'),
+ ]
+
+ def queryset(self, request, queryset):
+ v = self.value()
+ if v == 'cc':
+ return queryset.filter(**{
+ self.license_url_field + '__icontains': 'creativecommons.org'
+ })
+ elif v == 'fal':
+ return queryset.filter(**{
+ self.license_url_field + '__icontains': 'artlibre.org'
+ })
+ elif v == 'pd':
+ return queryset.filter(**{
+ self.license_name_field + '__icontains': 'domena publiczna'
+ })
+ else:
+ return queryset
+
+
+class CoverLicenseFilter(LicenseFilter):
+ title = 'Licencja okładki'
+ parameter_name = 'cover_license'
+ license_url_field = 'document_book__dc_cover_image__license_url'
+ license_name_field = 'document_book__dc_cover_image__license_name'
+
+
+class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin):
+ list_display = [
+ "smart_title",
+ "authors_str",
+ "translators_str",
+ "language",
+ "pd_year",
+ "priority",
+ "wikidata_link",
+ ]
+ search_fields = [
+ "title", "wikidata",
+ "authors__first_name", "authors__last_name",
+ "translators__first_name", "translators__last_name",
+ "scans_source", "text_source", "notes", "estimate_source",
+ ]
+ autocomplete_fields = ["authors", "translators", "based_on", "collections", "epochs", "genres", "kinds"]