From 1c281eadaa7164d9b6e76be6ae325561c0297965 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 6 Sep 2022 13:35:01 +0200 Subject: [PATCH 1/1] Add wiki_link filter for books. --- src/catalogue/admin.py | 10 +++++++++- src/club/forms.py | 2 +- src/pz/admin.py | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/catalogue/admin.py b/src/catalogue/admin.py index 997dd5ed0..47032ba2d 100644 --- a/src/catalogue/admin.py +++ b/src/catalogue/admin.py @@ -3,6 +3,11 @@ # from django.contrib import admin from catalogue.models import Tag, Book, Fragment, BookMedia, Collection, Source +from pz.admin import EmptyFieldListFilter + + +class BlankFieldListFilter(EmptyFieldListFilter): + with_empty_str = True class TagAdmin(admin.ModelAdmin): @@ -30,7 +35,10 @@ class BookAdmin(admin.ModelAdmin): list_display = ( 'title', 'slug', 'created_at', 'has_epub_file', 'has_html_file', 'has_description', ) - list_filter = ['print_on_demand'] + list_filter = [ + 'print_on_demand', + ('wiki_link', BlankFieldListFilter), + ] search_fields = ('title',) ordering = ('title',) diff --git a/src/club/forms.py b/src/club/forms.py index f91985539..2347e2a61 100644 --- a/src/club/forms.py +++ b/src/club/forms.py @@ -143,7 +143,7 @@ class DonationStep1Form(forms.ModelForm): state['amount'] = \ self.cleaned_data[f'{which}_amount'] or \ self.cleaned_data['custom_amount'] or \ - self.cleaned_data[f'{monthly}_amount_selected'] + self.cleaned_data[f'{which}_amount_selected'] return state diff --git a/src/pz/admin.py b/src/pz/admin.py index 23ad9c249..1b8838315 100644 --- a/src/pz/admin.py +++ b/src/pz/admin.py @@ -18,6 +18,8 @@ admin.site.register(models.Campaign) # Backport from Django 3.1. class EmptyFieldListFilter(FieldListFilter): + with_empty_str = False + def __init__(self, field, request, params, model, model_admin, field_path): self.lookup_kwarg = '%s__isempty' % field_path self.lookup_val = params.get(self.lookup_kwarg) @@ -30,6 +32,8 @@ class EmptyFieldListFilter(FieldListFilter): raise IncorrectLookupParameters lookup_condition = Q(**{'%s__isnull' % self.field_path: True}) + if self.with_empty_str: + lookup_condition |= Q(**{self.field_path: ''}) if self.lookup_val == '1': return queryset.filter(lookup_condition) return queryset.exclude(lookup_condition) -- 2.20.1