viewsets.py 3.93 KB
Newer Older
1 2 3 4 5
from django.conf import settings
from rest_framework.response import Response
from rest_framework.views import APIView

from backend_app.checks import check_viewsets
6
from backend_app.models.abstract.essentialModule import EssentialModuleViewSet
7 8 9 10 11 12 13 14
from backend_app.models.campus import CampusViewSet, MainCampusViewSet
from backend_app.models.campusTaggedItem import CampusTaggedItemViewSet
from backend_app.models.city import CityViewSet
from backend_app.models.cityTaggedItem import CityTaggedItemViewSet
from backend_app.models.country import CountryViewSet
from backend_app.models.countryDri import CountryDriViewSet
from backend_app.models.countryScholarship import CountryScholarshipViewSet
from backend_app.models.countryTaggedItem import CountryTaggedItemViewSet
15
from backend_app.models.courseFeedback import CourseFeedback
16 17
from backend_app.models.currency import CurrencyViewSet
from backend_app.models.department import DepartmentViewSet
18
from backend_app.models.exchangeFeedback import ExchangeFeedbackViewSet
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
from backend_app.models.for_testing.moderation import ForTestingModerationViewSet
from backend_app.models.for_testing.versioning import ForTestingVersioningViewSet
from backend_app.models.offer import OfferViewSet
from backend_app.models.pendingModeration import (
    PendingModerationViewSet,
    PendingModerationObjViewSet,
)
from backend_app.models.specialty import SpecialtyViewSet
from backend_app.models.tag import TagViewSet
from backend_app.models.university import UniversityViewSet
from backend_app.models.universityDri import UniversityDriViewSet
from backend_app.models.universityInfo import UniversityInfoViewSet
from backend_app.models.universityScholarship import UniversityScholarshipViewSet
from backend_app.models.universitySemestersDates import UniversitySemestersDatesViewSet
from backend_app.models.universityTaggedItem import UniversityTaggedItemViewSet
from backend_app.models.userData import UserDataViewSet
from backend_app.models.version import VersionViewSet
from backend_app.permissions.app_permissions import ReadOnly
37
from backend_app.serializers import CourseFeedbackSerializer
38 39
from backend_app.settings.defaults import OBJ_MODERATION_PERMISSIONS
from base_app.models import UserViewset
40

41 42 43 44 45 46 47

class CourseFeedbackViewSet(EssentialModuleViewSet):
    queryset = CourseFeedback.objects.all().prefetch_related()  # pylint: disable=E1101
    serializer_class = CourseFeedbackSerializer
    end_point_route = "courseFeedbacks"


48
ALL_API_VIEWSETS = [
49
    UserViewset,
50 51 52 53 54 55 56 57 58
    CampusViewSet,
    MainCampusViewSet,
    CampusTaggedItemViewSet,
    CityViewSet,
    CityTaggedItemViewSet,
    CountryViewSet,
    CountryDriViewSet,
    CountryScholarshipViewSet,
    CountryTaggedItemViewSet,
59
    CourseFeedbackViewSet,
60 61 62 63 64
    CurrencyViewSet,
    DepartmentViewSet,
    OfferViewSet,
    PendingModerationViewSet,
    PendingModerationObjViewSet,
65
    ExchangeFeedbackViewSet,
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    SpecialtyViewSet,
    TagViewSet,
    UniversityViewSet,
    UniversityDriViewSet,
    UniversityInfoViewSet,
    UniversityScholarshipViewSet,
    UniversitySemestersDatesViewSet,
    UniversityTaggedItemViewSet,
    UserDataViewSet,
    VersionViewSet,
]

if settings.TESTING:
    # We only register viewsets in a testing environment
    ALL_API_VIEWSETS += [ForTestingModerationViewSet, ForTestingVersioningViewSet]


class AppModerationStatusViewSet(APIView):
    """
    Viewset to know what is the app moderation status
    """

    # Since AppModerationStatusViewSet doesn't inherit from BaseModelViewSet
    # We need to link here the correct permissions
    permission_classes = (ReadOnly,)
    end_point_route = "serverModerationStatus"

    def get(self, request):
        return Response(
            {
                "activated": settings.MODERATION_ACTIVATED,
                "moderator_level": OBJ_MODERATION_PERMISSIONS["moderator"],
            }
        )


ALL_API_VIEW_VIEWSETS = [AppModerationStatusViewSet]

ALL_VIEWSETS = ALL_API_VIEWSETS + ALL_API_VIEW_VIEWSETS

check_viewsets(ALL_VIEWSETS)