本文整理汇总了Python中horizon.forms.Select方法的典型用法代码示例。如果您正苦于以下问题:Python forms.Select方法的具体用法?Python forms.Select怎么用?Python forms.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizon.forms
的用法示例。
在下文中一共展示了forms.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_datastore_flavor_field
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [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)
示例2: populate_config_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_config_choices(self, request, context):
try:
configs = api.trove.configuration_list(request)
config_name = "%(name)s (%(datastore)s - %(version)s)"
choices = [(c.id,
config_name % {'name': c.name,
'datastore': c.datastore_name,
'version': c.datastore_version_name})
for c in configs]
except Exception:
choices = []
if choices:
choices.insert(0, ("", _("Select configuration")))
else:
choices.insert(0, ("", _("No configurations available")))
return choices
示例3: populate_backup_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_backup_choices(self, request, context):
try:
choices = []
backups = api.trove.backup_list(request)
for b in backups:
if self.backup_id and b.id != self.backup_id:
continue
if b.status == 'COMPLETED':
choices.append((b.id, b.name))
except Exception:
choices = []
if choices:
choices.insert(0, ("", _("Select backup")))
else:
choices.insert(0, ("", _("No backups available")))
return choices
示例4: _add_datastore_flavor_field
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [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
示例5: set_notification_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def set_notification_choices(self, request):
try:
notifications = api.monitor.notification_list(request)
except Exception as e:
notifications = []
exceptions.handle(request,
_('Unable to retrieve notifications: %s') % e)
notification_choices = [(notification['id'], notification['name'])
for notification in notifications]
if notification_choices:
if len(notification_choices) > 1:
notification_choices.insert(
0, ("", six.text_type(_("Select Notification"))))
else:
notification_choices.insert(
0, ("", six.text_type(_("No notifications available."))))
self.fields['notifications'].choices = notification_choices
示例6: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def __init__(self, request, *args, **kwargs):
super(AddVipAction, self).__init__(request, *args, **kwargs)
tenant_id = request.user.tenant_id
subnet_id_choices = [('', _("Select a Subnet"))]
try:
networks = api.neutron.network_list_for_tenant(request, tenant_id)
except Exception:
exceptions.handle(request,
_('Unable to retrieve networks list.'))
networks = []
for n in networks:
for s in n['subnets']:
subnet_id_choices.append((s.id, s.cidr))
self.fields['subnet_id'].choices = subnet_id_choices
protocol_choices = [('', _("Select a Protocol"))]
[protocol_choices.append((p, p)) for p in AVAILABLE_PROTOCOLS]
self.fields['protocol'].choices = protocol_choices
session_persistence_choices = [('', _("No Session Persistence"))]
for mode in ('SOURCE_IP', 'HTTP_COOKIE', 'APP_COOKIE'):
session_persistence_choices.append((mode.lower(), mode))
self.fields[
'session_persistence'].choices = session_persistence_choices
示例7: populate_monitor_id_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_monitor_id_choices(self, request, context):
self.fields['monitor_id'].label = _("Select a monitor template "
"for %s") % context['pool_name']
monitor_id_choices = [('', _("Select a Monitor"))]
try:
tenant_id = self.request.user.tenant_id
monitors = api.lbaas.pool_health_monitor_list(request,
tenant_id=tenant_id)
pool_monitors_ids = [pm.id for pm in context['pool_monitors']]
for m in monitors:
if m.id not in pool_monitors_ids:
display_name = utils.get_monitor_display_name(m)
monitor_id_choices.append((m.id, display_name))
except Exception:
exceptions.handle(request,
_('Unable to retrieve monitors list.'))
self.fields['monitor_id'].choices = monitor_id_choices
return monitor_id_choices
示例8: _generate_plugin_version_fields
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [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
示例9: populate_image_id_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_image_id_choices(self, request, context):
choices = []
images = image_utils.get_available_images(request,
context.get('project_id'),
self._images_cache)
for image in images:
image.bytes = image.size
image.volume_size = max(
image.min_disk, functions.bytes_to_gigabytes(image.bytes))
choices.append((image.id, image))
if context.get('image_id') == image.id and \
'volume_size' not in context:
context['volume_size'] = image.volume_size
if choices:
choices.sort(key=lambda c: c[1].name)
choices.insert(0, ("", _("Select Image")))
else:
choices.insert(0, ("", _("No images available")))
return choices
示例10: populate_volume_id_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_volume_id_choices(self, request, context):
volumes = []
try:
if base.is_service_enabled(request, 'volume'):
available = api.cinder.VOLUME_STATE_AVAILABLE
volumes = [self._get_volume_display_name(v)
for v in cinder.volume_list(self.request,
search_opts=dict(status=available, bootable=1))]
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve list of volumes.'))
if volumes:
volumes.insert(0, ("", _("Select Volume")))
else:
volumes.insert(0, ("", _("No volumes available")))
return volumes
示例11: populate_volume_snapshot_id_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_volume_snapshot_id_choices(self, request, context):
snapshots = []
try:
if base.is_service_enabled(request, 'volume'):
available = api.cinder.VOLUME_STATE_AVAILABLE
snapshots = [self._get_volume_display_name(s)
for s in cinder.volume_snapshot_list(
self.request, search_opts=dict(status=available))]
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve list of volume '
'snapshots.'))
if snapshots:
snapshots.insert(0, ("", _("Select Volume Snapshot")))
else:
snapshots.insert(0, ("", _("No volume snapshots available")))
return snapshots
示例12: populate_master_choices
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def populate_master_choices(self, request, context):
try:
instances = self._get_instances()
choices = sorted([(i.id, i.name) for i in
instances if i.status == 'ACTIVE'],
key=lambda i: i[1])
except Exception:
choices = []
if choices:
choices.insert(0, ("", _("Select instance")))
else:
choices.insert(0, ("", _("No instances available")))
return choices
示例13: _init_fields
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [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."))
示例14: __init__
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [as 别名]
def __init__(self, initial, attrs=None):
comparators = [('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<=')]
func = [('min', _('min')), ('max', _('max')), ('sum', _('sum')),
('count', _('count')), ('avg', _('avg'))]
_widgets = (
django_forms.widgets.Select(attrs=attrs, choices=func),
ExpressionWidget(initial, attrs={}),
django_forms.widgets.Select(attrs=attrs, choices=comparators),
django_forms.widgets.TextInput(),
)
super(SimpleExpressionWidget, self).__init__(_widgets, attrs)
示例15: _init_fields
# 需要导入模块: from horizon import forms [as 别名]
# 或者: from horizon.forms import Select [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)