Skip to content
Snippets Groups Projects
Commit 3b1bbb91 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Introduce API for constraint violations (protected and currently readonly)

This also introduces some additional properties for human readable details of the violations to the model
parent 0a2794b5
No related branches found
No related tags found
2 merge requests!100Scheduling Constraints WIP WIP WIP,!99Constraint Violation checking & visualization
......@@ -480,5 +480,21 @@ class ConstraintViolation(models.Model):
get_details.short_description = _('Details')
@property
def details(self):
return self.get_details()
@property
def level_display(self):
return self.get_level_display()
@property
def type_display(self):
return self.get_type_display()
@property
def timestamp_display(self):
return self.timestamp.astimezone(self.event.timezone).strftime('%d.%m.%y %H:%M')
def __str__(self):
return f"{self.get_level_display()}: {self.get_type_display()} [{self.get_details()}]"
......@@ -17,10 +17,12 @@ api_router.register('akslot', views.AKSlotViewSet, basename='AKSlot')
extra_paths = []
if apps.is_installed("AKScheduling"):
from AKScheduling.api import ResourcesViewSet, RoomAvailabilitiesView, EventsView, EventsViewSet
from AKScheduling.api import ResourcesViewSet, RoomAvailabilitiesView, EventsView, EventsViewSet, \
ConstraintViolationsViewSet
api_router.register('scheduling-resources', ResourcesViewSet, basename='scheduling-resources')
api_router.register('scheduling-event', EventsViewSet, basename='scheduling-event')
api_router.register('scheduling-constraint-violations', ConstraintViolationsViewSet, basename='scheduling-constraint-violations')
extra_paths = [
path('api/scheduling-events/', EventsView.as_view(), name='scheduling-events'),
......
......@@ -7,7 +7,7 @@ from django.views.generic import ListView
from rest_framework import viewsets, mixins, serializers, permissions
from AKModel.availability.models import Availability
from AKModel.models import Room, AKSlot
from AKModel.models import Room, AKSlot, ConstraintViolation
from AKModel.views import EventSlugMixin
......@@ -109,3 +109,20 @@ class EventsViewSet(EventSlugMixin, viewsets.ModelViewSet):
def get_queryset(self):
return AKSlot.objects.filter(event=self.event)
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']
class ConstraintViolationsViewSet(EventSlugMixin, viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
serializer_class = ConstraintViolationSerializer
def get_object(self):
return get_object_or_404(ConstraintViolation, pk=self.kwargs["pk"])
def get_queryset(self):
return ConstraintViolation.objects.filter(event=self.event)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment