Commit 3b60ab82 authored by Janez K's avatar Janez K

merge api

parents f6f8fbe4 1acc66d2
......@@ -174,6 +174,7 @@ INSTALLED_APPS_DEFAULT = (
'djcelery',
#'kombu.transport.django',
'discover_runner',
'rest_framework',
)
INSTALLED_APPS_WORKFLOWS_SUB = ()
......@@ -195,10 +196,16 @@ INSTALLED_APPS = \
INSTALLED_APPS_DEFAULT +\
INSTALLED_APPS_WORKFLOWS_SUB
#REST_FRAMEWORK = {
# 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
# 'PAGINATE_BY': 10
#}
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',
'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
......
{% extends "rest_framework/base.html" %}
{% block title %}ClowdFlows API{% endblock %}
{% block branding %}<a class='navbar-brand' href="/api/">ClowdFlows API<span class="version">1.0</span></a>{% endblock %}
\ No newline at end of file
......@@ -22,6 +22,8 @@ urlpatterns = patterns('',
url(r'^streams/', include('streams.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('workflows.api_urls')),
url('^' + LOGIN_URL[1:] + '$', 'django.contrib.auth.views.login', name='login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
url(r'^change-password/$', 'django.contrib.auth.views.password_change', name='password change'),
......
......@@ -15,4 +15,5 @@ ladon==0.8.9
django-discover-runner==1.0
liac-arff==2.0.1
networkx==1.9.1
djangorestframework==3.0.3
django-filter==0.9.1
from django.conf.urls import patterns, include, url
from rest_framework import routers
from workflows import api_views
router = routers.DefaultRouter()
router.register(r'workflows', api_views.WorkflowViewSet)
router.register(r'widgets', api_views.WidgetViewSet)
router.register(r'connections', api_views.ConnectionViewSet)
router.register(r'inputs', api_views.InputViewSet)
router.register(r'outputs', api_views.OutputViewSet)
urlpatterns = patterns('',
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
from rest_framework import viewsets, mixins
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import filters
from workflows.models import *
from workflows.serializers import *
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 perform_create(self, serializer):
serializer.save(user=self.request.user)
def get_queryset(self):
return Workflow.objects.filter(user=self.request.user).prefetch_related('widgets','widgets__inputs','widgets__outputs')
class WidgetViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows widgets to be viewed or edited.
"""
model = Widget
filter_fields = ('workflow',)
def get_serializer_class(self):
if self.action == 'list':
return WidgetListSerializer
return WidgetSerializer
def get_queryset(self):
return Widget.objects.filter(workflow__user=self.request.user).prefetch_related('inputs','outputs')
class ConnectionViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows connections to be viewed or edited.
"""
serializer_class = ConnectionSerializer
model = Connection
def get_queryset(self):
return Connection.objects.filter(workflow__user=self.request.user)
class InputViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows widget inputs to be viewed or edited.
"""
serializer_class = InputSerializer
model = Input
def get_queryset(self):
return Input.objects.filter(widget__workflow__user=self.request.user)
class OutputViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows widget outputs to be viewed or edited.
"""
serializer_class = OutputSerializer
model = Output
def get_queryset(self):
return Output.objects.filter(widget__workflow__user=self.request.user)
......@@ -903,6 +903,8 @@ class Input(models.Model):
('text','Single line'),
('textarea','Multi line text'),
('select', 'Select box'),
('file', 'File field'),
('checkbox', 'Checkbox'),
)
parameter_type = models.CharField(max_length=50,choices=PARAMETER_CHOICES,blank=True,null=True)
order = models.PositiveIntegerField(default=1)
......
from rest_framework import serializers
from workflows.models import *
#from rest_framework.reverse import reverse
class ConnectionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Connection
class InputSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Input
exclude = ('value',)
class OutputSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Output
exclude = ('value',)
class WidgetListSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
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 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
exclude = ('user',)
\ No newline at end of file
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