Skip to content
Snippets Groups Projects
Commit 560ccb4a authored by Benjamin Hättasch's avatar Benjamin Hättasch Committed by Nadja Geisler
Browse files

Add edit button to constraint violation view

This includes returning the edit url as part of the (internal) API response
parent 4ee689a8
No related branches found
No related tags found
1 merge request!117Hide blank fields in string representation of ConstraintViolation and add edit link for each violation on constraint violation overview
Pipeline #81894 failed
...@@ -2,6 +2,7 @@ import itertools ...@@ -2,6 +2,7 @@ import itertools
from datetime import timedelta from datetime import timedelta
from django.db import models from django.db import models
from django.urls import reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.utils.datetime_safe import datetime from django.utils.datetime_safe import datetime
from django.utils.text import slugify from django.utils.text import slugify
...@@ -539,6 +540,10 @@ class ConstraintViolation(models.Model): ...@@ -539,6 +540,10 @@ class ConstraintViolation(models.Model):
def details(self): def details(self):
return self.get_details() return self.get_details()
@property
def edit_url(self):
return reverse_lazy('admin:AKModel_constraintviolation_change', kwargs={'object_id': self.pk})
@property @property
def level_display(self): def level_display(self):
return self.get_level_display() return self.get_level_display()
......
...@@ -114,7 +114,7 @@ class EventsViewSet(EventSlugMixin, viewsets.ModelViewSet): ...@@ -114,7 +114,7 @@ class EventsViewSet(EventSlugMixin, viewsets.ModelViewSet):
class ConstraintViolationSerializer(serializers.ModelSerializer): class ConstraintViolationSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = ConstraintViolation 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): class ConstraintViolationsViewSet(EventSlugMixin, viewsets.ModelViewSet):
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
// Update violations table // Update violations table
for(let i=0;i<response.length;i++) { 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 { else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment