universityModulesAPI.py 1.79 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
from backend.models.university import University
2
from backend.models.campus import CampusSerializer
Florent Chehab's avatar
Florent Chehab committed
3
4

from backend.models.university import UniversityDriSerializer
5
6
7
8
9
from backend.models.university import UniversityInfoSerializer
from backend.models.university import UniversityScholarshipSerializer
from backend.models.university import UniversitySemestersDatesSerializer
from backend.models.university import UniversityTaggedItemSerializer

10
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
11
from backend.utils import get_viewset_permissions
Florent Chehab's avatar
Florent Chehab committed
12
13


14
class UniversityModulesSerializer(MyModelSerializer):
15
16
17
18
19
    university_campuses = CampusSerializer(many=True, read_only=True)
    university_scholarships = UniversityScholarshipSerializer(
        many=True, read_only=True)
    university_tagged_items = UniversityTaggedItemSerializer(
        many=True, read_only=True)
Florent Chehab's avatar
Florent Chehab committed
20
    university_dri = UniversityDriSerializer(many=True, read_only=True)
21
22
23
    university_info = UniversityInfoSerializer(read_only=True)
    university_semesters_dates = UniversitySemestersDatesSerializer(
        read_only=True)
Florent Chehab's avatar
Florent Chehab committed
24
25
26
27
28
29

    class Meta:
        model = University
        fields = '__all__'


30
class UniversityModulesViewSet(MyModelViewSet):
31
    permission_classes = get_viewset_permissions("UniversityModulesViewSet")
Florent Chehab's avatar
Florent Chehab committed
32
    serializer_class = UniversityModulesSerializer
33
    queryset = University.objects.all()
34
    LIST_SHOULD_BE_DETAIL = True
Florent Chehab's avatar
Florent Chehab committed
35

36
    def extend_queryset(self):
Florent Chehab's avatar
Florent Chehab committed
37
        univ_id = self.kwargs['univ_id']
38
39
40
41
42
43
44
45
        return self.my_model_queryset.filter(pk=univ_id).prefetch_related(
            'university_campuses',
            'university_dri',
            'university_info',
            'university_scholarships',
            'university_semesters_dates',
            'university_tagged_items'
        )  # pylint: disable=E1101