Coverage for apps/practitioners/views.py: 68%
40 statements
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-31 13:23 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2024-05-31 13:23 -0600
1from rest_framework.decorators import action
2from rest_framework.mixins import CreateModelMixin as Create
3from rest_framework.mixins import ListModelMixin as List
4from rest_framework.mixins import RetrieveModelMixin as Detail
5from rest_framework.mixins import UpdateModelMixin as Update
6from rest_framework.serializers import ValidationError
7from rest_framework.viewsets import GenericViewSet, ModelViewSet
9from apps.users.mixins import AdminMixin, UserMixin
11from .serializers import CertificationSerializer, GoogleCalendarSerializer, PractitionerSerializer
12from app.stripe.serializers import StripeSubscriptionSerializer
15class AdminPractitionerViewSet(AdminMixin, ModelViewSet):
16 """
17 Model ViewSet for Practitioners
18 """
20 serializer_class = PractitionerSerializer
23class AdminCertificationViewSet(AdminMixin, ModelViewSet):
24 """
25 Model ViewSet for Certifications
26 """
28 serializer_class = CertificationSerializer
31class UserPractitionerViewSet(UserMixin, GenericViewSet, Create, Detail, Update):
32 """
33 Model ViewSet for Practitioners
34 """
36 serializer_class = PractitionerSerializer
38 def create(self, request, *args, **kwargs):
39 request.data["user"] = request.user.pk
40 return super().create(request, args, kwargs)
43class UserSubscriptionViewSet(UserMixin, GenericViewSet, Create, List, Detail, Update):
44 """
45 Model ViewSet for Suscriptions
46 """
48 serializer_class = StripeSubscriptionSerializer
50 def get_queryset(self, *args, **kwargs):
51 if getattr(self.user, 'practitioner', None):
52 return super().get_queryset().filter(subscriber=self.user.practitioner.pk)
53 return super().get_queryset().none()
55 def create(self, request, *args, **kwargs):
56 practitioner = getattr(request.user, 'practitioner', None)
57 if not practitioner:
58 raise ValidationError({"Este usuario no es Doctor"})
59 request.data["practitioner"] = request.user.practitioner
60 sup = super().create(request, args, kwargs)
61 print(sup)
62 return sup
67class UserCertificationViewSet(UserMixin, GenericViewSet, Create, List, Detail):
68 """
69 Model ViewSet for Certifications
70 """
72 serializer_class = CertificationSerializer
74 def create(self, request, *args, **kwargs):
75 request.data["practitioner"] = request.user.practitioner.pk
76 return super().create(request, args, kwargs)
79class UserGoogleCalendarViewSet(UserMixin, GenericViewSet, Update, Detail):
80 """
81 Model ViewSet for GoogleCalendars
82 """
84 serializer_class = GoogleCalendarSerializer