Commit 584bd049 authored by Jorrit Schaap's avatar Jorrit Schaap

TMSS-153: moved default_specificaton and parset methods from view functions to...

TMSS-153: moved default_specificaton and parset methods from view functions to viewset methods, and annotated them with swagger documentation. This way they are automatically part of the swagger API pages
parent d31c6e6d
......@@ -3,10 +3,17 @@ This file contains the viewsets (based on the elsewhere defined data models and
"""
from django.shortcuts import get_object_or_404
from rest_framework import viewsets
from .lofar_viewset import LOFARViewSet
from .. import models
from .. import serializers
from rest_framework.decorators import action
from django.http import HttpResponse, JsonResponse
from drf_yasg.utils import swagger_auto_schema
from lofar.sas.tmss.tmss.tmssapp.viewsets.lofar_viewset import LOFARViewSet
from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp import serializers
from lofar.common.json_utils import get_default_json_object_for_schema
from lofar.sas.tmss.tmss.tmssapp.adapters.parset import convert_to_parset
class SubtaskConnectorViewSet(LOFARViewSet):
queryset = models.SubtaskConnector.objects.all()
......@@ -52,6 +59,16 @@ class SubtaskTemplateViewSet(LOFARViewSet):
return queryset
@swagger_auto_schema(responses={200: 'JSON object with all the defaults from the schema filled in',
403: 'forbidden'},
operation_description="Get a JSON object with all the defaults from the schema filled in.")
@action(methods=['get'], detail=True)
def default_specification(self, request, pk=None):
subtask_template = get_object_or_404(models.SubtaskTemplate, pk=pk)
spec = get_default_json_object_for_schema(subtask_template.schema)
return JsonResponse(spec)
class DefaultSubtaskTemplateViewSet(LOFARViewSet):
queryset = models.DefaultSubtaskTemplate.objects.all()
serializer_class = serializers.DefaultSubtaskTemplateSerializer
......@@ -76,7 +93,6 @@ class DataproductFeedbackTemplateViewSet(LOFARViewSet):
queryset = models.DataproductFeedbackTemplate.objects.all()
serializer_class = serializers.DataproductFeedbackTemplateSerializer
class SubtaskViewSet(LOFARViewSet):
queryset = models.Subtask.objects.all()
serializer_class = serializers.SubtaskSerializer
......@@ -88,6 +104,14 @@ class SubtaskViewSet(LOFARViewSet):
else:
return models.Subtask.objects.all()
@swagger_auto_schema(responses={200: 'A LOFAR parset for this subtask',
403: 'forbidden'},
operation_description="Get a a LOFAR parset for the specifications of this subtask")
@action(methods=['get'], detail=True)
def default_specification(self, request, pk=None):
subtask = get_object_or_404(models.Subtask, pk=pk)
parset = convert_to_parset(subtask)
return HttpResponse(str(parset), content_type='text/plain')
class SubtaskInputViewSet(LOFARViewSet):
queryset = models.SubtaskInput.objects.all()
......@@ -152,3 +176,14 @@ class SubtaskViewSetJSONeditorOnline(LOFARViewSet):
return task_blueprint.subtasks.all()
else:
return models.Subtask.objects.all()
@swagger_auto_schema(responses={200: 'A LOFAR parset for this subtask (as plain text, not json)',
403: 'forbidden',
404: 'Not found'},
operation_description="Get a LOFAR parset for the specifications of this subtask")
@action(methods=['get'], detail=True)
def parset(self, request, pk=None):
subtask = get_object_or_404(models.Subtask, pk=pk)
parset = convert_to_parset(subtask)
return HttpResponse(str(parset), content_type='text/plain')
......@@ -3,12 +3,19 @@ This file contains the viewsets (based on the elsewhere defined data models and
"""
from django.shortcuts import get_object_or_404
from rest_framework import viewsets
from .lofar_viewset import LOFARViewSet
from .. import models, serializers
from rest_framework.renderers import BrowsableAPIRenderer, TemplateHTMLRenderer
from django.http import JsonResponse
from rest_framework.decorators import permission_classes
from rest_framework.permissions import IsAuthenticatedOrReadOnly, DjangoModelPermissions
from rest_framework.decorators import action
from drf_yasg.utils import swagger_auto_schema
from lofar.sas.tmss.tmss.tmssapp.viewsets.lofar_viewset import LOFARViewSet
from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp import serializers
from lofar.common.json_utils import get_default_json_object_for_schema
class TagsViewSet(LOFARViewSet):
queryset = models.Tags.objects.all()
......@@ -39,6 +46,15 @@ class TaskTemplateViewSet(LOFARViewSet):
queryset = models.TaskTemplate.objects.all()
serializer_class = serializers.TaskTemplateSerializer
@swagger_auto_schema(responses={200: 'JSON object with all the defaults from the schema filled in',
403: 'forbidden'},
operation_description="Get a JSON object with all the defaults from the schema filled in.")
@action(methods=['get'], detail=True)
def default_specification(self, request, pk=None):
template = get_object_or_404(models.TaskTemplate, pk=pk)
spec = get_default_json_object_for_schema(template.schema)
return JsonResponse(spec)
class DefaultTaskTemplateViewSet(LOFARViewSet):
queryset = models.DefaultTaskTemplate.objects.all()
......
......@@ -122,10 +122,6 @@ router.register(r'default_dataproduct_specifications_template', viewsets.Default
router.register(r'subtask_input_selection_template', viewsets.SubtaskInputSelectionTemplateViewSet)
router.register(r'dataproduct_feedback_template', viewsets.DataproductFeedbackTemplateViewSet)
urlpatterns.append(re_path(r'task_template/(?P<task_template_pk>\d+)/default_specification', views.task_template_default_specification))
urlpatterns.append(re_path(r'subtask_template/(?P<subtask_template_pk>\d+)/default_specification', views.subtask_template_default_specification))
urlpatterns.append(re_path(r'subtask/(?P<subtask_pk>\d+)/parset', views.subtask_parset))
# instances
#router.register(r'subtask', viewsets.SubtaskViewSet) # todo: default view, re-activate or remove the JSON editor one in bottom
router.register(r'dataproduct', viewsets.DataproductViewSet)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment