previousDepartureFeedback.py 1.4 KB
Newer Older
1
2
3
from django.db import models
from django.core.validators import MaxValueValidator

4
from backend.models.user import UserRestrictedModule, UserRestrictedModuleSerializer, UserRestrictedModuleViewSet
5
from backend.models.user import PreviousDeparture
6
from backend.fields import JSONField
Florent Chehab's avatar
Florent Chehab committed
7
from backend.utils import get_model_config, get_viewset_permissions
8
9
10


class PreviousDepartureFeedback(UserRestrictedModule):
Florent Chehab's avatar
Florent Chehab committed
11
    model_config = get_model_config("Country")
12
13
14
    departure = models.OneToOneField(
        PreviousDeparture, on_delete=models.CASCADE)

Florent Chehab's avatar
Florent Chehab committed
15
    courses_and_courses_feedback = JSONField(default=dict)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    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__'


32
class PreviousDepartureFeedbackViewSet(UserRestrictedModuleViewSet):
33
34
    permission_classes = get_viewset_permissions(
        "PreviousDepartureFeedbackViewSet")
35
36
    queryset = PreviousDepartureFeedback.objects.all()  # pylint: disable=E1101
    serializer_class = PreviousDepartureFeedbackSerializer