def __init__(self, cleaned_data, version, fqn, forms=None, templates=None,
                 application=None, **kwargs):
        self.cleaned_data = cleaned_data
        self.templates = templates or {}
        self.spec_version = str(version)

        if application is None:
            raise ValueError('Application section is required')
        else:
            self.application = application

        self.context = legacy.create_context()
        yaql_functions.register(self.context)

        self.forms = []
        for key, value in six.iteritems(kwargs):
            setattr(self, key, value)

        if forms:
            for counter, data in enumerate(forms):
                name, field_specs, validators = self.extract_form_data(data)
                self._add_form(name, field_specs, validators)

        # Add ManageWorkflowForm
        workflow_form = catalog_forms.WorkflowManagementForm()
        if semantic_version.Version.coerce(self.spec_version) >= \
                semantic_version.Version.coerce('2.2'):
            app_name_field = workflow_form.name_field(fqn)
            workflow_form.field_specs.insert(0, app_name_field)

        self._add_form(workflow_form.name,
                       workflow_form.field_specs,
                       workflow_form.validators)
Exemple #2
0
    def __init__(self,
                 cleaned_data,
                 version,
                 fqn,
                 forms=None,
                 templates=None,
                 application=None,
                 parameters=None,
                 **kwargs):
        self.cleaned_data = cleaned_data
        self.templates = templates or {}
        self.spec_version = str(version)
        if forms is None:
            forms = []

        if application is None:
            raise ValueError('Application section is required')
        else:
            self.application = application

        self.context = legacy.create_context()
        self.context['?service'] = self
        yaql_functions.register(self.context)

        params = parameters or {}
        self.parameters = {}
        for k, v in six.iteritems(params):
            if not k or not k[0].isalpha():
                continue
            v = helpers.evaluate(v, self.context)
            self.parameters[k] = v
            self.context[k] = v

        self.forms = []
        for key, value in six.iteritems(kwargs):
            setattr(self, key, value)

        for form in forms:
            (name, field_specs, validators,
             region) = self.extract_form_data(form)
            # NOTE(kzaitsev) should be str (not unicode) under python2
            # however it also works as str under python3
            name = helpers.to_str(name)
            self._add_form(name, field_specs, validators, region)

        # Add ManageWorkflowForm
        workflow_form = catalog_forms.WorkflowManagementForm()
        if semantic_version.Version.coerce(self.spec_version) >= \
                semantic_version.Version.coerce('2.2'):
            app_name_field = workflow_form.name_field(fqn)
            workflow_form.field_specs.insert(0, app_name_field)

        self._add_form(workflow_form.name, workflow_form.field_specs,
                       workflow_form.validators)