From f127b2c224969827365a88e2ff65bac78da56b5f Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Tue, 8 Oct 2019 15:35:07 +0200 Subject: [PATCH 1/7] Refactor ticket list --- helpdesk/views/staff.py | 66 ++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index f148eca1..6f882faa 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -6,6 +6,8 @@ django-helpdesk - A Django powered ticket tracker for small enterprise. views/staff.py - The bulk of the application - provides most business logic and renders all staff-facing views. """ +from copy import deepcopy + from django import VERSION as DJANGO_VERSION from django.conf import settings from django.contrib.auth import get_user_model @@ -840,6 +842,10 @@ def ticket_list(request): 'keyword': None, 'search_string': None, } + default_query_params = { + 'filtering': {'status__in': [1, 2, 3]}, + 'sorting': 'created', + } from_saved_query = False @@ -898,46 +904,25 @@ def ticket_list(request): # Query deserialization failed. (E.g. was a pickled query) return HttpResponseRedirect(reverse('helpdesk:list')) - elif not ('queue' in request.GET or - 'assigned_to' in request.GET or - 'status' in request.GET or - 'q' in request.GET or - 'sort' in request.GET or - 'sortreverse' in request.GET): - - # Fall-back if no querying is being done, force the list to only - # show open/reopened/resolved (not closed) cases sorted by creation - # date. - + elif not {'queue', 'assigned_to', 'status', 'q', 'sort', 'sortreverse'}.intersection(request.GET): + # Fall-back if no querying is being done all_queues = Queue.objects.all() - query_params = { - 'filtering': {'status__in': [1, 2, 3]}, - 'sorting': 'created', - } + query_params = deepcopy(default_query_params) else: - queues = request.GET.getlist('queue') - if queues: - try: - queues = [int(q) for q in queues] - query_params['filtering']['queue__id__in'] = queues - except ValueError: - pass + filter_in_params = [ + ('queue', 'queue__id__in'), + ('assigned_to', 'assigned_to__id__in'), + ('status', 'status__in'), + ] - owners = request.GET.getlist('assigned_to') - if owners: - try: - owners = [int(u) for u in owners] - query_params['filtering']['assigned_to__id__in'] = owners - except ValueError: - pass - - statuses = request.GET.getlist('status') - if statuses: - try: - statuses = [int(s) for s in statuses] - query_params['filtering']['status__in'] = statuses - except ValueError: - pass + for param, filter_command in filter_in_params: + patterns = request.GET.getlist(param) + if patterns: + try: + pattern_pks = [int(pattern) for pattern in patterns] + query_params['filtering'][filter_command] = pattern_pks + except ValueError: + pass date_from = request.GET.get('date_from') if date_from: @@ -969,11 +954,7 @@ def ticket_list(request): ticket_qs = apply_query(tickets, query_params) except ValidationError: # invalid parameters in query, return default query - query_params = { - 'filtering': {'status__in': [1, 2, 3]}, - 'sorting': 'created', - } - ticket_qs = apply_query(tickets, query_params) + ticket_qs = apply_query(tickets, default_query_params) search_message = '' if 'query' in context and settings.DATABASES['default']['ENGINE'].endswith('sqlite'): @@ -1001,7 +982,6 @@ def ticket_list(request): return render(request, 'helpdesk/ticket_list.html', dict( context, - tickets=ticket_qs, default_tickets_per_page=request.user.usersettings_helpdesk.tickets_per_page, user_choices=User.objects.filter(is_active=True, is_staff=True), queue_choices=user_queues, From b862732512f091a57367bbedbeef2c5a36d3ca5b Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Tue, 8 Oct 2019 17:00:57 +0200 Subject: [PATCH 2/7] Remove "classic" code path and always use datatables for ticket lists --- demo/demodesk/config/settings.py | 3 - docs/settings.rst | 5 - helpdesk/settings.py | 4 - helpdesk/templates/helpdesk/ticket_list.html | 248 +++++++++---------- helpdesk/views/staff.py | 9 +- 5 files changed, 119 insertions(+), 150 deletions(-) diff --git a/demo/demodesk/config/settings.py b/demo/demodesk/config/settings.py index b672dfc4..e1ac8106 100644 --- a/demo/demodesk/config/settings.py +++ b/demo/demodesk/config/settings.py @@ -106,9 +106,6 @@ HELPDESK_REDIRECT_TO_LOGIN_BY_DEFAULT = False LOGIN_URL = '/login/' LOGIN_REDIRECT_URL = '/login/' -# Turn off server-side processing for this local demo -HELPDESK_USE_SERVERSIDE_PROCESSING = False - # Database # - by default, we use SQLite3 for the demo, but you can also # configure MySQL or PostgreSQL, see the docs for more: diff --git a/docs/settings.rst b/docs/settings.rst index 72792849..0502f0e2 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -90,11 +90,6 @@ These changes are visible throughout django-helpdesk **Default:** ``HELPDESK_ANON_ACCESS_RAISES_404 = False`` -- **HELPDESK_USE_SERVERSIDE_PROCESSING** If True, may improve performance by utilizing server-side processing of the full ticket list whenever performing queries on the ticket list. Set to False to restore the "classic" functionality using javascript. - - **Default:** ``HELPDESK_USE_SERVERSIDE_PROCESSING = True`` - - Options shown on public pages ----------------------------- diff --git a/helpdesk/settings.py b/helpdesk/settings.py index 7142ce18..32afacc6 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -151,7 +151,3 @@ HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION = getattr( # use https in the email links HELPDESK_USE_HTTPS_IN_EMAIL_LINK = getattr(settings, 'HELPDESK_USE_HTTPS_IN_EMAIL_LINK', False) - -# Asynchronous Datatables - Optional -HELPDESK_USE_SERVERSIDE_PROCESSING = getattr( - settings, 'HELPDESK_USE_SERVERSIDE_PROCESSING', True) diff --git a/helpdesk/templates/helpdesk/ticket_list.html b/helpdesk/templates/helpdesk/ticket_list.html index 0da85099..3a3a0b20 100644 --- a/helpdesk/templates/helpdesk/ticket_list.html +++ b/helpdesk/templates/helpdesk/ticket_list.html @@ -185,9 +185,6 @@ {% trans "Time Spent" %} - {% if not server_side %} - {% include 'helpdesk/ticket_list_table.html' %} - {% endif %}

@@ -229,135 +226,126 @@ {% block helpdesk_js %}