本文整理汇总了Python中horizon.forms.ChoiceField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.ChoiceField方法的具体用法?Python forms.ChoiceField怎么用?Python forms.ChoiceField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizon.forms
的用法示例。
在下文中一共展示了forms.ChoiceField方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def __init__(self, request, *args, **kwargs):
if args:
self.backup_id = args[0].get('backup', None)
else:
self.backup_id = None
super(SetInstanceDetailsAction, self).__init__(request,
*args,
**kwargs)
# Add this field to the end after the dynamic fields
self.fields['locality'] = forms.ChoiceField(
label=_("Locality"),
choices=[("", "None"),
("affinity", "affinity"),
("anti-affinity", "anti-affinity")],
required=False,
help_text=_("Specify whether future replicated instances will "
"be created on the same hypervisor (affinity) or on "
"different hypervisors (anti-affinity). "
"This value is ignored if the instance to be "
"launched is a replica.")
)
示例2: _add_datastore_flavor_field
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def _add_datastore_flavor_field(self,
request,
datastore,
datastore_version):
name = self._build_widget_field_name(datastore, datastore_version)
attr_key = 'data-datastore-' + name
field_name = self._build_flavor_field_name(datastore,
datastore_version)
self.fields[field_name] = forms.ChoiceField(
label=_("Flavor"),
help_text=_("Size of image to launch."),
required=False,
widget=forms.Select(attrs={
'class': 'switched',
'data-switch-on': 'datastore',
attr_key: _("Flavor")
}))
valid_flavors = self.datastore_flavors(request,
datastore,
datastore_version)
if valid_flavors:
self.fields[field_name].choices = instance_utils.sort_flavor_list(
request, valid_flavors)
示例3: _add_datastore_flavor_field
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def _add_datastore_flavor_field(self,
request,
datastore,
datastore_version):
name = self._build_widget_field_name(datastore, datastore_version)
attr_key = 'data-datastore-' + name
field = forms.ChoiceField(
label=_("Flavor"),
help_text=_("Size of image to launch."),
required=False,
widget=forms.Select(attrs={
'class': 'switched',
'data-switch-on': 'datastore',
attr_key: _("Flavor")
}))
valid_flavors = self.datastore_flavors(request,
datastore,
datastore_version)
if valid_flavors:
field.choices = instance_utils.sort_flavor_list(
request, valid_flavors)
return name, field
示例4: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
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
)
示例5: _generate_plugin_version_fields
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def _generate_plugin_version_fields(self, sahara):
plugins = sahara.plugins.list()
plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]
self.fields["plugin_name"] = forms.ChoiceField(
label=_("Plugin Name"),
choices=plugin_choices,
widget=forms.Select(attrs={"class": "plugin_name_choice"}))
for plugin in plugins:
field_name = plugin.name + "_version"
choice_field = forms.ChoiceField(
label=_("Version"),
choices=[(version, version) for version in plugin.versions],
widget=forms.Select(
attrs={"class": "plugin_version_choice "
+ field_name + "_choice"})
)
self.fields[field_name] = choice_field
示例6: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def __init__(self, *args, **kwargs):
super(AssociateIPAction, self).__init__(*args, **kwargs)
if api.base.is_service_enabled(self.request, 'network'):
label = _("Port to be associated")
else:
label = _("Instance to be associated")
self.fields['instance_id'].label = label
# If AssociateIP is invoked from instance menu, instance_id parameter
# is passed in URL. In Neutron based Floating IP implementation
# an association target is not an instance but a port, so we need
# to get an association target based on a received instance_id
# and set the initial value of instance_id ChoiceField.
q_instance_id = self.request.GET.get('instance_id')
if q_instance_id:
targets = self._get_target_list()
target_id = api.network.floating_ip_target_get_by_instance(
self.request, q_instance_id, targets)
self.initial['instance_id'] = target_id
示例7: _init_fields
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
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."))
示例8: _init_fields
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
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)
示例9: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def __init__(self, request, *args, **kwargs):
super(Create, self).__init__(request, *args, **kwargs)
self.neutron_enabled = base.is_service_enabled(request, 'network')
net_choices = network.network_list(request)
if self.neutron_enabled:
self.fields['neutron_net_id'] = forms.ChoiceField(
choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
for choice in net_choices],
label=_("Neutron Net"), widget=forms.Select(
attrs={'class': 'switchable', 'data-slug': 'net'}))
for net in net_choices:
# For each network create switched choice field with
# the its subnet choices
subnet_field_name = 'subnet-choices-%s' % net.id
subnet_field = forms.ChoiceField(
choices=(), label=_("Neutron Subnet"),
widget=forms.Select(attrs={
'class': 'switched',
'data-switch-on': 'net',
'data-net-%s' % net.id: _("Neutron Subnet")
}))
self.fields[subnet_field_name] = subnet_field
subnet_choices = neutron.subnet_list(
request, network_id=net.id)
self.fields[subnet_field_name].choices = [
(' ', ' ')] + [(choice.id, choice.name_or_id)
for choice in subnet_choices]
else:
self.fields['nova_net_id'] = forms.ChoiceField(
choices=[(' ', ' ')] + [(choice.id, choice.name_or_id)
for choice in net_choices],
label=_("Nova Net"), widget=forms.Select(
attrs={'class': 'switched', 'data-slug': 'net'}))
示例10: build_control
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
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)
示例11: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
def __init__(self, request, *args, **kwargs):
super(SelectPluginAction, self).__init__(request, *args, **kwargs)
try:
plugins = saharaclient.plugin_list(request)
except Exception:
plugins = []
exceptions.handle(request,
_("Unable to fetch plugin list."))
plugin_choices = [(plugin.name, plugin.title) for plugin in plugins]
self.fields["plugin_name"] = forms.ChoiceField(
label=_("Plugin name"),
choices=plugin_choices,
widget=forms.Select(attrs={"class": "plugin_name_choice"}))
for plugin in plugins:
field_name = plugin.name + "_version"
choice_field = forms.ChoiceField(
label=_("Version"),
choices=[(version, version) for version in plugin.versions],
widget=forms.Select(
attrs={"class": "plugin_version_choice "
+ field_name + "_choice"})
)
self.fields[field_name] = choice_field
示例12: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import ChoiceField [as 别名]
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))