previousDeparture.py 1.34 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from django.db import models
2
from backend_app.models.specialty import Specialty
Florent Chehab's avatar
Florent Chehab committed
3
from backend_app.models.university import University
4
from base_app.models import User
Florent Chehab's avatar
Florent Chehab committed
5
from backend_app.fields import JSONField
6
7
8
9
from backend_app.models.abstract.essentialModule import (
    EssentialModule,
    EssentialModuleSerializer,
    EssentialModuleViewSet,
10
)
11
from backend_app.models.shared import SEMESTER_OPTIONS
Florent Chehab's avatar
Florent Chehab committed
12
13


14
class PreviousDeparture(EssentialModule):
15

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

25
26
    is_anonymous = models.BooleanField()
    courses = JSONField(null=True)  # Store data from ENT
Florent Chehab's avatar
Florent Chehab committed
27
28


29
class PreviousDepartureSerializer(EssentialModuleSerializer):
Florent Chehab's avatar
Florent Chehab committed
30
31
    class Meta:
        model = PreviousDeparture
32
        fields = "__all__"
Florent Chehab's avatar
Florent Chehab committed
33
34


35
class PreviousDepartureViewSet(EssentialModuleViewSet):
Florent Chehab's avatar
Florent Chehab committed
36
37
    queryset = PreviousDeparture.objects.all()  # pylint: disable=E1101
    serializer_class = PreviousDepartureSerializer