From 8603830281b07d69b89e18eccc4ad24e4839cf3d Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson <frjo@xdeb.org> Date: Mon, 25 Nov 2019 16:04:01 +0100 Subject: [PATCH] Add a open/closed filter to the round admin page in wagtail admin. --- opentech/apply/funds/admin.py | 2 ++ opentech/apply/funds/admin_helpers.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/opentech/apply/funds/admin.py b/opentech/apply/funds/admin.py index 3eef4a8b7..1c1414756 100644 --- a/opentech/apply/funds/admin.py +++ b/opentech/apply/funds/admin.py @@ -12,6 +12,7 @@ from opentech.apply.categories.admin import CategoryAdmin, MetaTermAdmin from .admin_helpers import ( ButtonsWithPreview, FormsFundRoundListFilter, + RoundStateListFilter, RoundFundChooserView, ApplicationFormButtonHelper, ) @@ -32,6 +33,7 @@ class RoundAdmin(BaseRoundAdmin): model = Round menu_icon = 'repeat' list_display = ('title', 'fund', 'start_date', 'end_date', 'applications', 'review_forms') + list_filter = (RoundStateListFilter,) def applications(self, obj): diff --git a/opentech/apply/funds/admin_helpers.py b/opentech/apply/funds/admin_helpers.py index 79d4b8f31..8df313c63 100644 --- a/opentech/apply/funds/admin_helpers.py +++ b/opentech/apply/funds/admin_helpers.py @@ -71,6 +71,25 @@ class FormsFundRoundListFilter(admin.SimpleListFilter): return queryset +class RoundStateListFilter(admin.SimpleListFilter): + title = 'state' + parameter_name = 'form-state' + + def lookups(self, request, model_admin): + return ( + ('open', _('Open')), + ('closed', _('Closed')), + ) + + def queryset(self, request, queryset): + value = self.value() + if value == 'open': + return queryset.open() + elif value == 'closed': + return queryset.closed() + return queryset + + class ApplicationFormButtonHelper(ButtonHelper): def prepare_classnames(self, start=None, add=None, exclude=None): """Parse classname sets into final css classess list.""" -- GitLab