Skip to content

Commit

Permalink
Add type and params fields to ComponentSerializer
Browse files Browse the repository at this point in the history
Effecting APIs:
  - /api/v1/oprations/:ComponentName/:id
  - /api/v1/oprations/:id

Related-Issue: #34
  • Loading branch information
travelist committed Sep 27, 2015
1 parent 54273c4 commit e53c9cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cognitive/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Data_operation_type(models.Model):
function_arg = models.CharField(max_length=50, choices=FUNCTION_ARG)
function_arg_id = models.CharField(max_length=50, blank=True, null=True)
function_subtype = models.CharField(max_length=50, choices=FUNCTION_SUBTYPE)

# This should be JSON format
function_subtype_arg = models.CharField(max_length=50, blank=True, null=True)

def __str__(self):
Expand Down
23 changes: 22 additions & 1 deletion cognitive/app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.

import json

from rest_framework import serializers
from .models import User, Experiment, Component, Workflow
from .models import User, Experiment, Component, Workflow, Data_operation_type


class UserSerializer(serializers.ModelSerializer):
Expand All @@ -35,11 +37,30 @@ class Meta:
# 'execution_start_time', 'execution_end_time', 'component_start_id')


class ComponentOutputValue(serializers.ModelSerializer):
class Meta:
fields = ('function_subtype', 'function_subtype_arg')
model = Data_operation_type

class ComponentSerializer(serializers.ModelSerializer):
type = serializers.SerializerMethodField('component_type')
params = serializers.SerializerMethodField('component_params')

class Meta:
model = Component

def component_type(self, obj):
return obj.operation_type.function_subtype

def component_params(self, obj):
data = obj.operation_type.function_subtype_arg
if data is None:
return ''
elif data.startswith(('[', '{')):
return json.loads(data)
else:
# TODO(|Less Priority| All Data_operation_type.function_subtype_arg values should be JSON)
return data

class WorkflowSerializer(serializers.ModelSerializer):

Expand Down

0 comments on commit e53c9cd

Please sign in to comment.