Commit 06969002 authored by Janez K's avatar Janez K
Browse files

workflow api

parent 2e1dc094
......@@ -203,6 +203,8 @@ REST_FRAMEWORK = {
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'PAGINATE_BY': None,
'DEFAULT_FILTER_BACKENDS': ('rest_framework.filters.DjangoFilterBackend',)
}
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS
......
......@@ -11,17 +11,18 @@ class WorkflowViewSet(viewsets.ModelViewSet):
API endpoint that allows workflows to be viewed or edited.
"""
model = Workflow
filter_fields = ('public',)
def get_serializer_class(self):
if self.action == 'list':
return WorkflowListSerializer
return WorkflowSerializer
def pre_save(self, workflow):
workflow.user = self.request.user
def perform_create(self, serializer):
serializer.save(user=self.request.user)
def get_queryset(self):
return Workflow.objects.filter(user=self.request.user,widget=None)
return Workflow.objects.filter(user=self.request.user).prefetch_related('widgets','widgets__inputs','widgets__outputs')
class WidgetViewSet(viewsets.ModelViewSet):
......@@ -29,6 +30,7 @@ class WidgetViewSet(viewsets.ModelViewSet):
API endpoint that allows widgets to be viewed or edited.
"""
model = Widget
filter_field = ('workflow',)
def get_serializer_class(self):
if self.action == 'list':
......@@ -36,7 +38,7 @@ class WidgetViewSet(viewsets.ModelViewSet):
return WidgetSerializer
def get_queryset(self):
return Widget.objects.filter(workflow__user=self.request.user)
return Widget.objects.filter(workflow__user=self.request.user).prefetch_related('inputs','outputs')
class ConnectionViewSet(viewsets.ModelViewSet):
......
......@@ -2,7 +2,6 @@ from rest_framework import serializers
from workflows.models import *
#from rest_framework.reverse import reverse
class ConnectionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Connection
......@@ -25,24 +24,42 @@ class WidgetListSerializer(serializers.HyperlinkedModelSerializer):
model = Widget
exclude = ('abstract_widget',)
class WorkflowListSerializer(serializers.HyperlinkedModelSerializer):
is_subprocess = serializers.SerializerMethodField()
def get_is_subprocess(self, obj):
if obj.widget == None:
return False
else:
return True
class Meta:
model = Workflow
exclude = ('user',)
class WidgetSerializer(serializers.HyperlinkedModelSerializer):
inputs = InputSerializer(many=True, read_only=True)
outputs = OutputSerializer(many=True, read_only=True)
workflow_link = serializers.HyperlinkedRelatedField(
read_only=True,
view_name='workflow-detail'
)
class Meta:
model = Widget
exclude = ('abstract_widget',)
class WorkflowListSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Workflow
fields = ('id', 'name', 'public', 'description', 'url')
class WorkflowSerializer(serializers.HyperlinkedModelSerializer):
widgets = WidgetSerializer(many=True, read_only=True)
connections = ConnectionSerializer(many=True, read_only=True)
is_subprocess = serializers.SerializerMethodField()
def get_is_subprocess(self, obj):
if obj.widget == None:
return False
else:
return True
class Meta:
model = Workflow
fields = ('id', 'name', 'public', 'description', 'widgets', 'connections', 'url')
exclude = ('user',)
\ No newline at end of file
Supports Markdown
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