From 8b18f83a5e35d86d97e8d115638aeca3e117155c Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Tue, 20 Jan 2015 13:39:10 +0100 Subject: [PATCH] Refactor StackMixin and RoleMixin Move them out to infrastructure/views.py. Change-Id: If05ffd27a7a3a3cf5cc140b8594c81bbf206b868 --- tuskar_ui/infrastructure/overview/views.py | 19 +++++----------- tuskar_ui/infrastructure/roles/views.py | 26 +++++----------------- tuskar_ui/infrastructure/views.py | 20 +++++++++++++++++ 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/tuskar_ui/infrastructure/overview/views.py b/tuskar_ui/infrastructure/overview/views.py index 1302fa03a..3a125ea7d 100644 --- a/tuskar_ui/infrastructure/overview/views.py +++ b/tuskar_ui/infrastructure/overview/views.py @@ -21,10 +21,10 @@ import django.utils.text from django.utils.translation import ugettext_lazy as _ import heatclient import horizon.forms -from horizon.utils import memoized from tuskar_ui import api from tuskar_ui.infrastructure.overview import forms +from tuskar_ui.infrastructure import views INDEX_URL = 'horizon:infrastructure:overview:index' @@ -98,14 +98,7 @@ def _get_role_data(plan, stack, form, role): return data -class StackMixin(object): - @memoized.memoized - def get_stack(self): - plan = api.tuskar.Plan.get_the_plan(self.request) - return api.heat.Stack.get_by_plan(self.request, plan) - - -class IndexView(horizon.forms.ModalFormView, StackMixin): +class IndexView(horizon.forms.ModalFormView, views.StackMixin): template_name = 'infrastructure/overview/index.html' form_class = forms.EditPlan success_url = reverse_lazy(INDEX_URL) @@ -258,7 +251,7 @@ class IndexView(horizon.forms.ModalFormView, StackMixin): }), mimetype='application/json') -class DeployConfirmationView(horizon.forms.ModalFormView, StackMixin): +class DeployConfirmationView(horizon.forms.ModalFormView, views.StackMixin): form_class = forms.DeployOvercloud template_name = 'infrastructure/overview/deploy_confirmation.html' submit_label = _("Deploy") @@ -276,7 +269,7 @@ class DeployConfirmationView(horizon.forms.ModalFormView, StackMixin): return reverse(INDEX_URL) -class UndeployConfirmationView(horizon.forms.ModalFormView, StackMixin): +class UndeployConfirmationView(horizon.forms.ModalFormView, views.StackMixin): form_class = forms.UndeployOvercloud template_name = 'infrastructure/overview/undeploy_confirmation.html' submit_label = _("Undeploy") @@ -296,7 +289,7 @@ class UndeployConfirmationView(horizon.forms.ModalFormView, StackMixin): return initial -class PostDeployInitView(horizon.forms.ModalFormView, StackMixin): +class PostDeployInitView(horizon.forms.ModalFormView, views.StackMixin): form_class = forms.PostDeployInit template_name = 'infrastructure/overview/post_deploy_init.html' submit_label = _("Initialize") @@ -316,7 +309,7 @@ class PostDeployInitView(horizon.forms.ModalFormView, StackMixin): return initial -class ScaleOutView(horizon.forms.ModalFormView, StackMixin): +class ScaleOutView(horizon.forms.ModalFormView, views.StackMixin): form_class = forms.ScaleOut template_name = "infrastructure/overview/scale_out.html" submit_label = _("Deploy Changes") diff --git a/tuskar_ui/infrastructure/roles/views.py b/tuskar_ui/infrastructure/roles/views.py index 19fe4b4bd..533f1ab5b 100644 --- a/tuskar_ui/infrastructure/roles/views.py +++ b/tuskar_ui/infrastructure/roles/views.py @@ -28,31 +28,14 @@ from openstack_dashboard.api import base as api_base from tuskar_ui import api from tuskar_ui.infrastructure.roles import tables from tuskar_ui.infrastructure.roles import workflows as role_workflows -import tuskar_ui.infrastructure.views as infrastructure_views +from tuskar_ui.infrastructure import views from tuskar_ui.utils import metering as metering_utils INDEX_URL = 'horizon:infrastructure:roles:index' -class RoleMixin(object): - @utils.memoized.memoized - def get_role(self, redirect=None): - role_id = self.kwargs['role_id'] - role = api.tuskar.Role.get(self.request, role_id, - _error_redirect=redirect) - return role - - -class StackMixin(object): - @utils.memoized.memoized - def get_stack(self): - plan = api.tuskar.Plan.get_the_plan(self.request) - return api.heat.Stack.get_by_plan(self.request, plan) - - -class IndexView(infrastructure_views.ItemCountMixin, - horizon_tables.DataTableView): +class IndexView(views.ItemCountMixin, horizon_tables.DataTableView): table_class = tables.RolesTable template_name = "infrastructure/roles/index.html" @@ -79,7 +62,8 @@ class IndexView(infrastructure_views.ItemCountMixin, return roles -class DetailView(horizon_tables.DataTableView, RoleMixin, StackMixin): +class DetailView(horizon_tables.DataTableView, views.RoleMixin, + views.StackMixin): table_class = tables.NodeTable template_name = 'infrastructure/roles/detail.html' @@ -175,7 +159,7 @@ class UpdateView(workflows.WorkflowView): } -class PerformanceView(base.TemplateView, RoleMixin, StackMixin): +class PerformanceView(base.TemplateView, views.RoleMixin, views.StackMixin): def get(self, request, *args, **kwargs): meter = request.GET.get('meter') date_options = request.GET.get('date_options') diff --git a/tuskar_ui/infrastructure/views.py b/tuskar_ui/infrastructure/views.py index d432a3c4b..7c0219bc0 100644 --- a/tuskar_ui/infrastructure/views.py +++ b/tuskar_ui/infrastructure/views.py @@ -12,6 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from horizon.utils import memoized + +from tuskar_ui import api + class ItemCountMixin(object): def get_items_count(self): @@ -21,3 +25,19 @@ class ItemCountMixin(object): context = super(ItemCountMixin, self).get_context_data(**kwargs) context['items_count'] = self.get_items_count() return context + + +class StackMixin(object): + @memoized.memoized + def get_stack(self): + plan = api.tuskar.Plan.get_the_plan(self.request) + return api.heat.Stack.get_by_plan(self.request, plan) + + +class RoleMixin(object): + @memoized.memoized + def get_role(self, redirect=None): + role_id = self.kwargs['role_id'] + role = api.tuskar.Role.get(self.request, role_id, + _error_redirect=redirect) + return role