diff --git a/opentech/apply/dashboard/tables.py b/opentech/apply/dashboard/tables.py index 3ae000d46e2ae10636743f3e77b624528b0679cc..d98eed0333ca4aca9fd8b20adab97cbde0a4d06a 100644 --- a/opentech/apply/dashboard/tables.py +++ b/opentech/apply/dashboard/tables.py @@ -1,4 +1,6 @@ +import django_filters as filters import django_tables2 as tables + from opentech.apply.funds.models import ApplicationSubmission @@ -15,3 +17,9 @@ class DashboardTable(tables.Table): def render_user(self, value): return value.get_full_name() + + +class SubmissionFilter(filters.FilterSet): + class Meta: + model = ApplicationSubmission + fields = ('round',) diff --git a/opentech/apply/dashboard/templates/dashboard/dashboard.html b/opentech/apply/dashboard/templates/dashboard/dashboard.html index ee2f7fc260f32525cd43019b34d9ff0487df6f5d..08ae363360542af9d06a1622d0f289f8ebef7909 100644 --- a/opentech/apply/dashboard/templates/dashboard/dashboard.html +++ b/opentech/apply/dashboard/templates/dashboard/dashboard.html @@ -15,6 +15,12 @@ </div> <div class="wrapper wrapper--medium wrapper--top-bottom-inner-space"> - {% render_table object_list %} + {% if filter %} + <form action="" method="get" class="form form-inline"> + {{ filter.form.as_p }} + <button>Filter</button> + </form> + {% endif %} + {% render_table table %} </div> {% endblock %} diff --git a/opentech/apply/dashboard/views.py b/opentech/apply/dashboard/views.py index b86e281c466be79136ff303496990da608fd46c3..0fa61f17c409ddd26c3daf5128dffbfa5bcc5b96 100644 --- a/opentech/apply/dashboard/views.py +++ b/opentech/apply/dashboard/views.py @@ -1,17 +1,14 @@ -from django.views.generic import ListView -from django_tables2 import RequestConfig +from django_filters.views import FilterView +from django_tables2.views import SingleTableMixin from opentech.apply.funds.models import ApplicationSubmission -from .tables import DashboardTable +from .tables import DashboardTable, SubmissionFilter -class DashboardView(ListView): +class DashboardView(SingleTableMixin, FilterView): model = ApplicationSubmission template_name = 'dashboard/dashboard.html' + table_class = DashboardTable - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - context['object_list'] = DashboardTable(context['object_list']) - RequestConfig(self.request).configure(context['object_list']) - return context + filterset_class = SubmissionFilter diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 063ce2e71d820323e02d9e943cf5a0d7867bdef4..8fca9323f77f8c186adcac06bad7791f7b9a1fcb 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -57,6 +57,7 @@ INSTALLED_APPS = [ 'tinymce', 'wagtailcaptcha', 'django_tables2', + 'django_filters', 'addressfield', 'django.contrib.admin', diff --git a/requirements.txt b/requirements.txt index 3289a95041273e351a3da4b6fdb048e02b194aee..b8b5004d5c1306c6fb9a4c385bd1034944b3f991 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ flake8 social_auth_app_django==2.1.0 django-tables2==1.17.1 +django-filter==1.1.0 # Production dependencies dj-database-url==0.4.1