initial commit

staff.py changes:
import django core paginator libs
get user setting for tickets per page
get http GET variables for page selection on three tables
use django paginator to get current page tickets only, and pass those to dashboard.html instead of all tickets

dashboard.html changes:
assign the correct HTTP GET argument to each table

tickets.html changes:
add pagination controls below table div, and pass HTTP GET args back to the URL when clicked
This commit is contained in:
Tom Bernens 2020-06-01 16:14:55 -07:00
parent 2041430cd3
commit 03760a921e
3 changed files with 72 additions and 3 deletions

View File

@ -16,18 +16,21 @@
{% if all_tickets_reported_by_current_user %}
{% trans "All Tickets submitted by you" as ticket_list_caption %}
{% include 'helpdesk/include/tickets.html' with ticket_list=all_tickets_reported_by_current_user ticket_list_empty_message="" %}
{% trans "atrbcu_page" as page_var}
{% include 'helpdesk/include/tickets.html' with ticket_list=all_tickets_reported_by_current_user ticket_list_empty_message="" page_var=page_var %}
{% endif %}
{% trans "Open Tickets assigned to you (you are working on this ticket)" as ticket_list_caption %}
{% trans "You have no tickets assigned to you." as no_assigned_tickets %}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets ticket_list_empty_message=no_assigned_tickets %}
{% trans "ut_page" as page_var}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets ticket_list_empty_message=no_assigned_tickets page_var=page_var %}
{% include 'helpdesk/include/unassigned.html' %}
{% if user_tickets_closed_resolved %}
{% trans "Closed & resolved Tickets you used to work on" as ticket_list_caption %}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets_closed_resolved ticket_list_empty_message="" %}
{% trans "utcr_page" as page_var}
{% include 'helpdesk/include/tickets.html' with ticket_list=user_tickets_closed_resolved ticket_list_empty_message="" page_var=page_var %}
{% endif %}
{% endblock %}

View File

@ -37,6 +37,27 @@
</table>
</div>
<!-- /.table-responsive -->
{% if ticket_list.has_other_pages %}
<ul class="pagination">
{% if ticket_list.has_previous %}
<li><a href="?{{ page_var }}={{ ticket_list.previous_page_number }}">&laquo;</a></li>
{% else %}
<li class="disabled"><span>&laquo;</span></li>
{% endif %}
{% for i in ticket_list.paginator.page_range %}
{% if ticket_list.number == i %}
<li class="active"><span>{{ i }} <span class="sr-only">(current)</span></span></li>
{% else %}
<li><a href="?{{ page_var }}={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %}
{% if ticket_list.has_next %}
<li><a href="?{{ page_var }}={{ ticket_list.next_page_number }}">&raquo;</a></li>
{% else %}
<li class="disabled"><span>&raquo;</span></li>
{% endif %}
</ul>
{% endif %}
</div>
<!-- /.panel-body -->
</div>

View File

@ -15,6 +15,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.core.exceptions import ValidationError, PermissionDenied
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Q
from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.shortcuts import render, get_object_or_404
@ -91,6 +92,15 @@ def dashboard(request):
showing ticket counts by queue/status, and a list of unassigned tickets
with options for them to 'Take' ownership of said tickets.
"""
# user settings num tickets per page
tickets_per_page = request.user.usersettings_helpdesk.tickets_per_page
# page vars for the three ticket tables
user_tickets_page = request.GET.get('ut_page', 1)
user_tickets_closed_resolved_page = request.GET.get('utcr_page', 1)
all_tickets_reported_by_current_user_page = request.GET.get('atrbcu_page', 1)
# open & reopened tickets, assigned to current user
tickets = Ticket.objects.select_related('queue').filter(
assigned_to=request.user,
@ -141,6 +151,41 @@ def dashboard(request):
else:
where_clause = """WHERE q.id = t.queue_id"""
# get user assigned tickets page
paginator = Paginator(
tickets, tickets_per_page)
try:
tickets = paginator.page(user_tickets_page)
except PageNotAnInteger:
tickets = paginator.page(1)
except EmptyPage:
tickets = paginator.page(
paginator.num_pages)
# get user completed tickets page
paginator = Paginator(
tickets_closed_resolved, tickets_per_page)
try:
tickets_closed_resolved = paginator.page(
user_tickets_closed_resolved_page)
except PageNotAnInteger:
tickets_closed_resolved = paginator.page(1)
except EmptyPage:
tickets_closed_resolved = paginator.page(
paginator.num_pages)
# get user submitted tickets page
paginator = Paginator(
all_tickets_reported_by_current_user, tickets_per_page)
try:
all_tickets_reported_by_current_user = paginator.page(
all_tickets_reported_by_current_user_page)
except PageNotAnInteger:
all_tickets_reported_by_current_user = paginator.page(1)
except EmptyPage:
all_tickets_reported_by_current_user = paginator.page(
paginator.num_pages)
return render(request, 'helpdesk/dashboard.html', {
'user_tickets': tickets,
'user_tickets_closed_resolved': tickets_closed_resolved,