Coverage for backend/django/core/auxiliary/viewsets/CustomPropertyPackageViewSet.py: 88%
49 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
1from ..serializers.CustomPropertyPackageSerializer import CustomPropertyPackageSerializer, CustomCompoundSerializer, KappaSerializer, CustomPropertyPackagePropertySerializer, CompoundPropertySerializer
2from ..models.CustomPropertyPackage import CustomPropertyPackage, CustomCompound, CustomPropertyPackageProperty, Kappa, CompoundProperty
3from core.viewset import ModelViewSet
4from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes
5from rest_framework.decorators import action
6from rest_framework.response import Response
7from rest_framework.request import Request
8from ..methods.custom_property_packages.add_compound_to_package import add_compound_to_property_package, remove_compound_from_property_package
9from ..methods.custom_property_packages.create_compound import add_compound
10from ..methods.custom_property_packages.create_property_package import add_property_package
11from rest_framework import status, viewsets
16class CustomPropertyPackageViewSet(ModelViewSet):
17 serializer_class = CustomPropertyPackageSerializer
19 def get_queryset(self, **kwargs):
20 return CustomPropertyPackage.objects.prefetch_related("properties","kappas").all()
23 @extend_schema(
24 parameters=[
25 OpenApiParameter(name="property_package_id", required=True, type=OpenApiTypes.INT),
26 OpenApiParameter(name="compound_id", required=True, type=OpenApiTypes.INT),
27 ],
28 request=None,
29 responses={204: None}
30 )
31 @action(detail=False, methods=["post"], url_path="add-compound")
32 def add_compound_to_package(self,request: Request):
33 package_id = request.query_params.get("property_package_id")
34 compound_id = request.query_params.get("compound_id")
35 package = CustomPropertyPackage.objects.get(id=package_id)
36 compound = CustomCompound.objects.get(id=compound_id)
37 add_compound_to_property_package(package, compound)
38 return Response(status=204)
40 @extend_schema(
41 parameters=[
42 OpenApiParameter(name="property_package_id", required=True, type=OpenApiTypes.INT),
43 OpenApiParameter(name="compound_id", required=True, type=OpenApiTypes.INT),
44 ],
45 request=None,
46 responses={204: None}
47 )
48 @action(detail=False, methods=["post"], url_path="remove-compound")
49 def remove_compound_from_property_package(self,request: Request):
50 package_id = request.query_params.get("property_package_id")
51 compound_id = request.query_params.get("compound_id")
52 package = CustomPropertyPackage.objects.get(id=package_id)
53 compound = CustomCompound.objects.get(id=compound_id)
54 remove_compound_from_property_package(package, compound)
55 return Response(status=204)
59class CustomCompoundViewSet(ModelViewSet):
60 serializer_class = CustomCompoundSerializer
62 def get_queryset(self, **kwargs):
63 return CustomCompound.objects.prefetch_related("properties").all()
66class CustomPropertyPackagePropertyViewSet(ModelViewSet):
67 serializer_class = CustomPropertyPackagePropertySerializer
69 def get_queryset(self, **kwargs):
70 return CustomPropertyPackageProperty.objects.all()
73class CompoundPropertyViewSet(ModelViewSet):
74 serializer_class = CompoundPropertySerializer
75 def get_queryset(self, **kwargs):
76 return CompoundProperty.objects.all()
78class KappaViewSet(ModelViewSet):
79 serializer_class = KappaSerializer
80 def get_queryset(self, **kwargs):
81 return Kappa.objects.all()