previousDeparture.py 1.43 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from rest_framework import viewsets, permissions, serializers
Florent Chehab's avatar
Florent Chehab committed
3
4
5
6

from rex.models.otherCore.specialty import Specialty
from rex.models.otherCore.semester import Semester
from rex.models.university import University
7
8
from django.contrib.auth.models import User
from django.contrib.postgres.fields import JSONField
Florent Chehab's avatar
Florent Chehab committed
9
10


11
12
class PreviousDeparture(models.Model):
    # This model should be filled with data from the ENT
Florent Chehab's avatar
Florent Chehab committed
13
14
15
    semester = models.ForeignKey(Semester, on_delete=models.PROTECT)
    university = models.ForeignKey(University, on_delete=models.PROTECT)
    specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT)
16
17
18
    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
19

20
21
22
23
    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
24
25


26
class PreviousDepartureSerializer(serializers.ModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
27
28
29
30
31
32
33

    class Meta:
        model = PreviousDeparture
        fields = '__all__'


class PreviousDepartureViewSet(viewsets.ModelViewSet):
34
    permission_classes = (permissions.IsAdminUser,)
Florent Chehab's avatar
Florent Chehab committed
35
36
    queryset = PreviousDeparture.objects.all()  # pylint: disable=E1101
    serializer_class = PreviousDepartureSerializer
37
    # todo if is_anonymous set user to null