mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-21 15:33:09 +01:00
Rewrite dependency tickets ordering, using Case annotation
This commit is contained in:
parent
ec603347c7
commit
54864b2c1e
@ -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)
|
||||
|
@ -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
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user