Skip to content
Snippets Groups Projects
Unverified Commit bb97f896 authored by Fredrik Jonsson's avatar Fredrik Jonsson Committed by GitHub
Browse files

Merge pull request #1702 from OpenTechFund/enhancement/round_admin_state_filter

Add a open/closed filter to the round admin page in wagtail admin.
parents f076b017 12756831
No related branches found
Tags v5.5.0
No related merge requests found
......@@ -12,7 +12,9 @@ from opentech.apply.categories.admin import CategoryAdmin, MetaTermAdmin
from .admin_helpers import (
ButtonsWithPreview,
FormsFundRoundListFilter,
RoundStateListFilter,
RoundFundChooserView,
RoundAdminURLHelper,
ApplicationFormButtonHelper,
)
from .admin_views import CopyApplicationFormViewClass
......@@ -32,6 +34,8 @@ class RoundAdmin(BaseRoundAdmin):
model = Round
menu_icon = 'repeat'
list_display = ('title', 'fund', 'start_date', 'end_date', 'applications', 'review_forms')
list_filter = (RoundStateListFilter,)
url_helper_class = RoundAdminURLHelper
def applications(self, obj):
......
from urllib.parse import urlencode
from django import forms
from django.contrib import admin
from django.urls import reverse
from django.utils.functional import cached_property
from django.utils.translation import ugettext as _
from wagtail.contrib.modeladmin.forms import ParentChooserForm
from wagtail.contrib.modeladmin.helpers import PageButtonHelper, ButtonHelper
from wagtail.contrib.modeladmin.helpers import PageAdminURLHelper, PageButtonHelper, ButtonHelper
from wagtail.contrib.modeladmin.views import ChooseParentView
from wagtail.core.models import Page
......@@ -71,6 +74,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."""
......@@ -103,3 +125,11 @@ class ApplicationFormButtonHelper(ButtonHelper):
buttons.append(copy_form_button)
return buttons
class RoundAdminURLHelper(PageAdminURLHelper):
@cached_property
def index_url(self):
# By default set open filter for Round listing page's index URL
params = {'form-state': 'open'}
return f"{self.get_action_url('index')}?{urlencode(params)}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment