Add last step to manage redirect on form submission
If checked - stay at app catalog, go to the environment details otherwise Implements blueprint add-return-to-environment-checkbox Change-Id: Ifc1d78f003ede6638e66eac0762e6552a3d6df3e
This commit is contained in:
parent
9f0fc0331d
commit
8aac8d5f94
|
@ -0,0 +1,34 @@
|
|||
# Copyright (c) 2014 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
class WorkflowManagementForm(object):
|
||||
name = 'workflowManagement'
|
||||
field_specs = [{
|
||||
'widgetMedia':
|
||||
{'css':
|
||||
{'all': ('muranodashboard/css/checkbox.css',
|
||||
'muranodashboard/css/hide_app_name.css')
|
||||
}
|
||||
},
|
||||
'name': 'StayAtCatalog',
|
||||
'initial': False,
|
||||
'description': 'If checked, you will be returned to the '
|
||||
'Application Catalog page. If not - to the '
|
||||
'Environment page, where you can deploy'
|
||||
' the application.',
|
||||
'required': False,
|
||||
'type': 'boolean',
|
||||
'label': 'Add more applications to the environment'}]
|
||||
validators = []
|
|
@ -31,7 +31,8 @@ urlpatterns = patterns(
|
|||
'switch',
|
||||
name='switch_env'),
|
||||
url(r'^add/(?P<environment_id>[^/]+)/(?P<app_id>[^/]+)$',
|
||||
env_views.Wizard.as_view(services.get_app_forms),
|
||||
env_views.Wizard.as_view(services.get_app_forms,
|
||||
condition_dict=services.condition_getter),
|
||||
name='add'),
|
||||
url(r'^quick-add/(?P<app_id>[^/]+)$',
|
||||
'quick_deploy',
|
||||
|
|
|
@ -99,8 +99,10 @@ def create_quick_environment(request):
|
|||
def quick_deploy(request, app_id):
|
||||
env = create_quick_environment(request)
|
||||
try:
|
||||
return views.Wizard.as_view(services.get_app_forms)(
|
||||
request, app_id=app_id, environment_id=env.id, do_redirect=True)
|
||||
view = views.Wizard.as_view(services.get_app_forms,
|
||||
condition_dict=services.condition_getter)
|
||||
return view(request, app_id=app_id, environment_id=env.id,
|
||||
do_redirect=True, drop_wm_form=True)
|
||||
except:
|
||||
api.environment_delete(request, env.id)
|
||||
raise
|
||||
|
|
|
@ -13,20 +13,19 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
|
||||
|
||||
import os
|
||||
import re
|
||||
import yaml
|
||||
import yaql
|
||||
|
||||
from muranodashboard.dynamic_ui import helpers
|
||||
from .helpers import decamelize
|
||||
from muranodashboard.environments.consts import CACHE_DIR
|
||||
from muranodashboard.dynamic_ui import version
|
||||
from muranodashboard.dynamic_ui import yaql_expression
|
||||
from muranodashboard.dynamic_ui import yaql_functions
|
||||
from muranodashboard.catalog import forms as catalog_forms
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -74,10 +73,12 @@ class Service(object):
|
|||
if forms:
|
||||
for data in forms:
|
||||
name, field_specs, validators = self.extract_form_data(data)
|
||||
self._add_form(name, field_specs, validators)
|
||||
self._init_forms(field_specs, name, validators)
|
||||
|
||||
# for pickling/unpickling
|
||||
self._forms.append((name, field_specs, validators))
|
||||
# Add ManageWorkflowForm
|
||||
workflow_form = catalog_forms.WorkflowManagementForm
|
||||
self._init_forms(workflow_form.field_specs, workflow_form.name,
|
||||
workflow_form.validators)
|
||||
|
||||
def __getstate__(self):
|
||||
dct = dict((k, v) for (k, v) in self.__dict__.iteritems()
|
||||
|
@ -110,6 +111,11 @@ class Service(object):
|
|||
|
||||
self.forms.append(Form)
|
||||
|
||||
def _init_forms(self, field_specs, name, validators):
|
||||
self._add_form(name, field_specs, validators)
|
||||
# for pickling/unpickling
|
||||
self._forms.append((name, field_specs, validators))
|
||||
|
||||
@staticmethod
|
||||
def extract_form_data(form_data):
|
||||
form_name = form_data.keys()[0]
|
||||
|
@ -173,6 +179,15 @@ def import_app(request, app_id):
|
|||
return app
|
||||
|
||||
|
||||
def condition_getter(request, kwargs):
|
||||
def _func(wizard):
|
||||
return not wizard.get_wizard_flag('drop_wm_form')
|
||||
|
||||
app = import_app(request, kwargs['app_id'])
|
||||
last_form_key = str(len(app.forms) - 1)
|
||||
return {last_form_key: _func}
|
||||
|
||||
|
||||
def get_app_forms(request, kwargs):
|
||||
app = import_app(request, kwargs.get('app_id'))
|
||||
return app.forms
|
||||
|
|
|
@ -23,6 +23,7 @@ from django.contrib.formtools.wizard.views import SessionWizardView
|
|||
from django.http import HttpResponseRedirect # noqa
|
||||
from django.http import HttpResponse # noqa
|
||||
from django.views import generic
|
||||
from django.utils.decorators import classonlymethod
|
||||
from horizon import exceptions
|
||||
from horizon import tabs
|
||||
from horizon import tables
|
||||
|
@ -37,7 +38,6 @@ from tabs import ServicesTabs, DeploymentTabs, EnvironmentDetailsTabs
|
|||
from . import api
|
||||
from muranoclient.common.exceptions import HTTPUnauthorized, \
|
||||
CommunicationError, HTTPInternalServerError, HTTPForbidden, HTTPNotFound
|
||||
from django.utils.decorators import classonlymethod
|
||||
from muranodashboard.dynamic_ui.services import get_service_name
|
||||
from muranodashboard.dynamic_ui.services import get_service_field_descriptions
|
||||
from muranodashboard.dynamic_ui import helpers
|
||||
|
@ -75,6 +75,11 @@ class LazyWizard(SessionWizardView):
|
|||
_kwargs = copy.copy(initkwargs)
|
||||
|
||||
_kwargs = cls.get_initkwargs(forms, *initargs, **_kwargs)
|
||||
|
||||
cdict = _kwargs.get('condition_dict')
|
||||
if cdict and hasattr(cdict, '__call__'):
|
||||
_kwargs['condition_dict'] = cdict(request, kwargs)
|
||||
|
||||
self = cls(**_kwargs)
|
||||
if hasattr(self, 'get') and not hasattr(self, 'head'):
|
||||
self.head = self.get
|
||||
|
@ -115,6 +120,12 @@ class Wizard(hz_views.ModalFormMixin, LazyWizard):
|
|||
consts.DASHBOARD_ATTRS_KEY, {})
|
||||
storage['name'] = app_name
|
||||
|
||||
wm_form_data = service.cleaned_data.get('workflowManagement')
|
||||
if wm_form_data:
|
||||
do_redirect = not wm_form_data['StayAtCatalog']
|
||||
else:
|
||||
do_redirect = self.get_wizard_flag('do_redirect')
|
||||
|
||||
try:
|
||||
srv = api.service_create(self.request, environment_id, attributes)
|
||||
except HTTPForbidden:
|
||||
|
@ -133,7 +144,7 @@ class Wizard(hz_views.ModalFormMixin, LazyWizard):
|
|||
|
||||
messages.success(self.request, message)
|
||||
|
||||
if self._get_wizard_flag('do_redirect'):
|
||||
if do_redirect:
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
srv_id = getattr(srv, '?')['id']
|
||||
|
@ -160,7 +171,7 @@ class Wizard(hz_views.ModalFormMixin, LazyWizard):
|
|||
param = self.kwargs.get(key)
|
||||
return param if param is not None else self.request.POST.get(key)
|
||||
|
||||
def _get_wizard_flag(self, key):
|
||||
def get_wizard_flag(self, key):
|
||||
value = self._get_wizard_param(key)
|
||||
if isinstance(value, basestring):
|
||||
return value.lower() == 'true'
|
||||
|
@ -177,7 +188,8 @@ class Wizard(hz_views.ModalFormMixin, LazyWizard):
|
|||
'service_name': app.name,
|
||||
'app_id': app_id,
|
||||
'environment_id': self.kwargs.get('environment_id'),
|
||||
'do_redirect': self._get_wizard_flag('do_redirect'),
|
||||
'do_redirect': self.get_wizard_flag('do_redirect'),
|
||||
'drop_wm_form': self.get_wizard_flag('drop_wm_form'),
|
||||
'prefix': self.prefix,
|
||||
})
|
||||
return context
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
div.right h3{
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
div.right p strong {
|
||||
display: none !important;
|
||||
}
|
|
@ -58,6 +58,7 @@
|
|||
|
||||
<input type="hidden" name="wizard_goto_step" id="{{ prefix }}_val"/>
|
||||
<input type="hidden" name="do_redirect" value="{{ do_redirect }}"/>
|
||||
<input type="hidden" name="drop_wm_form" value="{{ drop_wm_form }}"/>
|
||||
{% if wizard.steps.next %}
|
||||
{% trans "Next" as next %}
|
||||
{% else %}
|
||||
|
|
Loading…
Reference in New Issue