+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'
+
+
+def add_title(base_class, suffix):
+ class TitledCategoryFilter(base_class):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.title += suffix
+ return TitledCategoryFilter
+
+
+
+class BookAdmin(WikidataAdminMixin, NumericFilterModelAdmin):