Skip to content

Commit

Permalink
Task/wp 751 submission listing bugs (#357)
Browse files Browse the repository at this point in the history
* - Updated view and url to get filters and filtered
submission content
- Moved styles from app to client
- Added sort options to filter hooks
- Created client side title case util so it won't
break pages on response if response does not exist

* - Staged the wrong changes. WIP from Nov 12

* - Adds filter styles to filter-contents class rather
that hard coding

* - Added some debug statements to find where
the modal data goes missing

* - Final configuring of both submitter submission page
and admin submission page

* - Catches undefined for string utils
- Removes repeated header

* - Linting

---------

Co-authored-by: Chandra Y <[email protected]>
  • Loading branch information
sophia-massie and chandra-tacc authored Nov 13, 2024
1 parent 3cbbc80 commit 1d12a43
Show file tree
Hide file tree
Showing 23 changed files with 628 additions and 487 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@

<link rel="stylesheet" href="{% static 'apcd-cms/css/table.css' %}">
<link rel="stylesheet" href="{% static 'apcd-cms/css/modal.css' %}">
<link rel="stylesheet" href="{% static 'submissions/css/table.css' %}">
<link rel="stylesheet" href="{% static 'submissions/css/modal.css' %}">
<link rel="stylesheet" href="{% static 'admin_submissions/css/admin_table.css' %}">
<link rel="stylesheet" href="{% static 'admin_regis_table/css/table.css' %}">

<div class="container">
{% include "nav_cms_breadcrumbs.html" %}

<h1>View Submissions</h1>
<hr />
<p style="margin-bottom: 30px">All completed submissions by organizations</p>
<hr />
<div id="list-admin-submissions"></div>
</div>
{% endblock %}
6 changes: 2 additions & 4 deletions apcd-cms/src/apps/admin_submissions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
app_name = 'administration'
urlpatterns = [
path('list-submissions/', TemplateView.as_view(template_name='list_admin_submissions.html'), name="admin_submissions"),
path(r'list-submissions/api/', AdminSubmissionsTable.as_view(), name="admin_submissions_api"),
path(r'list-submissions/api/?status=(?P<status>)/', AdminSubmissionsTable.as_view(), name="admin_submissions_api"),
path(r'list-submissions/api/?sort=(?P<sort>)/', AdminSubmissionsTable.as_view(), name="admin_submissions_api"),
path(r'list-submissions/api/?sort=(?P<sort>)&filter=(?P<status>)/', AdminSubmissionsTable.as_view(), name="admin_submissions_api"),
path('list-submissions/api/', AdminSubmissionsTable.as_view(), name="admin_submissions_api"),
path('list-submissions/api/options', AdminSubmissionsTable.as_view(), name='admin_submissions_api_options'),
]
156 changes: 79 additions & 77 deletions apcd-cms/src/apps/admin_submissions/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.http import HttpResponseRedirect, JsonResponse
from django.core.paginator import Paginator
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, table_filter
from apps.components.paginator.paginator import paginator
from apps.utils.utils import title_case
import logging
from dateutil import parser

Expand All @@ -12,86 +12,88 @@
class AdminSubmissionsTable(TemplateView):

template_name = 'list_admin_submissions.html'

def get(self, request, *args, **kwargs):
submission_content = get_all_submissions_and_logs()
context = self.get_submission_list_json(submission_content, *args, **kwargs)

return JsonResponse({'response': context})


def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated or not is_apcd_admin(request.user):
return HttpResponseRedirect('/')
return super(AdminSubmissionsTable, self).dispatch(request, *args, **kwargs)

def get(self, request, *args, **kwargs):
if 'options' in request.path:
return self.get_options(request)

status = request.GET.get('status', 'All')
sort = request.GET.get('sort', 'Newest Received')
page_number = int(request.GET.get('page', 1))
items_per_page = int(request.GET.get('limit', 50))
try:
submission_content = get_all_submissions_and_logs()
filtered_submissions = self.filtered_submissions(submission_content, status, sort)

paginator = Paginator(filtered_submissions, items_per_page)
page_info = paginator.get_page(page_number)

context= self.get_view_submissions_json(list(page_info), selected_status=status, selected_sort=sort)
context['page_num'] = page_info.number
context['total_pages'] = paginator.num_pages
return JsonResponse({'response': context})
except Exception as e:
logger.error("Error fetching filtered user data: %s", e)
return JsonResponse({'error': str(e)}, status=500)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update(self.get_view_submissions_json(get_all_submissions_and_logs()))
return context

def get_submission_list_json(self, submission_content, *args, **kwargs):

context = {}
queryStr = ''
dateSort = self.request.GET.get('sort')
status_filter = self.request.GET.get('status')

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
queryStr += f'&sort={dateSort}'
submission_content = sorted(submission_content, key=lambda row:getDate(row), reverse=(dateSort == 'newDate'))

def get_options(self, request):
try:
page_num = int(self.request.GET.get('page'))
except:
page_num = 1

context['selected_status'] = 'All'
if status_filter is not None and status_filter != 'All':
context['selected_status'] = status_filter
queryStr += f'&status={status_filter}'
submission_content = table_filter(status_filter, submission_content, 'status')

limit = 50
offset = limit * (page_num - 1)

# modifies the object fields for display, only modifies a subset of entries that will be displayed
# on the current page using offset and limit
for s in submission_content[offset:offset + limit]:
s['status'] = title_case(s['status'])
s['entity_name'] = title_case(s['entity_name'])
s['outcome'] = title_case(s['outcome'])
s['received_timestamp'] = parser.parse(s['received_timestamp']) if s['received_timestamp'] else None
s['updated_at'] = parser.parse(s['updated_at']) if s['updated_at'] else None
s['view_modal_content'] = [{
**t,
'outcome': title_case(t['outcome'])
} for t in (s['view_modal_content'] or [])]

context['header'] = ['Received', 'Entity Organization', 'File Name', 'Outcome', 'Status', 'Last Updated', 'Actions']
context['status_options'] = ['All', 'In Process', 'Complete']
context['sort_options'] = [
{'name': '', 'value': ''},
{'name': 'Newest Received', 'value': 'newDate'},
{'name': 'Oldest Received', 'value': 'oldDate'}
]

context['query_str'] = queryStr
page_info = paginator(self.request, submission_content, limit)

context['page'] = [{
'submission_id': obj['submission_id'],
'status': obj['status'],
'entity_name': obj['entity_name'],
'file_name': obj['file_name'],
'outcome': obj['outcome'],
'received_timestamp': obj['received_timestamp'],
'updated_at': obj['updated_at'],
'view_modal_content': obj['view_modal_content'],
} for obj in page_info['page']]

context['page_num'] = page_num
context['total_pages'] = page_info['page'].paginator.num_pages
status_options = ['All', 'In Process', 'Complete']
sort_options = [ {'name': 'Newest Received', 'value': 'newDate'},
{'name': 'Oldest Received', 'value': 'oldDate'}]

return JsonResponse({
'status_options': status_options,
'sort_options': sort_options,
})
except Exception as e:
logger.error("Error fetching options data: %s", e)
return JsonResponse({'error': str(e)}, status=500)

def filtered_submissions(self, submission_content, status, sort):
def getDate(submission):
date = submission['received_timestamp']
return parser.parse(date) if date is not None else parser.parse('1-1-3005')
submission_list = sorted(
submission_content,
key=lambda row: getDate(row),
reverse=(sort == 'Newest Received')
)
if status != 'All':
submission_list = [submission for submission in submission_content
if submission['status'].lower() == status.lower()]

return submission_list
def get_view_submissions_json(self, submission_content, selected_status='All', selected_sort='Newest Received'):
context = {
'page': [],
'selected_status': selected_status,
'selected_sort': selected_sort,
'pagination_url_namespaces':'admin_submission:admin_submissions'
}

def _set_submissions(submission):
return {
'submission_id': submission['submission_id'],
'status': submission['status'],
'entity_name': submission['entity_name'],
'file_name': submission['file_name'],
'outcome': title_case(submission['outcome']) if submission['outcome'] else None,
'received_timestamp': submission['received_timestamp'],
'updated_at': submission['updated_at'],
'view_modal_content': submission['view_modal_content'],
}
for submission in submission_content:
context['page'].append(_set_submissions(submission))

context['pagination_url_namespaces'] = 'admin_submission:admin_submissions'
return context

6 changes: 2 additions & 4 deletions apcd-cms/src/apps/submissions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
app_name = 'submissions'
urlpatterns = [
path('list-submissions/', TemplateView.as_view(template_name='list_submissions.html'), name="list_submissions"),
path(r'list-submissions/api/', SubmissionsTable.as_view(), name="list_submissions_api"),
path(r'list-submissions/api/?status=(?P<status>)/', SubmissionsTable.as_view(), name="list_submissions_api"),
path(r'list-submissions/api/?sort=(?P<sort>)/', SubmissionsTable.as_view(), name="list_submissions_api"),
path(r'list-submissions/api/?sort=(?P<sort>)&filter=(?P<status>)/', SubmissionsTable.as_view(), name="list_submissions_api"),
path('list-submissions/api/', SubmissionsTable.as_view(), name="list_submissions_api"),
path('list-submissions/api/options', SubmissionsTable.as_view(), name="list_submissions_api_options")
]
Loading

0 comments on commit 1d12a43

Please sign in to comment.