previousDeparture.py 1.49 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 base_app.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
    is_anonymous = models.BooleanField()
    courses = JSONField(null=True)  # Store data from ENT
Florent Chehab's avatar
Florent Chehab committed
28
29


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


36
class PreviousDepartureViewSet(MyModelViewSet):
37
    permission_classes = get_viewset_permissions("PreviousDepartureViewSet")
Florent Chehab's avatar
Florent Chehab committed
38
39
    queryset = PreviousDeparture.objects.all()  # pylint: disable=E1101
    serializer_class = PreviousDepartureSerializer