Exemplo n.º 1
0
    def get_form(self, form_class):

        stage_configurations = self.stage.get_queryset_configurations(prompt_me_for_input=True)

        form = form_class(**self.get_form_kwargs())

        # We want to inject fields into the form for the configurations they've marked as prompt
        for config in stage_configurations:
            if config.task_argument and config.task_name != self.task_name:
                continue

            str_config_key = 'configuration_value_for_{}'.format(config.key)

            if config.data_type == config.BOOLEAN_TYPE:
                field = BooleanField(widget=Select(choices=((False, 'False'), (True, 'True'))))
                field.coerce=lambda x: x == 'True',
            elif config.data_type == config.NUMBER_TYPE:
                field = FloatField()
            else:
                field = CharField()

                if config.sensitive_value:
                    field.widget = PasswordInput

                if config.task_argument:
                    field.label = 'Argument value for ' + config.key

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        return form
Exemplo n.º 2
0
    def get_form(self, form_class):

        stage_configurations = self.stage.get_queryset_configurations()

        form = form_class(**self.get_form_kwargs())

        used_arg_names = []

        # We want to inject fields into the form for the configurations they've marked as prompt
        for config in stage_configurations:
            if config.task_argument and config.task_name != self.task_name:
                continue

            if not config.prompt_me_for_input:
                if config.task_argument:
                    used_arg_names.append(config.key)
                continue

            str_config_key = 'configuration_value_for_{}'.format(config.key)

            if config.data_type == config.BOOLEAN_TYPE:
                field = BooleanField(widget=Select(choices=((False, 'False'), (True, 'True'))))
                field.coerce=lambda x: x == 'True',
            elif config.data_type == config.NUMBER_TYPE:
                field = FloatField()
            else:
                field = CharField()

                if config.sensitive_value:
                    field.widget = PasswordInput()

                if config.task_argument:
                    used_arg_names.append(config.key)
                    field.label = 'Argument value for ' + config.key

            field.initial = config.value

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        task_details = get_task_details(self.stage.project, self.task_name)

        for arg in task_details[2]:
            if isinstance(arg, tuple):
                name, default = arg
            else:
                name, default = arg, None

            if name in used_arg_names:
                continue

            str_config_key = 'configuration_value_for_{}'.format(name)

            field = CharField(label='Argument value for ' + name, initial=default)

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        return form
Exemplo n.º 3
0
    def get_form(self, form_class):

        stage_configurations = self.stage.get_queryset_configurations()

        form = form_class(**self.get_form_kwargs())

        used_arg_names = []

        # We want to inject fields into the form for the configurations they've marked as prompt
        for config in stage_configurations:
            if config.task_argument and config.task_name != self.task_name:
                continue

            if not config.prompt_me_for_input:
                if config.task_argument:
                    used_arg_names.append(config.key)
                continue

            str_config_key = 'configuration_value_for_{}'.format(config.key)

            if config.data_type == config.BOOLEAN_TYPE:
                field = BooleanField(widget=Select(choices=((False, 'False'), (True, 'True'))))
                field.coerce=lambda x: x == 'True',
            elif config.data_type == config.NUMBER_TYPE:
                field = FloatField()
            else:
                field = CharField()

                if config.sensitive_value:
                    field.widget = PasswordInput()

                if config.task_argument:
                    used_arg_names.append(config.key)
                    field.label = 'Argument value for ' + config.key

            field.initial = config.value

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        task_details = get_task_details(self.stage.project, self.task_name)

        for arg in task_details[2]:
            if isinstance(arg, tuple):
                name, default = arg
            else:
                name, default = arg, None

            if name in used_arg_names:
                continue

            str_config_key = 'configuration_value_for_{}'.format(name)

            field = CharField(label='Argument value for ' + name, initial=default)

            form.fields[str_config_key] = field
            form.helper.layout.fields.insert(len(form.helper.layout.fields)-1, str_config_key)

        return form