From 0be3d0bb5a7fa9d8a90c4e1299d97e6d41b49822 Mon Sep 17 00:00:00 2001 From: Ekaterina Fedorova Date: Wed, 5 Jun 2013 18:11:33 +0400 Subject: [PATCH] Add "Edit evironment". Change-Id: I42bb058b6785dc55b48b0ea63145a1e14b042e80 --- muranodashboard/panel/api.py | 4 ++ muranodashboard/panel/tables.py | 32 ++++++++++++---- muranodashboard/panel/urls.py | 5 ++- muranodashboard/panel/views.py | 33 +++++++++++++++- muranodashboard/panel/workflows.py | 46 ++++++++++++++++++++++- muranodashboard/templates/update.html | 11 ------ muranodashboard/templates/update_env.html | 11 ++++++ 7 files changed, 119 insertions(+), 23 deletions(-) delete mode 100644 muranodashboard/templates/update.html create mode 100644 muranodashboard/templates/update_env.html diff --git a/muranodashboard/panel/api.py b/muranodashboard/panel/api.py index 0daefa67f..e5966f2f2 100644 --- a/muranodashboard/panel/api.py +++ b/muranodashboard/panel/api.py @@ -136,6 +136,10 @@ def environment_deploy(request, environment_id): return env +def environment_update(request, environment_id, name): + return muranoclient(request).environments.update(environment_id, name) + + def get_service_client(request, service_type): if service_type == 'Active Directory': return muranoclient(request).activeDirectories diff --git a/muranodashboard/panel/tables.py b/muranodashboard/panel/tables.py index 5e5dd5fa6..17e5f27bb 100644 --- a/muranodashboard/panel/tables.py +++ b/muranodashboard/panel/tables.py @@ -14,11 +14,12 @@ import logging -from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse -from horizon import exceptions +from django.utils.translation import ugettext_lazy as _ +from horizon import exceptions from horizon import tables + from muranodashboard.panel import api LOG = logging.getLogger(__name__) @@ -78,8 +79,8 @@ class CreateEnvironment(tables.LinkAction): class DeleteEnvironment(tables.DeleteAction): - data_type_singular = _("Environment") - data_type_plural = _("Environments") + data_type_singular = _('Environment') + data_type_plural = _('Environments') def allowed(self, request, environment): return True @@ -92,13 +93,28 @@ class DeleteEnvironment(tables.DeleteAction): exceptions.handle(request, msg) +class EditEnvironment(tables.LinkAction): + name = 'edit' + verbose_name = _('Edit Environment') + url = 'horizon:project:murano:update_environment' + classes = ('ajax-modal', 'btn-edit') + + def allowed(self, request, environment): + status = getattr(environment, 'status', None) + if status not in [STATUS_ID_DEPLOYING]: + return True + else: + return False + + class DeleteService(tables.DeleteAction): data_type_singular = _('Service') data_type_plural = _('Services') def allowed(self, request, environment): status = getattr(environment, 'status', None) - if status not in [STATUS_ID_DEPLOYING]: + #TODO: Change this when services deletion on deployed env fixed + if status in [STATUS_ID_PENDING]: return True return False @@ -132,13 +148,13 @@ class DeployEnvironment(tables.BatchAction): api.environment_deploy(request, environment_id) except: msg = _('Unable to deploy. Maybe this environment \ - is already deploying by someone else. Try again later') + is already deploying. Try again later') redirect = reverse("horizon:project:murano:index") exceptions.handle(request, msg, redirect=redirect) class ShowEnvironmentServices(tables.LinkAction): - name = 'edit' + name = 'show' verbose_name = _('Services') url = 'horizon:project:murano:services' @@ -181,7 +197,7 @@ class EnvironmentsTable(tables.DataTable): status_columns = ['status'] table_actions = (CreateEnvironment, DeleteEnvironment) row_actions = (ShowEnvironmentServices, DeployEnvironment, - DeleteEnvironment) + EditEnvironment, DeleteEnvironment) class ServicesTable(tables.DataTable): diff --git a/muranodashboard/panel/urls.py b/muranodashboard/panel/urls.py index c9984680d..3b72c7e4a 100644 --- a/muranodashboard/panel/urls.py +++ b/muranodashboard/panel/urls.py @@ -15,7 +15,7 @@ from django.conf.urls.defaults import patterns, url from views import IndexView, Services, CreateEnvironmentView, DetailServiceView -from views import Wizard +from views import Wizard, EditEnvironmentView from forms import WizardFormServiceType, WizardFormConfiguration VIEW_MOD = 'openstack_dashboard.dashboards.project.murano.views' @@ -28,6 +28,9 @@ urlpatterns = patterns( name='create'), url(r'^create_environment$', CreateEnvironmentView.as_view(), name='create_environment'), + url(r'^(?P[^/]+)/update_environment$', + EditEnvironmentView.as_view(), + name='update_environment'), url(r'^(?P[^/]+)/services$', Services.as_view(), name='services'), url(r'^services/(?P[^/]+)$', DetailServiceView.as_view(), diff --git a/muranodashboard/panel/views.py b/muranodashboard/panel/views.py index 3e8c0cd91..184219e8b 100644 --- a/muranodashboard/panel/views.py +++ b/muranodashboard/panel/views.py @@ -17,7 +17,7 @@ from muranoclient.common.exceptions import CommunicationError import re from django.views import generic -from django.core.urlresolvers import reverse +from django.core.urlresolvers import reverse, reverse_lazy from django.utils.translation import ugettext_lazy as _ from django.contrib.formtools.wizard.views import SessionWizardView @@ -30,7 +30,7 @@ from horizon.forms.views import ModalFormMixin from muranodashboard.panel import api from tables import EnvironmentsTable, ServicesTable -from workflows import CreateEnvironment +from workflows import CreateEnvironment, UpdateEnvironment from tabs import ServicesTabs from forms import WizardFormADConfiguration from forms import WizardFormIISConfiguration @@ -224,3 +224,32 @@ class CreateEnvironmentView(workflows.WorkflowView): initial['project_id'] = self.request.user.tenant_id initial['user_id'] = self.request.user.id return initial + + +class EditEnvironmentView(workflows.WorkflowView): + workflow_class = UpdateEnvironment + template_name = 'update_env.html' + success_url = reverse_lazy("horizon:project:murano:index") + + def get_context_data(self, **kwargs): + context = super(EditEnvironmentView, self).get_context_data(**kwargs) + context["environment_id"] = self.kwargs['environment_id'] + return context + + def get_object(self, *args, **kwargs): + if not hasattr(self, "_object"): + environment_id = self.kwargs['environment_id'] + try: + self._object = \ + api.environment_get(self.request, environment_id) + except: + redirect = reverse("horizon:project:murano:index") + msg = _('Unable to retrieve environment details.') + exceptions.handle(self.request, msg, redirect=redirect) + return self._object + + def get_initial(self): + initial = super(EditEnvironmentView, self).get_initial() + initial.update({'environment_id': self.kwargs['environment_id'], + 'name': getattr(self.get_object(), 'name', '')}) + return initial diff --git a/muranodashboard/panel/workflows.py b/muranodashboard/panel/workflows.py index 822e9ff35..942263786 100644 --- a/muranodashboard/panel/workflows.py +++ b/muranodashboard/panel/workflows.py @@ -62,7 +62,7 @@ class ConfigureEnvironmentAction(workflows.Action): class ConfigureEnvironment(workflows.Step): action_class = ConfigureEnvironmentAction - contibutes = ('name',) + contributes = ('name',) def contribute(self, data, context): if data: @@ -90,3 +90,47 @@ class CreateEnvironment(workflows.Workflow): except: exceptions.handle(request) return False + + +class UpdateEnvironmentInfoAction(workflows.Action): + name = forms.CharField(required=True) + + def handle(self, request, data): + try: + api.environment_update(request, + data['environment_id'], + data['name']) + + except: + exceptions.handle(request, ignore=True) + return False + return True + + class Meta: + name = _("Environment Info") + slug = 'environment_info' + help_text = _("From here you can edit the environment details.") + + +class UpdateEnvironmentInfo(workflows.Step): + action_class = UpdateEnvironmentInfoAction + depends_on = ('environment_id',) + contributes = ('name',) + + def contribute(self, data, context): + if data: + context['name'] = data.get('name', '') + return context + + +class UpdateEnvironment(workflows.Workflow): + slug = "update_environment" + name = _("Edit Environment") + finalize_button_name = _("Save") + success_message = _('Modified environment "%s".') + failure_message = _('Unable to modify environment "%s".') + success_url = "horizon:project:murano:index" + default_steps = (UpdateEnvironmentInfo,) + + def format_status_message(self, message): + return message % self.context.get('name', 'unknown environment') diff --git a/muranodashboard/templates/update.html b/muranodashboard/templates/update.html deleted file mode 100644 index aba3dc9ab..000000000 --- a/muranodashboard/templates/update.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends 'base.html' %} -{% load i18n %} -{% block title %}{% trans "Update Instance" %}{% endblock %} - -{% block page_header %} - {% include "horizon/common/_page_header.html" with title=_("Update Instance") %} -{% endblock page_header %} - -{% block main %} - {% include 'project/instances/_update.html' %} -{% endblock %} diff --git a/muranodashboard/templates/update_env.html b/muranodashboard/templates/update_env.html new file mode 100644 index 000000000..5b851dc95 --- /dev/null +++ b/muranodashboard/templates/update_env.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block title %}{% trans "Edit Environment" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Edit Environment") %} +{% endblock page_header %} + +{% block main %} + {% include 'horizon/common/_workflow.html' %} +{% endblock %}