Removed unused dash_tickets variable and its calculation, modified the

case where it is used to rely on model query APIs rather than on raw
queries that use the default database and are not forwarded by routers.
This commit is contained in:
Andrii Iudin 2018-03-26 13:46:07 +01:00
parent fef08082de
commit 764c55e60e

View File

@ -151,21 +151,6 @@ def dashboard(request):
else: else:
where_clause = """WHERE q.id = t.queue_id""" where_clause = """WHERE q.id = t.queue_id"""
cursor = connection.cursor()
cursor.execute("""
SELECT q.id as queue,
q.title AS name,
COUNT(CASE t.status WHEN '1' THEN t.id WHEN '2' THEN t.id END) AS open,
COUNT(CASE t.status WHEN '3' THEN t.id END) AS resolved,
COUNT(CASE t.status WHEN '4' THEN t.id END) AS closed
%s
%s
GROUP BY queue, name
ORDER BY q.id;
""" % (from_clause, where_clause))
dash_tickets = query_to_dict(cursor.fetchall(), cursor.description)
return render(request, 'helpdesk/dashboard.html', { return render(request, 'helpdesk/dashboard.html', {
'user_tickets': tickets, 'user_tickets': tickets,
'user_tickets_closed_resolved': tickets_closed_resolved, 'user_tickets_closed_resolved': tickets_closed_resolved,
@ -1103,31 +1088,18 @@ def report_index(request):
# Open Resolved # Open Resolved
# Queue 1 10 4 # Queue 1 10 4
# Queue 2 4 12 # Queue 2 4 12
Queues = user_queues if user_queues else Queue.objects.all()
queues = _get_user_queues(request.user).values_list('id', flat=True) dash_tickets = []
for queue in Queues:
from_clause = """FROM helpdesk_ticket t, dash_ticket = {
helpdesk_queue q""" 'queue': queue.id,
if queues: 'name': queue.title,
where_clause = """WHERE q.id = t.queue_id AND 'open': queue.ticket_set.filter(status__in=[1, 2]).count(),
q.id IN (%s)""" % (",".join(("%d" % pk for pk in queues))) 'resolved': queue.ticket_set.filter(status=3).count(),
else: 'closed': queue.ticket_set.filter(status=4).count(),
where_clause = """WHERE q.id = t.queue_id""" }
dash_tickets.append(dash_ticket)
cursor = connection.cursor()
cursor.execute("""
SELECT q.id as queue,
q.title AS name,
COUNT(CASE t.status WHEN '1' THEN t.id WHEN '2' THEN t.id END) AS open,
COUNT(CASE t.status WHEN '3' THEN t.id END) AS resolved,
COUNT(CASE t.status WHEN '4' THEN t.id END) AS closed
%s
%s
GROUP BY queue, name
ORDER BY q.id;
""" % (from_clause, where_clause))
dash_tickets = query_to_dict(cursor.fetchall(), cursor.description)
return render(request, 'helpdesk/report_index.html', { return render(request, 'helpdesk/report_index.html', {
'number_tickets': number_tickets, 'number_tickets': number_tickets,