diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py index 8a9310d430c342a37a987cbf532120c26c353da2..80bc5caf0c07a4b49cd4c23daba8fe7e3659ae17 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/viewsets/specification.py @@ -105,6 +105,38 @@ class SchedulingUnitObservingStrategyTemplateViewSet(LOFARViewSet): status=status.HTTP_201_CREATED, headers={'Location': scheduling_unit_draft_path}) + + @swagger_auto_schema(responses={200: 'The template document as JSON object', + 403: 'forbidden'}, + operation_description="Get just the template document as JSON object. This template document can be submitted as the requirements_doc for a new scheduling_unit_draft (with user edits if you want).") + @action(methods=['get'], detail=True) + def template_doc(self, request, pk=None): + strategy_template = get_object_or_404(models.SchedulingUnitObservingStrategyTemplate, pk=pk) + return JsonResponse(strategy_template.template, json_dumps_params={'indent': 2}) + + + @swagger_auto_schema(responses={200: 'The template document as JSON object with all defaults filled in.', + 403: 'forbidden'}, + operation_description="Get the template document as JSON object with all defaults filled in. This template document can be submitted as the requirements_doc for a new scheduling_unit_draft (with user edits if you want).") + @action(methods=['get'], detail=True) + def template_doc_complete_with_defaults(self, request, pk=None): + strategy_template = get_object_or_404(models.SchedulingUnitObservingStrategyTemplate, pk=pk) + template_doc = strategy_template.template + + # loop over all tasks, and add the defaults to each task given the task's specifications_template + for task_name, task_doc in list(template_doc['tasks'].items()): + task_specifications_template = models.TaskTemplate.objects.get(name=task_doc['specifications_template']) + template_doc['tasks'][task_name] = add_defaults_to_json_object_for_schema(task_doc, task_specifications_template.schema) + + # add the default constraints given the scheduling_constraints_template + constraints_template = models.SchedulingConstraintsTemplate.objects.get(name=template_doc.get('scheduling_constraints_template')) + constraints_doc = add_defaults_to_json_object_for_schema(template_doc.get('scheduling_constraints_doc', {}), constraints_template.schema) + template_doc['scheduling_constraints_doc'] = constraints_doc + + return JsonResponse(template_doc, json_dumps_params={'indent': 2}) + + + class SchedulingUnitObservingStrategyTemplateNestedViewSet(LOFARNestedViewSet): queryset = models.SchedulingUnitObservingStrategyTemplate.objects.all() serializer_class = serializers.SchedulingUnitObservingStrategyTemplateSerializer