Order dependend ticket with NotIn ORM operator instead of itertools

This commit is contained in:
Georg Lehner 2024-06-08 12:00:43 +02:00
parent 887483a6d6
commit b52ab69c42
3 changed files with 14 additions and 5 deletions

View File

@ -11,3 +11,7 @@ class HelpdeskConfig(AppConfig):
def ready(self): def ready(self):
from . import webhooks # noqa: F401 from . import webhooks # noqa: F401
from django.db.models.fields import Field
from helpdesk.orm_operators import NotIn
Field.register_lookup(NotIn)

View File

@ -0,0 +1,7 @@
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

View File

@ -424,11 +424,9 @@ def view_ticket(request, ticket_id):
return redirect('helpdesk:edit_ticket_checklist', ticket.id, checklist.id) return redirect('helpdesk:edit_ticket_checklist', ticket.id, checklist.id)
open_dependencies = ticket.ticketdependency.filter(depends_on__status__in=Ticket.OPEN_STATUSES) # Open tickets on top
dependencies = [d for d in itertools.chain( dependencies = list(ticket.ticketdependency.filter(depends_on__status__in=Ticket.OPEN_STATUSES)) \
open_dependencies, + list(ticket.ticketdependency.filter(depends_on__status__not_in=Ticket.OPEN_STATUSES))
ticket.ticketdependency.all().difference(open_dependencies)
)]
return render(request, 'helpdesk/ticket.html', { return render(request, 'helpdesk/ticket.html', {
'ticket': ticket, 'ticket': ticket,