Coverage for backend/django/core/auxiliary/viewsets/PropertyValueViewSet.py: 100%
26 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-02-12 01:47 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-02-12 01:47 +0000
1from core.viewset import ModelViewSet
2from rest_framework.response import Response
3from drf_spectacular.utils import extend_schema
4from rest_framework.decorators import action
5from core.auxiliary.models.PropertyValue import PropertyValue
6from ..serializers.PropertyValueSerializer import PropertyValueSerializer
8from idaes_factory.endpoints import BuildStateSolveError
10class PropertyValueViewSet(ModelViewSet):
11 serializer_class = PropertyValueSerializer
13 def get_queryset(self):
14 return PropertyValue.objects.all()
17 def update(self, request, *args, **kwargs) -> Response:
18 try:
19 return super().update(request, *args, **kwargs)
20 except BuildStateSolveError as e:
21 return Response({"error": str(e)}, status=400, content_type="application/json")
22 except Exception as e:
23 import traceback
24 traceback.print_exc()
25 return Response({"error": str(e)}, status=400, content_type="application/json")
28 @extend_schema(request=None, responses=PropertyValueSerializer)
29 @action(detail=True, methods=["post"], url_path="auto_replace")
30 def auto_replace(self, request, *args, **kwargs) -> Response:
31 instance = self.get_object()
32 instance.auto_replace()
33 return Response(PropertyValueSerializer(instance).data)