Merge "Refactor StackMixin and RoleMixin"

This commit is contained in:
Jenkins 2015-01-26 14:35:20 +00:00 committed by Gerrit Code Review
commit 22292aee00
3 changed files with 31 additions and 34 deletions

View File

@ -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")

View File

@ -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')

View File

@ -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