workflow JT survey and launch serializer in functional state

This commit is contained in:
AlanCoding 2016-11-07 15:13:20 -05:00
parent 64b5e2ba5b
commit a87a56f518
4 changed files with 18 additions and 20 deletions

View File

@ -2609,20 +2609,21 @@ class JobLaunchSerializer(BaseSerializer):
class WorkflowJobLaunchSerializer(BaseSerializer):
# can_start_without_user_input = serializers.BooleanField(read_only=True)
# variables_needed_to_start = serializers.ReadOnlyField()
can_start_without_user_input = serializers.BooleanField(read_only=True)
variables_needed_to_start = serializers.ReadOnlyField()
survey_enabled = serializers.SerializerMethodField()
extra_vars = VerbatimField(required=False, write_only=True)
# workflow_job_template_data = serializers.SerializerMethodField()
# warnings =
warnings = serializers.SerializerMethodField()
workflow_job_template_data = serializers.SerializerMethodField()
class Meta:
model = WorkflowJobTemplate
fields = ('*',#'can_start_without_user_input',
'extra_vars',
'survey_enabled')#, 'variables_needed_to_start',
# 'workflow_job_template_data')
fields = ('can_start_without_user_input', 'extra_vars', 'warnings',
'survey_enabled', 'variables_needed_to_start',
'workflow_job_template_data')
def get_warnings(self, obj):
return obj.get_warnings()
def get_survey_enabled(self, obj):
if obj:

View File

@ -2803,13 +2803,6 @@ class WorkflowJobTemplateLaunch(RetrieveAPIView):
if extra_vars:
data['extra_vars'] = extra_vars
return data
# def get(self, request, *args, **kwargs):
# data = {}
# obj = self.get_object()
# data['warnings'] = obj.get_warnings()
# data['variables_needed_to_start'] = obj.variables_needed_to_start
# return Response(data)
def post(self, request, *args, **kwargs):
obj = self.get_object()
@ -2824,8 +2817,11 @@ class WorkflowJobTemplateLaunch(RetrieveAPIView):
new_job = obj.create_unified_job(**prompted_fields)
new_job.signal_start(**prompted_fields)
data = dict(workflow_job=new_job.id)
data = OrderedDict()
data['ignored_fields'] = ignored_fields
data.update(WorkflowJobSerializer(new_job, context=self.get_serializer_context()).to_representation(new_job))
data['workflow_job'] = new_job.id
return Response(data, status=status.HTTP_201_CREATED)
# TODO:

View File

@ -1541,7 +1541,8 @@ class WorkflowJobTemplateAccess(BaseAccess):
def can_change(self, obj, data):
# Check survey license if surveys are added to WFJTs
if 'survey_enabled' in data and obj.survey_enabled != data['survey_enabled'] and data['survey_enabled']:
if (data and 'survey_enabled' in data and
obj.survey_enabled != data['survey_enabled'] and data['survey_enabled']):
self.check_license(feature='surveys')
if self.user.is_superuser:

View File

@ -332,9 +332,9 @@ class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTempl
survey_vars = [question['variable'] for question in self.survey_spec.get('spec', [])]
for key in extra_vars:
if key in survey_vars:
prompted_fields[field][key] = extra_vars[key]
prompted_fields['extra_vars'][key] = extra_vars[key]
else:
ignored_fields[field][key] = extra_vars[key]
ignored_fields['extra_vars'][key] = extra_vars[key]
else:
prompted_fields['extra_vars'] = extra_vars