diff --git a/horizon/api/keystone.py b/horizon/api/keystone.py index 712b4b8ae..dbf614945 100644 --- a/horizon/api/keystone.py +++ b/horizon/api/keystone.py @@ -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): diff --git a/horizon/dashboards/syspanel/projects/workflows.py b/horizon/dashboards/syspanel/projects/workflows.py index 7c5c3472b..6a7ec99b4 100644 --- a/horizon/dashboards/syspanel/projects/workflows.py +++ b/horizon/dashboards/syspanel/projects/workflows.py @@ -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): diff --git a/horizon/dashboards/syspanel/users/forms.py b/horizon/dashboards/syspanel/users/forms.py index 5e3cc3447..7077ff86e 100644 --- a/horizon/dashboards/syspanel/users/forms.py +++ b/horizon/dashboards/syspanel/users/forms.py @@ -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): diff --git a/horizon/workflows/base.py b/horizon/workflows/base.py index 0b7d49345..10c27d83c 100644 --- a/horizon/workflows/base.py +++ b/horizon/workflows/base.py @@ -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 diff --git a/horizon/workflows/views.py b/horizon/workflows/views.py index c7f2ef1a1..5a1240299 100644 --- a/horizon/workflows/views.py +++ b/horizon/workflows/views.py @@ -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)