From bfb8d67c0c5c7595c194fe1b3dbc48b19986d0d2 Mon Sep 17 00:00:00 2001 From: edmondsgarrett <43251554+edmondsgarrett@users.noreply.github.com> Date: Mon, 8 May 2023 16:34:03 -0500 Subject: [PATCH] task/WP-7: Admin submissions filtering and date-sorting (#151) * Added url patterns for filter and sort on this page * Added filter and sort data modification to page's view * Added filter and sort dropdowns and coinciding scripts to handle changes on those elements to reload page with selected options implemented * Add date sort to view and grab selected filter + sort from url in view --- .../templates/list_admin_submissions.html | 62 +++++++++++++++++++ apcd-cms/src/apps/admin_submissions/urls.py | 3 + apcd-cms/src/apps/admin_submissions/views.py | 26 +++++++- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/apcd-cms/src/apps/admin_submissions/templates/list_admin_submissions.html b/apcd-cms/src/apps/admin_submissions/templates/list_admin_submissions.html index 614eaa5c..bd54433b 100644 --- a/apcd-cms/src/apps/admin_submissions/templates/list_admin_submissions.html +++ b/apcd-cms/src/apps/admin_submissions/templates/list_admin_submissions.html @@ -6,6 +6,7 @@ +
@@ -15,6 +16,27 @@

View Submissions


All completed submissions by organizations


+
+
+ Filter by Status: + + Sort by: + + {% if selected_filter or selected_sort %} + + {% endif %} +
+
+ @@ -43,4 +65,44 @@

View Submissions

{% include 'paginator.html' %} + {% endblock %} diff --git a/apcd-cms/src/apps/admin_submissions/urls.py b/apcd-cms/src/apps/admin_submissions/urls.py index fed16b10..dab6a62d 100644 --- a/apcd-cms/src/apps/admin_submissions/urls.py +++ b/apcd-cms/src/apps/admin_submissions/urls.py @@ -4,4 +4,7 @@ app_name = 'administration' urlpatterns = [ path('list-submissions/', AdminSubmissionsTable.as_view(), name="admin_submissions"), + path(r'list-submissions/?filter=(?P)/', AdminSubmissionsTable.as_view(), name="admin_submissions"), + path(r'list-submissions/?sort=(?P)/', AdminSubmissionsTable.as_view(), name="admin_submissions"), + path(r'list-submissions/?filter=(?P)&sort=(?P)/', AdminSubmissionsTable.as_view(), name="admin_submissions"), ] diff --git a/apcd-cms/src/apps/admin_submissions/views.py b/apcd-cms/src/apps/admin_submissions/views.py index 9945a3c9..33eda310 100644 --- a/apcd-cms/src/apps/admin_submissions/views.py +++ b/apcd-cms/src/apps/admin_submissions/views.py @@ -2,7 +2,7 @@ from django.views.generic.base import TemplateView from apps.utils.apcd_database import get_all_submissions_and_logs from apps.utils.apcd_groups import is_apcd_admin -from apps.utils.utils import title_case +from apps.utils.utils import title_case, table_filter from apps.components.paginator.paginator import paginator import logging from dateutil import parser @@ -24,11 +24,27 @@ def get_context_data(self, *args, **kwargs): submission_content = get_all_submissions_and_logs() + filter = self.request.GET.get('filter') + dateSort = self.request.GET.get('sort') + + def getDate(row): + date = row['received_timestamp'] + return parser.parse(date) if date is not None else parser.parse('1-1-3005') # put 'None' date entries all together at top/bottom depending on direction of sort + + if dateSort is not None: + context['selected_sort'] = dateSort + submission_content = sorted(submission_content, key=lambda row:getDate(row), reverse=(dateSort == 'newDate')) + try: page_num = int(self.request.GET.get('page')) except: page_num = 1 + context['selected_filter'] = None + if filter is not None and filter != 'All': + context['selected_filter'] = filter + submission_content = table_filter(filter, submission_content, 'status') + limit = 50 offset = limit * (page_num - 1) @@ -45,7 +61,13 @@ def get_context_data(self, *args, **kwargs): } for t in (s['view_modal_content'] or [])] context['header'] = ['Received', 'Organization', 'File Name', ' ', 'Outcome', 'Status', 'Last Updated', 'Actions'] + context['filter_options'] = ['All', 'In Process', 'Complete'] + context['sort_options'] = {'newDate': 'Newest Received', 'oldDate': 'Oldest Received'} - context.update(paginator(self.request, submission_content)) + queryStr = '?' + if len(self.request.META['QUERY_STRING']) > 0: + queryStr = queryStr + self.request.META['QUERY_STRING'].replace(f'page={page_num}', '') + ('&' if self.request.GET.get('page') is None else '') + context['query_str'] = queryStr + context.update(paginator(self.request, submission_content, limit)) context['pagination_url_namespaces'] = 'admin_submission:admin_submissions' return context