Python horizon.forms.CharField() Examples
The following are 22
code examples of horizon.forms.CharField().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
horizon.forms
, or try the search function
.
Example #1
Source File: forms.py From cloudkitty-dashboard with Apache License 2.0 | 6 votes |
def __init__(self, request, *args, **kwargs): super(CreateFieldForm, self).__init__(request, *args, **kwargs) service_id = kwargs['initial']['service_id'] manager = api.cloudkittyclient(request).rating.hashmap service = manager.get_service(service_id=service_id) self.fields['service_name'].initial = service['name'] try: fields = manager.get_field(service_id=service['name'])['fields'] except exceptions.NotFound: fields = None if fields: fields = api.identify(fields) choices = sorted([(field, field) for field in fields['metadata']]) self.fields['field'] = forms.DynamicChoiceField( label=_("Field")) self.fields['field'].choices = choices else: self.fields['field'] = forms.CharField( label=_("Field"))
Example #2
Source File: create.py From avos with Apache License 2.0 | 6 votes |
def __init__(self, request, *args, **kwargs): super(GeneralConfigAction, self).__init__(request, *args, **kwargs) plugin, hadoop_version = whelpers.\ get_plugin_and_hadoop_version(request) if saharaclient.base.is_service_enabled(request, 'network'): self.fields["neutron_management_network"] = forms.ChoiceField( label=_("Neutron Management Network"), choices=self.populate_neutron_management_network_choices( request, {}) ) self.fields["plugin_name"] = forms.CharField( widget=forms.HiddenInput(), initial=plugin ) self.fields["hadoop_version"] = forms.CharField( widget=forms.HiddenInput(), initial=hadoop_version )
Example #3
Source File: create.py From freezer-web-ui with Apache License 2.0 | 6 votes |
def __init__(self, request, *args, **kwargs): super(ClientsConfigurationAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to retrieve client list.') job_id = args[0].get('job_id', None) default_role_name = self.get_default_role_field_name() self.fields[default_role_name] = forms.CharField(required=False) self.fields[default_role_name].initial = 'member' all_clients = [] try: all_clients = freezer_api.Client(request).list() except Exception: exceptions.handle(request, err_msg) client_list = [(c.uuid, c.hostname) for c in all_clients] field_name = self.get_member_field_name('member') if not job_id: self.fields[field_name] = forms.MultipleChoiceField() self.fields[field_name].choices = client_list
Example #4
Source File: workflow_helpers.py From avos with Apache License 2.0 | 5 votes |
def build_control(parameter): attrs = {"priority": parameter.priority, "placeholder": parameter.default_value} if parameter.param_type == "string": return forms.CharField( widget=forms.TextInput(attrs=attrs), label=parameter.name, required=(parameter.required and parameter.default_value is None), help_text=parameter.description, initial=parameter.initial_value) if parameter.param_type == "int": return forms.IntegerField( widget=forms.TextInput(attrs=attrs), label=parameter.name, required=parameter.required, help_text=parameter.description, initial=parameter.initial_value) elif parameter.param_type == "bool": return forms.BooleanField( widget=forms.CheckboxInput(attrs=attrs), label=parameter.name, required=False, initial=parameter.initial_value, help_text=parameter.description) elif parameter.param_type == "dropdown": return forms.ChoiceField( widget=forms.Select(attrs=attrs), label=parameter.name, required=parameter.required, choices=parameter.choices, help_text=parameter.description)
Example #5
Source File: workflows.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(ManageAggregateHostsAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to get the available hosts') default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) aggregate_id = self.initial['id'] aggregate = api.nova.aggregate_get(request, aggregate_id) current_aggregate_hosts = aggregate.hosts hosts = [] try: hosts = api.nova.host_list(request) except Exception: exceptions.handle(request, err_msg) host_names = [] for host in hosts: if host.host_name not in host_names and host.service == u'compute': host_names.append(host.host_name) host_names.sort() self.fields[field_name].choices = \ [(host_name, host_name) for host_name in host_names] self.fields[field_name].initial = current_aggregate_hosts
Example #6
Source File: workflows.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(AddHostsToAggregateAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to get the available hosts') default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) hosts = [] try: hosts = api.nova.host_list(request) except Exception: exceptions.handle(request, err_msg) host_names = [] for host in hosts: if host.host_name not in host_names and host.service == u'compute': host_names.append(host.host_name) host_names.sort() self.fields[field_name].choices = \ [(host_name, host_name) for host_name in host_names]
Example #7
Source File: forms.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(CreateSnapshotForm, self).__init__(request, *args, **kwargs) # populate volume_id volume_id = kwargs.get('initial', {}).get('volume_id', []) self.fields['volume_id'] = forms.CharField(widget=forms.HiddenInput(), initial=volume_id)
Example #8
Source File: forms.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): super(AttachForm, self).__init__(*args, **kwargs) # Hide the device field if the hypervisor doesn't support it. if not nova.can_set_mount_point(): self.fields['device'].widget = forms.widgets.HiddenInput() # populate volume_id volume = kwargs.get('initial', {}).get("volume", None) if volume: volume_id = volume.id else: volume_id = None self.fields['volume_id'] = forms.CharField(widget=forms.HiddenInput(), initial=volume_id) # Populate instance choices instance_list = kwargs.get('initial', {}).get('instances', []) instances = [] for instance in instance_list: if instance.status in tables.VOLUME_ATTACH_READY_STATES and \ not any(instance.id == att["server_id"] for att in volume.attachments): instances.append((instance.id, '%s (%s)' % (instance.name, instance.id))) if instances: instances.insert(0, ("", _("Select an instance"))) else: instances = (("", _("No instances available")),) self.fields['instance'].choices = instances
Example #9
Source File: forms.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(DecryptPasswordInstanceForm, self).__init__(request, *args, **kwargs) instance_id = kwargs.get('initial', {}).get('instance_id') self.fields['instance_id'].initial = instance_id keypair_name = kwargs.get('initial', {}).get('keypair_name') self.fields['keypair_name'].initial = keypair_name try: result = api.nova.get_password(request, instance_id) if not result: _unavailable = _("Instance Password is not set" " or is not yet available") self.fields['encrypted_password'].initial = _unavailable else: self.fields['encrypted_password'].initial = result self.fields['private_key_file'] = forms.FileField( label=_('Private Key File'), widget=forms.FileInput()) self.fields['private_key'] = forms.CharField( widget=forms.widgets.Textarea(), label=_("OR Copy/Paste your Private Key")) _attrs = {'readonly': 'readonly'} self.fields['decrypted_password'] = forms.CharField( widget=forms.widgets.TextInput(_attrs), label=_("Password"), required=False) except Exception: redirect = reverse('horizon:project:instances:index') _error = _("Unable to retrieve instance password.") exceptions.handle(request, _error, redirect=redirect)
Example #10
Source File: launch.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(JobExecutionGeneralConfigAction, self).__init__(request, *args, **kwargs) if request.REQUEST.get("job_id", None) is None: self.fields["job"] = forms.ChoiceField( label=_("Job")) self.fields["job"].choices = self.populate_job_choices(request) else: self.fields["job"] = forms.CharField( widget=forms.HiddenInput(), initial=request.REQUEST.get("job_id", None))
Example #11
Source File: create.py From avos with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(GeneralConfigAction, self).__init__(request, *args, **kwargs) plugin, hadoop_version = whelpers.\ get_plugin_and_hadoop_version(request) self.fields["plugin_name"] = forms.CharField( widget=forms.HiddenInput(), initial=plugin ) self.fields["hadoop_version"] = forms.CharField( widget=forms.HiddenInput(), initial=hadoop_version )
Example #12
Source File: workflow_helpers.py From avos with Apache License 2.0 | 5 votes |
def build_node_group_fields(action, name, template, count, serialized=None): action.fields[name] = forms.CharField( label=_("Name"), widget=forms.TextInput()) action.fields[template] = forms.CharField( label=_("Node group cluster"), widget=forms.HiddenInput()) action.fields[count] = forms.IntegerField( label=_("Count"), min_value=0, widget=forms.HiddenInput()) action.fields[serialized] = forms.CharField( widget=forms.HiddenInput())
Example #13
Source File: forms.py From mistral-dashboard with Apache License 2.0 | 5 votes |
def _generate_parameter_fields(self, list): self.workflow_parameters = [] for entry in list.split(","): label, _, default = entry.partition("=") label = label.strip() if label != '': self.workflow_parameters.append(label) if default == "None": default = None required = False else: required = True self.fields[label] = forms.CharField(label=label, required=required, initial=default)
Example #14
Source File: test_forms.py From manila-ui with Apache License 2.0 | 5 votes |
def test___init__(self, extra_specs_dict_input, extra_specs_str_output): form = self._get_form({'extra_specs': extra_specs_dict_input}) for expected_extra_spec in extra_specs_str_output: self.assertIn(expected_extra_spec, form.initial['extra_specs']) self.assertIn('extra_specs', list(form.fields.keys())) self.assertTrue( isinstance(form.fields['extra_specs'], horizon_forms.CharField))
Example #15
Source File: workflows.py From manila-ui with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(AddProjectAction, self).__init__(request, *args, **kwargs) default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) share_type_id = self.initial['id'] # Get list of existing projects try: projects, __ = keystone.tenant_list(request) except Exception: err_msg = _('Unable to get list of projects.') exceptions.handle(request, err_msg) # Get list of projects with access to this Share Type try: share_type = manila.share_type_get(request, share_type_id) self.share_type_name = share_type.name projects_initial = manila.share_type_access_list( request, share_type) except Exception: err_msg = _('Unable to get information about share type access.') exceptions.handle(request, err_msg) self.fields[field_name].choices = [ (project.id, project.name or project.id) for project in projects] self.fields[field_name].initial = [ pr.project_id for pr in projects_initial] self.projects_initial = set(self.fields[field_name].initial)
Example #16
Source File: forms.py From manila-ui with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(self.__class__, self).__init__(request, *args, **kwargs) # populate share_group_id sg_id = kwargs.get('initial', {}).get('share_group_id', []) self.fields['share_group_id'] = forms.CharField( widget=forms.HiddenInput(), initial=sg_id)
Example #17
Source File: workflows.py From manila-ui with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(AddSecurityServiceAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to get the security services hosts') default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) share_network_id = self.initial['id'] security_services = manila.share_network_security_service_list( request, share_network_id) sec_services_initial = [sec_service.id for sec_service in security_services] sec_services = [] try: sec_services = manila.security_service_list(request) except Exception: exceptions.handle(request, err_msg) sec_services_choices = [(sec_service.id, sec_service.name or sec_service.id) for sec_service in sec_services] self.fields[field_name].choices = sec_services_choices self.fields[field_name].initial = sec_services_initial
Example #18
Source File: forms.py From manila-ui with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(CreateReplicaForm, self).__init__(request, *args, **kwargs) # populate share_id share_id = kwargs.get('initial', {}).get('share_id', []) self.fields['share_id'] = forms.CharField(widget=forms.HiddenInput(), initial=share_id) availability_zones = manila.availability_zone_list(request) self.fields['availability_zone'].choices = ( [(az.name, az.name) for az in availability_zones])
Example #19
Source File: forms.py From manila-ui with Apache License 2.0 | 5 votes |
def __init__(self, request, *args, **kwargs): super(self.__class__, self).__init__(request, *args, **kwargs) # populate share_id share_id = kwargs.get('initial', {}).get('share_id', []) self.fields['share_id'] = forms.CharField( widget=forms.HiddenInput(), initial=share_id)
Example #20
Source File: forms.py From monasca-ui with Apache License 2.0 | 5 votes |
def _init_fields(self, readOnly=False, create=False, initial=None): required = True textWidget = None textAreaWidget = forms.Textarea(attrs={'class': 'large-text-area'}) choiceWidget = forms.Select if create: expressionWidget = SimpleExpressionWidget(initial) notificationWidget = NotificationCreateWidget() else: expressionWidget = textAreaWidget notificationWidget = NotificationCreateWidget() self.fields['name'] = forms.CharField(label=_("Name"), required=required, max_length=250, widget=textWidget) self.fields['expression'] = forms.CharField(label=_("Expression"), required=required, widget=expressionWidget) self.fields['description'] = forms.CharField(label=_("Description"), required=False, widget=textAreaWidget) sev_choices = [("LOW", _("Low")), ("MEDIUM", _("Medium")), ("HIGH", _("High")), ("CRITICAL", _("Critical"))] self.fields['severity'] = forms.ChoiceField(label=_("Severity"), choices=sev_choices, widget=choiceWidget, required=False) self.fields['state'] = forms.CharField(label=_("State"), required=False, widget=textWidget) self.fields['actions_enabled'] = \ forms.BooleanField(label=_("Notifications Enabled"), required=False, initial=True) self.fields['notifications'] = NotificationField( label=_("Notifications"), required=False, widget=notificationWidget)
Example #21
Source File: forms.py From monasca-ui with Apache License 2.0 | 5 votes |
def _init_fields(self, readOnly=False, create=False): required = True textWidget = None selectWidget = None readOnlyTextInput = READONLY_TEXTINPUT readOnlySelectInput = forms.Select(attrs={'disabled': 'disabled'}) if readOnly: required = False textWidget = readOnlyTextInput selectWidget = readOnlySelectInput choices = [(n['type'], n['type'].capitalize()) for n in self.notification_types] choices = sorted(choices, key=lambda c: c[0]) period_choices = [(0, '0'), (60, '60')] self.fields['name'] = forms.CharField(label=_("Name"), required=required, max_length="250", widget=textWidget, help_text=_("A descriptive name of " "the notification method.")) self.fields['type'] = forms.ChoiceField( label=_("Type"), required=required, widget=selectWidget, choices=choices, initial=constants.NotificationType.EMAIL, help_text=_("The type of notification method (i.e. email).")) self.fields['address'] = forms.CharField(label=_("Address"), required=required, max_length="512", widget=textWidget, help_text=_("The email/url address to notify.")) self.fields['period'] = forms.ChoiceField(label=_("Period"), widget=selectWidget, choices=period_choices, initial=0, required=required, help_text=_("The notification period."))
Example #22
Source File: workflows.py From avos with Apache License 2.0 | 4 votes |
def __init__(self, request, *args, **kwargs): super(UpdateFlavorAccessAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to retrieve flavor access list. ' 'Please try again later.') context = args[0] default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) # Get list of available projects. all_projects = [] try: all_projects, has_more = api.keystone.tenant_list(request) except Exception: exceptions.handle(request, err_msg) projects_list = [(project.id, project.name) for project in all_projects] self.fields[field_name].choices = projects_list # If we have a POST from the CreateFlavor workflow, the flavor id # isn't an existing flavor. For the UpdateFlavor case, we don't care # about the access list for the current flavor anymore as we're about # to replace it. if request.method == 'POST': return # Get list of flavor projects if the flavor is not public. flavor_id = context.get('flavor_id') flavor_access = [] try: if flavor_id: flavor = api.nova.flavor_get(request, flavor_id) if not flavor.is_public: flavor_access = [project.tenant_id for project in api.nova.flavor_access_list(request, flavor_id)] except Exception: exceptions.handle(request, err_msg) self.fields[field_name].initial = flavor_access