From 404e160f057e6eeb926db17940f3d23baff0e3f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?=
 <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de>
Date: Thu, 27 Feb 2025 00:34:09 +0100
Subject: [PATCH] Scheduler: Show conflicts in AK details in both directions

Find conflicts that this AK specifies and those AKs where this AK was specified
Deduplicate and order list alphabetically
This implements #223
---
 AKModel/models.py     | 16 +++++++++++++++-
 AKScheduling/views.py |  2 +-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/AKModel/models.py b/AKModel/models.py
index 0890e536..26ed0f21 100644
--- a/AKModel/models.py
+++ b/AKModel/models.py
@@ -408,8 +408,22 @@ class AK(models.Model):
             detail_string += f"\n{_('Requirements')}: {', '.join(str(r) for r in self.requirements.all())}"
         if self.types.count() > 0:
             detail_string += f"\n{_('Types')}: {', '.join(str(r) for r in self.types.all())}"
+
+        # Find conflicts
+        # (both directions, those specified for this AK and those were this AK was specified as conflict)
+        # Deduplicate and order list alphabetically
+        conflicts = set()
         if self.conflicts.count() > 0:
-            detail_string += f"\n{_('Conflicts')}: {', '.join(str(c) for c in self.conflicts.all())}"
+            for c in self.conflicts.all():
+                conflicts.add(str(c))
+        if self.conflict.count() > 0:
+            for c in self.conflict.all():
+                conflicts.add(str(c))
+        if len(conflicts) > 0:
+            conflicts = list(conflicts)
+            conflicts.sort()
+            detail_string += f"\n{_('Conflicts')}: {', '.join(conflicts)}"
+
         if self.prerequisites.count() > 0:
             detail_string += f"\n{_('Prerequisites')}: {', '.join(str(p) for p in self.prerequisites.all())}"
         detail_string += f"\n{_('Availabilities')}: \n{availabilities}"
diff --git a/AKScheduling/views.py b/AKScheduling/views.py
index 2e549f9f..d7533f3d 100644
--- a/AKScheduling/views.py
+++ b/AKScheduling/views.py
@@ -43,7 +43,7 @@ class SchedulingAdminView(AdminViewMixin, FilterByEventSlugMixin, ListView):
     def get_queryset(self):
         return super().get_queryset().filter(start__isnull=True).select_related('event', 'ak', 'ak__track',
             'ak__category').prefetch_related('ak__types', 'ak__owners', 'ak__conflicts', 'ak__prerequisites',
-            'ak__requirements').order_by('ak__track', 'ak')
+            'ak__requirements', 'ak__conflict').order_by('ak__track', 'ak')
 
     def get_context_data(self, *, object_list=None, **kwargs):
         context = super().get_context_data(object_list=object_list, **kwargs)
-- 
GitLab