diff --git a/helpdesk/apps.py b/helpdesk/apps.py index de9d8537..d316d314 100644 --- a/helpdesk/apps.py +++ b/helpdesk/apps.py @@ -11,7 +11,3 @@ class HelpdeskConfig(AppConfig): def ready(self): from . import webhooks # noqa: F401 - - from django.db.models.fields import Field - from helpdesk.orm_operators import NotIn - Field.register_lookup(NotIn) diff --git a/helpdesk/orm_operators.py b/helpdesk/orm_operators.py deleted file mode 100644 index 46c26ff3..00000000 --- a/helpdesk/orm_operators.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.db.models.lookups import In - -class NotIn(In): - lookup_name = "not_in" - - def get_rhs_op(self, connection, rhs): - return "NOT IN %s" % rhs diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index d78d342a..fc82263a 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -20,7 +20,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied from django.core.handlers.wsgi import WSGIRequest from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator -from django.db.models import Q +from django.db.models import Q, Case, Value, When from django.forms import HiddenInput, inlineformset_factory, TextInput from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import get_object_or_404, redirect, render @@ -423,9 +423,12 @@ def view_ticket(request, ticket_id): return redirect('helpdesk:edit_ticket_checklist', ticket.id, checklist.id) - # Open tickets on top - dependencies = list(ticket.ticketdependency.filter(depends_on__status__in=Ticket.OPEN_STATUSES)) \ - + list(ticket.ticketdependency.filter(depends_on__status__not_in=Ticket.OPEN_STATUSES)) + # List open tickets on top + dependencies = ticket.ticketdependency.annotate( + rank=Case( + When(depends_on__status__in=Ticket.OPEN_STATUSES, then=Value('1')), + default=Value('2') + )).order_by('rank') return render(request, 'helpdesk/ticket.html', { 'ticket': ticket,