Add module priority in the dashboard
Change-Id: Ia1836357352eb07ecda4449b101200b282c427eb
This commit is contained in:
parent
7bbf02e8d7
commit
0efc3c6dc5
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2017 Objectif Libre
|
||||
#
|
||||
# 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.
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import forms
|
||||
|
||||
from cloudkittydashboard.api import cloudkitty as api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EditPriorityForm(forms.SelfHandlingForm):
|
||||
priority = forms.IntegerField(label=_("Priority"), required=True)
|
||||
|
||||
def handle(self, request, data):
|
||||
ck_client = api.cloudkittyclient(request)
|
||||
return ck_client.modules.update(
|
||||
module_id=self.initial["module_id"],
|
||||
priority=data["priority"]
|
||||
)
|
|
@ -22,6 +22,19 @@ ENABLE = 0
|
|||
DISABLE = 1
|
||||
|
||||
|
||||
class EditModulePriority(tables.LinkAction):
|
||||
name = "editmodulepriority"
|
||||
verbose_name = _("Edit module priority")
|
||||
icon = "edit"
|
||||
ajax = True
|
||||
classes = ("ajax-modal",)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
if datum.module_id:
|
||||
url = "horizon:admin:rating_modules:edit_priority"
|
||||
return reverse(url, kwargs={'module_id': datum.module_id})
|
||||
|
||||
|
||||
class ToggleEnabledModule(tables.BatchAction):
|
||||
name = "toggle_module"
|
||||
action_present = (_("Enable"), _("Disable"))
|
||||
|
@ -59,9 +72,10 @@ class ModulesTable(tables.DataTable):
|
|||
name = tables.Column('name', verbose_name=_("Name"), link=get_details_link)
|
||||
description = tables.Column('description', verbose_name=_("Description"))
|
||||
hot_config = tables.Column('hot-config', verbose_name=_("Configurable"))
|
||||
priority = tables.Column('priority', verbose_name=_("Priority"))
|
||||
enabled = tables.Column('enabled', verbose_name=_("Enabled"))
|
||||
|
||||
class Meta(object):
|
||||
name = "modules"
|
||||
verbose_name = _("Modules")
|
||||
row_actions = (ToggleEnabledModule,)
|
||||
row_actions = (ToggleEnabledModule, EditModulePriority)
|
||||
|
|
|
@ -22,5 +22,7 @@ urlpatterns = patterns(
|
|||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(r'^(?P<module_id>[^/]+)/?$', views.ModuleDetailsView.as_view(),
|
||||
name="module_details"),
|
||||
|
||||
url(r'^edit_priority/(?P<module_id>[^/]+)/?$',
|
||||
views.PriorityModuleEditView.as_view(),
|
||||
name="edit_priority"),
|
||||
)
|
||||
|
|
|
@ -12,11 +12,15 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from horizon import forms
|
||||
from horizon import tables
|
||||
from horizon import views
|
||||
|
||||
from cloudkittydashboard.api import cloudkitty as api
|
||||
from cloudkittydashboard.dashboards.admin.modules import forms as module_forms
|
||||
from cloudkittydashboard.dashboards.admin.modules import tables as admin_tables
|
||||
|
||||
|
||||
|
@ -48,3 +52,33 @@ class ModuleDetailsView(views.APIView):
|
|||
context['hotconfig'] = module._info['hot-config']
|
||||
context['module'] = module
|
||||
return context
|
||||
|
||||
|
||||
class PriorityModuleEditView(forms.ModalFormView):
|
||||
form_class = module_forms.EditPriorityForm
|
||||
form_id = "edit_priority"
|
||||
modal_header = _("Edit Priority Module")
|
||||
page_title = _("Edit priority module")
|
||||
submit_url = "horizon:admin:rating_modules:edit_priority"
|
||||
success_url = "horizon:admin:rating_modules:edit_priority"
|
||||
template_name = "horizon/common/modal_form.html"
|
||||
|
||||
def get_initial(self):
|
||||
module = api.cloudkittyclient(self.request).modules.get(
|
||||
module_id=self.kwargs['module_id'])
|
||||
self.initial = module.to_dict()
|
||||
return self.initial
|
||||
|
||||
def get_object_id(self, obj):
|
||||
return obj.module_id
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(
|
||||
PriorityModuleEditView, self).get_context_data(**kwargs)
|
||||
context['module_id'] = self.kwargs.get('module_id')
|
||||
context['submit_url'] = reverse_lazy(self.submit_url,
|
||||
args=(context['module_id'], ))
|
||||
return context
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
return reverse('horizon:admin:rating_modules:index')
|
||||
|
|
Loading…
Reference in New Issue