Show name and description in the form

Change-Id: I1dbbb0fdb3000ee779ceb0b2bf20b18950f2def8
This commit is contained in:
Lennart Regebro 2014-09-29 18:58:52 +02:00
parent df5962dcc9
commit b0506f09d8
2 changed files with 34 additions and 3 deletions

View File

@ -14,7 +14,9 @@
import re
from django import forms
from django.utils import html
from django.utils.translation import ugettext_lazy as _
import netaddr
@ -114,3 +116,15 @@ class SelfHandlingFormset(forms.formsets.BaseFormSet):
else:
pass
return success
class LabelWidget(forms.Widget):
"""This is a custom widget to show context information just as text,
as readonly inputs are confusing.
Note that the field also must be required=False, as no input
is rendered, and it must be ignored in the handle() method.
"""
def render(self, name, value, attrs=None):
if value:
return html.escape(value)
return ''

View File

@ -20,10 +20,23 @@ from horizon import workflows
from openstack_dashboard.api import glance
from tuskar_ui import api
from tuskar_ui import forms as tuskar_forms
from tuskar_ui.infrastructure.flavors import utils
class UpdateRoleInfoAction(workflows.Action):
name = forms.CharField(
label=_("Name"),
widget=tuskar_forms.LabelWidget(),
required=False,
)
description = forms.CharField(
label=_("Description"),
widget=tuskar_forms.LabelWidget(),
required=False,
)
flavor = forms.ChoiceField(
label=_("Flavor"),
)
@ -36,7 +49,7 @@ class UpdateRoleInfoAction(workflows.Action):
name = _("Role Information")
help_text = _("helptext here")
slug = 'update_role_info'
help_text = _("Edit the role details. Roles define the yadyadayada ")
help_text = _("Edit the role details.")
def __init__(self, request, context, *args, **kwargs):
super(UpdateRoleInfoAction, self).__init__(request, context, *args,
@ -72,10 +85,14 @@ class UpdateRole(workflows.Workflow):
'horizon:infrastructure:roles:index')
def name(self):
return _('Edit Role "%s"') % self.context['name']
# Use context_seed here, as context['name'] returns empty
# as it's one of the fields.
return _('Edit Role "%s"') % self.context_seed['name']
def format_status_message(self, message):
return message % self.context['name']
# Use context_seed here, as context['name'] returns empty
# as it's one of the fields.
return message % self.context_seed['name']
def handle(self, request, data):
# save it!