previousDeparture.py 1.67 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_app.models.other_core.specialty import Specialty
from backend_app.models.university import University
4
from django.contrib.auth.models import User
Florent Chehab's avatar
Florent Chehab committed
5
from backend_app.fields import JSONField
6
7
8
9
10
from backend_app.models.abstract.my_model import (
    MyModel,
    MyModelSerializer,
    MyModelViewSet,
)
Florent Chehab's avatar
Florent Chehab committed
11
from backend_app.utils import get_model_config, get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
12
from backend_app.models import SEMESTER_OPTIONS
Florent Chehab's avatar
Florent Chehab committed
13
14


15
class PreviousDeparture(MyModel):
Florent Chehab's avatar
Florent Chehab committed
16
    model_config = get_model_config("PreviousDeparture")
17
    # This model should be filled with data from the ENT
Florent Chehab's avatar
Florent Chehab committed
18
19
    university = models.ForeignKey(University, on_delete=models.PROTECT)
    specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT)
20
    user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
Florent Chehab's avatar
Florent Chehab committed
21
    # Useful to relink a departure with a user
22
    Utc_departure_id = models.IntegerField()
Florent Chehab's avatar
Florent Chehab committed
23
24
    year = models.PositiveIntegerField(default=2018)
    semester = models.CharField(max_length=2, choices=SEMESTER_OPTIONS, default="a")
Florent Chehab's avatar
Florent Chehab committed
25

26
27
28
29
    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
30
31


32
class PreviousDepartureSerializer(MyModelSerializer):
Florent Chehab's avatar
Florent Chehab committed
33
34
    class Meta:
        model = PreviousDeparture
35
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
36
37


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