Adds dynamic project creation to Create User.

Change-Id: If137a31ffdb64a97ff663b5327c4d8c41f6937b1
This commit is contained in:
Gabriel Hurley 2012-07-27 13:01:45 -07:00
parent d0403e9318
commit 972802edc4
5 changed files with 40 additions and 11 deletions

View File

@ -129,8 +129,8 @@ def tenant_name(request, tenant_id):
def tenant_create(request, tenant_name, description, enabled):
return keystoneclient(request, admin=True).tenants.create(tenant_name,
description,
enabled)
description,
enabled)
def tenant_get(request, tenant_id, admin=False):

View File

@ -102,10 +102,10 @@ class CreateProject(workflows.Workflow):
# create the project
try:
desc = data['description']
response = api.keystone.tenant_create(request,
tenant_name=data['name'],
description=desc,
enabled=data['enabled'])
self.object = api.keystone.tenant_create(request,
tenant_name=data['name'],
description=desc,
enabled=data['enabled'])
except:
exceptions.handle(request, ignore=True)
return False
@ -114,7 +114,7 @@ class CreateProject(workflows.Workflow):
ifcb = data['injected_file_content_bytes']
try:
api.nova.tenant_quota_update(request,
response.id,
self.object.id,
metadata_items=data['metadata_items'],
injected_file_content_bytes=ifcb,
volumes=data['volumes'],
@ -124,10 +124,9 @@ class CreateProject(workflows.Workflow):
instances=data['instances'],
injected_files=data['injected_files'],
cores=data['cores'])
return True
except:
exceptions.handle(request, _('Unable to set project quotas.'))
return True
return True
class UpdateProjectInfoAction(CreateProjectInfoAction):

View File

@ -54,6 +54,9 @@ class BaseUserForm(forms.SelfHandlingForm):
return data
ADD_PROJECT_URL = "horizon:syspanel:projects:create"
class CreateUserForm(BaseUserForm):
name = forms.CharField(label=_("User Name"))
email = forms.EmailField(label=_("Email"))
@ -66,7 +69,8 @@ class CreateUserForm(BaseUserForm):
label=_("Confirm Password"),
required=False,
widget=forms.PasswordInput(render_value=False))
tenant_id = forms.ChoiceField(label=_("Primary Project"))
tenant_id = forms.DynamicChoiceField(label=_("Primary Project"),
add_item_link=ADD_PROJECT_URL)
role_id = forms.ChoiceField(label=_("Role"))
def __init__(self, *args, **kwargs):

View File

@ -522,6 +522,14 @@ class Workflow(html.HTMLElement):
The name of a parameter used for tracking the URL to redirect to upon
completion of the workflow. Defaults to ``"next"``.
.. attribute:: object
The object (if any) which this workflow relates to. In the case of
a workflow which creates a new resource the object would be the created
resource after the relevant creation steps have been undertaken. In
the case of a workflow which updates a resource it would be the
resource being updated after it has been retrieved.
"""
__metaclass__ = WorkflowMetaclass
slug = None
@ -550,6 +558,7 @@ class Workflow(html.HTMLElement):
self.depends_on = set([])
self.contributions = set([])
self.entry_point = entry_point
self.object = None
# Put together our steps in order. Note that we pre-register
# non-default steps so that we can identify them and subsequently

View File

@ -16,11 +16,13 @@
import copy
from django import http
from django import shortcuts
from django.views import generic
from horizon import exceptions
from horizon import messages
from horizon.openstack.common import jsonutils
class WorkflowView(generic.TemplateView):
@ -101,6 +103,12 @@ class WorkflowView(generic.TemplateView):
template = self.template_name
return template
def get_object_id(self, obj):
return getattr(obj, "id", None)
def get_object_display(self, obj):
return getattr(obj, "name", None)
def add_error_to_step(self, error_msg, step):
self.step_errors[step] = error_msg
@ -133,6 +141,15 @@ class WorkflowView(generic.TemplateView):
else:
msg = workflow.format_status_message(workflow.failure_message)
messages.error(request, msg)
return shortcuts.redirect(next or workflow.get_success_url())
if "HTTP_X_HORIZON_ADD_TO_FIELD" in self.request.META:
field_id = self.request.META["HTTP_X_HORIZON_ADD_TO_FIELD"]
data = [self.get_object_id(workflow.object),
self.get_object_display(workflow.object)]
response = http.HttpResponse(jsonutils.dumps(data))
response["X-Horizon-Add-To-Field"] = field_id
return response
else:
return shortcuts.redirect(next or workflow.get_success_url())
else:
return self.render_to_response(context)