previousDepartureFeedback.py 1.28 KB
Newer Older
1
2
3
4
from django.db import models
from rest_framework import viewsets, permissions
from django.core.validators import MaxValueValidator

5
6
from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerializer
from backend.models.user import PreviousDeparture
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from django.contrib.postgres.fields import JSONField


class PreviousDepartureFeedback(UserRestrictedModule):
    departure = models.OneToOneField(
        PreviousDeparture, on_delete=models.CASCADE)

    courses_and_courses_feedback = JSONField(null=True)
    adequation_comment = models.TextField()
    integration_comment = models.TextField()
    adequation_grate = models.PositiveIntegerField(
        validators=[MaxValueValidator(20)])
    integration_grade = models.PositiveIntegerField(
        validators=[MaxValueValidator(20)])
    # TODO check on save that courses are coherent with Previous Departure


class PreviousDepartureFeedbackSerializer(UserRestrictedModuleSerializer):

    class Meta:
        model = PreviousDepartureFeedback
        fields = '__all__'


class PreviousDepartureFeedbackViewSet(viewsets.ModelViewSet):
    permission_classes = (permissions.DjangoModelPermissions,)
    queryset = PreviousDepartureFeedback.objects.all()  # pylint: disable=E1101
    serializer_class = PreviousDepartureFeedbackSerializer