Coverage for apps/organizations/views.py: 84%
51 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-09 09:43 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-09 09:43 -0600
1from rest_framework import status
2from rest_framework.decorators import action
3from rest_framework.mixins import CreateModelMixin as Create
4from rest_framework.mixins import DestroyModelMixin as Delete
5from rest_framework.mixins import ListModelMixin as List
6from rest_framework.mixins import RetrieveModelMixin as Detail
7from rest_framework.mixins import UpdateModelMixin as Update
8from rest_framework.response import Response
9from rest_framework.viewsets import GenericViewSet
11from apps.users.mixins import EmployeeMixin, PublicMixin
13from .filters import OrganizationUploadFilter
14from .models import Organization, OrganizationUpload
15from .serializers import (
16 OrganizationCampaignLabelSerializer,
17 OrganizationCarouselSerializer,
18 OrganizationSerializer,
19 OrganizationSiteLabelSerializer,
20 OrganizationSocialSerializer,
21 OrganizationStatsSerializer,
22 OrganizationTreeSerializer,
23 OrganizationUploadPolymorphicSerializer,
24)
27class CurrentHost(PublicMixin, GenericViewSet):
28 def list(self, request, *args, **kwargs):
29 origin = request.headers.get("Origin", None)
30 try:
31 organization = Organization.objects.get(domain=origin)
32 except Organization.DoesNotExist:
33 return Response(status=status.HTTP_404_NOT_FOUND)
34 serializer = OrganizationSerializer(organization, context={"request": request})
35 return Response(serializer.data)
38class EmployeeOrganizationViewSet(EmployeeMixin, GenericViewSet, List, Detail, Update):
39 """
40 ViewSet for Organiztions
41 """
43 model_organization = "random_slug"
44 serializer_class = OrganizationSerializer
46 @action(methods=["GET"], detail=False)
47 def tree(self, request, *args, **kwargs):
48 self.serializer_class = OrganizationTreeSerializer
49 return super().list(request, args, kwargs)
51 @action(methods=["GET"], detail=False)
52 def stats(self, request, *args, **kwargs):
53 self.serializer_class = OrganizationStatsSerializer
54 return super().list(request, args, kwargs)
57class EmployeeOrganizationUploadViewSet(EmployeeMixin, GenericViewSet, Create, List, Detail, Update, Delete):
58 """
59 ViewSet for Organization Uploads
60 """
62 model = OrganizationUpload
63 serializer_class = OrganizationUploadPolymorphicSerializer
64 filterset_class = OrganizationUploadFilter
65 search_fields = ["name"]
68class EmployeeOrganizationSocialViewSet(EmployeeMixin, GenericViewSet, Create, List, Detail, Update, Delete):
69 """
70 ViewSet for Organization Socials
71 """
73 serializer_class = OrganizationSocialSerializer
76class EmployeeOrganizationCarouselViewSet(EmployeeMixin, GenericViewSet, Create, List, Detail, Update, Delete):
77 """
78 ViewSet for Organization Carousels
79 """
81 serializer_class = OrganizationCarouselSerializer
84class EmployeeOrganizationSiteLabelViewSet(EmployeeMixin, GenericViewSet, List, Update):
85 """
86 Organization Site Label ViewSet for Employee
87 """
89 serializer_class = OrganizationSiteLabelSerializer
90 filterset_fields = ["organization"]
93class EmployeeOrganizationCampaignLabelViewSet(EmployeeMixin, GenericViewSet, List, Update):
94 """
95 Organization Campaign Label ViewSet for Employee
96 """
98 serializer_class = OrganizationCampaignLabelSerializer
99 filterset_fields = ["organization"]
102class PublicOrganizationUploadViewSet(PublicMixin, GenericViewSet, List):
103 """
104 Viewset for Organization Uploads
105 """
107 model = OrganizationUpload
108 serializer_class = OrganizationUploadPolymorphicSerializer