From 8d7518eacc44b585d9ee3f4caccd9a478d9c3c0e Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Fri, 11 Jan 2019 12:43:22 +0000 Subject: [PATCH] Move the search method into the page --- .../funds/base_submissions_table.html | 6 ++-- .../templates/funds/includes/search.html | 4 +-- opentech/apply/funds/urls.py | 2 -- opentech/apply/funds/views.py | 35 ++++++------------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/opentech/apply/funds/templates/funds/base_submissions_table.html b/opentech/apply/funds/templates/funds/base_submissions_table.html index 9804b60e9..5ab3e1796 100644 --- a/opentech/apply/funds/templates/funds/base_submissions_table.html +++ b/opentech/apply/funds/templates/funds/base_submissions_table.html @@ -9,10 +9,8 @@ {% block content %} {% block table %} <div class="wrapper wrapper--table-actions"> - {% if table.data or active_filters %} - <button class="button button--filters button--contains-icons js-toggle-filters">Filters</button> - {% include "funds/includes/search.html" %} - {% endif %} + <button class="button button--filters button--contains-icons js-toggle-filters">Filters</button> + {% include "funds/includes/search.html" %} </div> {% if table.data or active_filters %} diff --git a/opentech/apply/funds/templates/funds/includes/search.html b/opentech/apply/funds/templates/funds/includes/search.html index 0c2a62dc2..525771944 100644 --- a/opentech/apply/funds/templates/funds/includes/search.html +++ b/opentech/apply/funds/templates/funds/includes/search.html @@ -1,6 +1,6 @@ -<form action="{% url 'funds:search' %}" method="get" role="search" class="form form--search-desktop"> +<form action="" method="get" role="search" class="form form--search-desktop"> <button class="button button--search" type="submit" aria-label="Search"> <svg class="icon icon--magnifying-glass icon--search"><use xlink:href="#magnifying-glass"></use></svg> </button> - <input class="input input--search" type="text" placeholder="Search submissions" name="query"{% if search_query %} value="{{ search_query }}{% endif %}" aria-label="Search input"> + <input class="input input--search" type="text" placeholder="Search submissions" name="query"{% if search_term %} value="{{ search_term }}"{% endif %} aria-label="Search input"> </form> diff --git a/opentech/apply/funds/urls.py b/opentech/apply/funds/urls.py index 3f461c32e..cedf0284f 100644 --- a/opentech/apply/funds/urls.py +++ b/opentech/apply/funds/urls.py @@ -8,7 +8,6 @@ from .views import ( SubmissionEditView, SubmissionListView, SubmissionSealedView, - SubmissionSearchView, ) from .api_views import SubmissionList, SubmissionDetail @@ -45,5 +44,4 @@ submission_api_urls = ([ urlpatterns = [ path('submissions/', include(submission_urls)), path('api/submissions/', include(submission_api_urls)), - path('search/', SubmissionSearchView.as_view(), name="search"), ] diff --git a/opentech/apply/funds/views.py b/opentech/apply/funds/views.py index 15f46128b..8f18493cc 100644 --- a/opentech/apply/funds/views.py +++ b/opentech/apply/funds/views.py @@ -39,7 +39,7 @@ from .workflow import STAGE_CHANGE_ACTIONS @method_decorator(staff_required, name='dispatch') class BaseAdminSubmissionsTable(SingleTableMixin, FilterView): table_class = AdminSubmissionsTable - filterset_class = SubmissionFilter + filterset_class = SubmissionFilterAndSearch excluded_fields = [] @@ -61,8 +61,17 @@ class BaseAdminSubmissionsTable(SingleTableMixin, FilterView): return self.filterset_class._meta.model.objects.current().for_table(self.request.user) def get_context_data(self, **kwargs): + kwargs = super().get_context_data(**kwargs,) + + search_term = self.request.GET.get('query') active_filters = self.filterset.data - return super().get_context_data(active_filters=active_filters, **kwargs) + active_filters = len(self.filterset.data) > 1 + kwargs.update( + search_term=search_term, + active_filters=active_filters, + ) + + return kwargs class SubmissionListView(AllActivityContextMixin, BaseAdminSubmissionsTable): @@ -89,28 +98,6 @@ class SubmissionsByRound(BaseAdminSubmissionsTable): return super().get_context_data(object=self.obj, **kwargs) -@method_decorator(staff_required, name='dispatch') -class SubmissionSearchView(BaseAdminSubmissionsTable): - template_name = 'funds/submissions_search.html' - - filterset_class = SubmissionFilterAndSearch - - def get_context_data(self, **kwargs): - kwargs = super().get_context_data(**kwargs,) - - search_term = self.request.GET.get('query') - - # We have more data than just 'query' - active_filters = len(self.filterset.data) > 1 - - kwargs.update( - search_term=search_term, - active_filters=active_filters, - ) - - return kwargs - - @method_decorator(staff_required, name='dispatch') class ProgressSubmissionView(DelegatedViewMixin, UpdateView): model = ApplicationSubmission -- GitLab