From 4a04d4edae8083cce72cf9755257ae4f8578443c Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Thu, 15 Feb 2018 11:55:36 +0000 Subject: [PATCH] Add select2 widget to the form --- opentech/apply/dashboard/tables.py | 11 +++++++++-- .../dashboard/templates/dashboard/dashboard.html | 4 ++++ opentech/settings/base.py | 1 + opentech/urls.py | 1 + requirements.txt | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/opentech/apply/dashboard/tables.py b/opentech/apply/dashboard/tables.py index d51aa4b49..3fe68e7ad 100644 --- a/opentech/apply/dashboard/tables.py +++ b/opentech/apply/dashboard/tables.py @@ -1,5 +1,6 @@ import django_filters as filters import django_tables2 as tables +from django_select2.forms import Select2MultipleWidget from wagtail.wagtailcore.models import Page @@ -30,9 +31,15 @@ def get_used_funds(request): return Page.objects.filter(applicationsubmission__isnull=False).distinct() +class Select2ModelMultipleChoiceFilter(filters.ModelMultipleChoiceFilter): + def __init__(self, *args, **kwargs): + kwargs.setdefault('widget', Select2MultipleWidget) + super().__init__(*args, **kwargs) + + class SubmissionFilter(filters.FilterSet): - round = filters.ModelMultipleChoiceFilter(queryset=get_used_rounds) - page = filters.ModelMultipleChoiceFilter(queryset=get_used_funds, label='Funds') + round = Select2ModelMultipleChoiceFilter(queryset=get_used_rounds) + page = Select2ModelMultipleChoiceFilter(queryset=get_used_funds, label='Funds') class Meta: model = ApplicationSubmission diff --git a/opentech/apply/dashboard/templates/dashboard/dashboard.html b/opentech/apply/dashboard/templates/dashboard/dashboard.html index 08ae36336..e8ec362ed 100644 --- a/opentech/apply/dashboard/templates/dashboard/dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/dashboard.html @@ -24,3 +24,7 @@ {% render_table table %} </div> {% endblock %} + +{% block extra_js %} + {{ filter.form.media }} +{% endblock %} diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 8fca9323f..7499a8eda 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -58,6 +58,7 @@ INSTALLED_APPS = [ 'wagtailcaptcha', 'django_tables2', 'django_filters', + 'django_select2', 'addressfield', 'django.contrib.admin', diff --git a/opentech/urls.py b/opentech/urls.py index 77fbcf1c9..22c3889c8 100644 --- a/opentech/urls.py +++ b/opentech/urls.py @@ -24,6 +24,7 @@ urlpatterns = [ url('^', include(apply_urls)), url('^', include('social_django.urls', namespace='social')), url(r'^tinymce/', include('tinymce.urls')), + url(r'^select2/', include('django_select2.urls')), ] diff --git a/requirements.txt b/requirements.txt index b8b5004d5..497a0a0b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,6 +20,7 @@ flake8 social_auth_app_django==2.1.0 django-tables2==1.17.1 django-filter==1.1.0 +django_select2==6.0.1 # Production dependencies dj-database-url==0.4.1 -- GitLab