From 4ee689a802f9f3397e98bf4d131b575b37ffb09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Thu, 19 May 2022 19:46:14 +0200 Subject: [PATCH 1/2] Hide blank fields in string representation of ConstraintViolation This fixes #130 --- AKModel/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AKModel/models.py b/AKModel/models.py index 979f005f..6d17aab9 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -529,7 +529,7 @@ class ConstraintViolation(models.Model): # Stringify all other fields for field in self.fields: a = getattr(self, field, None) - if a is not None: + if a is not None and str(a) != '': output.append(f"{field}: {a}") return ", ".join(output) -- GitLab From 560ccb4a26d5965dcdbdc3e67242d896dae2bf6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Thu, 19 May 2022 20:01:15 +0200 Subject: [PATCH 2/2] Add edit button to constraint violation view This includes returning the edit url as part of the (internal) API response --- AKModel/models.py | 5 +++++ AKScheduling/api.py | 2 +- .../templates/admin/AKScheduling/constraint_violations.html | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AKModel/models.py b/AKModel/models.py index 6d17aab9..5c359610 100644 --- a/AKModel/models.py +++ b/AKModel/models.py @@ -2,6 +2,7 @@ import itertools from datetime import timedelta from django.db import models +from django.urls import reverse_lazy from django.utils import timezone from django.utils.datetime_safe import datetime from django.utils.text import slugify @@ -539,6 +540,10 @@ class ConstraintViolation(models.Model): def details(self): return self.get_details() + @property + def edit_url(self): + return reverse_lazy('admin:AKModel_constraintviolation_change', kwargs={'object_id': self.pk}) + @property def level_display(self): return self.get_level_display() diff --git a/AKScheduling/api.py b/AKScheduling/api.py index b7ab7fbd..2e065b46 100644 --- a/AKScheduling/api.py +++ b/AKScheduling/api.py @@ -114,7 +114,7 @@ class EventsViewSet(EventSlugMixin, viewsets.ModelViewSet): class ConstraintViolationSerializer(serializers.ModelSerializer): class Meta: model = ConstraintViolation - fields = ['pk', 'type_display', 'aks', 'ak_slots', 'ak_owner', 'room', 'requirement', 'category', 'comment', 'timestamp_display', 'manually_resolved', 'level_display', 'details'] + fields = ['pk', 'type_display', 'aks', 'ak_slots', 'ak_owner', 'room', 'requirement', 'category', 'comment', 'timestamp_display', 'manually_resolved', 'level_display', 'details', 'edit_url'] class ConstraintViolationsViewSet(EventSlugMixin, viewsets.ModelViewSet): diff --git a/AKScheduling/templates/admin/AKScheduling/constraint_violations.html b/AKScheduling/templates/admin/AKScheduling/constraint_violations.html index 8645c192..c987f311 100644 --- a/AKScheduling/templates/admin/AKScheduling/constraint_violations.html +++ b/AKScheduling/templates/admin/AKScheduling/constraint_violations.html @@ -63,7 +63,7 @@ // Update violations table for(let i=0;i<response.length;i++) { - table_html += "<tr><td>" + response[i].level_display + "</td><td>" + response[i].type_display + "</td><td>" + response[i].details + "</td><td>" + response[i].timestamp_display + "</td><td></td></tr>"; + table_html += "<tr><td>" + response[i].level_display + "</td><td>" + response[i].type_display + "</td><td>" + response[i].details + "</td><td class='nowrap'>" + response[i].timestamp_display + "</td><td><a href='" + response[i].edit_url + "'><i class='btn btn-primary fa fa-pen'></i></a></td></tr>"; } } else { -- GitLab