previousDeparture.py 1.49 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 backend_app.permissions.app_permissions import ReadOnly
5
from base_app.models import User
Florent Chehab's avatar
Florent Chehab committed
6
from backend_app.fields import JSONField
7 8 9 10
from backend_app.models.abstract.essentialModule import (
    EssentialModule,
    EssentialModuleSerializer,
    EssentialModuleViewSet,
11
)
12
from backend_app.models.shared import SEMESTER_OPTIONS
Florent Chehab's avatar
Florent Chehab committed
13 14


15
class PreviousDeparture(EssentialModule):
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)
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
38 39
    permission_classes = (ReadOnly,)
    end_point_route = "universitiesPreviousDepartures"