previousDeparture.py 1.58 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
Florent Chehab's avatar
Florent Chehab committed
2
3
from backend.models.other_core.specialty import Specialty
from backend.models.other_core.semester import Semester
4
from backend.models.university import University
5
from django.contrib.auth.models import User
6
7
from backend.fields import JSONField
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
Florent Chehab's avatar
Florent Chehab committed
8
from backend.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
9
10


11
class PreviousDeparture(MyModel):
Florent Chehab's avatar
Florent Chehab committed
12
    model_config = get_model_config("PreviousDeparture")
13
    # This model should be filled with data from the ENT
Florent Chehab's avatar
Florent Chehab committed
14
15
16
    semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
    university = models.ForeignKey(University, on_delete=models.PROTECT)
    specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT)
17
18
19
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    # Usefull to relink a departure with a user
    Utc_departure_id = models.IntegerField()
Florent Chehab's avatar
Florent Chehab committed
20

21
22
23
24
    is_anonymous = models.BooleanField()
    courses = JSONField(null=True)  # Store data from ENT
    # TODO ask the DSI to return an anonymous ID with data so
    # when someone delete the link and relink we can rematch the data
Florent Chehab's avatar
Florent Chehab committed
25
26


27
class PreviousDepartureSerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
28
29
30
31
32
33

    class Meta:
        model = PreviousDeparture
        fields = '__all__'


34
class PreviousDepartureViewSet(MyModelViewSet):
35
    permission_classes = get_viewset_permissions("PreviousDepartureViewSet")
Florent Chehab's avatar
Florent Chehab committed
36
37
    queryset = PreviousDeparture.objects.all()  # pylint: disable=E1101
    serializer_class = PreviousDepartureSerializer
38
    # todo if is_anonymous set user to null