Fix NotImplementedError with horizon

Since Pike, both action_past and action_present methods are required

Closes-Bug: #1696346
Change-Id: Ibfa57684e97298a7801089393298430a4a53b2dc
This commit is contained in:
Pierre-Alexandre Bardina 2017-06-07 14:20:25 +00:00
parent b38d7827ea
commit 373248e146
3 changed files with 135 additions and 17 deletions

View File

@ -15,6 +15,8 @@
from collections import OrderedDict
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
from horizon import tabs
@ -33,12 +35,26 @@ class CreateService(tables.LinkAction):
class DeleteService(tables.DeleteAction):
name = "deleteservice"
verbose_name = _("Delete Service")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("Service")
data_type_plural = _("Services")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Service",
u"Delete Services",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Service",
u"Deleted Services",
count
)
def action(self, request, service_id):
api.cloudkittyclient(request).hashmap.services.delete(
service_id=service_id)
@ -79,12 +95,26 @@ class CreateGroup(tables.LinkAction):
class DeleteGroup(tables.DeleteAction):
name = "deletegroup"
verbose_name = _("Delete Group")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("Group")
data_type_plural = _("Groups")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Group",
u"Delete Groups",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Group",
u"Deleted Groups",
count
)
def action(self, request, group_id):
api.cloudkittyclient(request).hashmap.groups.delete(
group_id=group_id)
@ -151,14 +181,28 @@ class CreateFieldThreshold(tables.LinkAction):
class DeleteServiceThreshold(tables.DeleteAction):
name = "deletetservicehreshold"
name = "deletetservicethreshold"
verbose_name = _("Delete Service Threshold")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("Service Threshold")
data_type_plural = _("Service Thresholds")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Service Threshold",
u"Delete Service Thresholds",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Service Threshold",
u"Deleted Service Thresholds",
count
)
def action(self, request, threshold_id):
api.cloudkittyclient(request).hashmap.thresholds.delete(
threshold_id=threshold_id)
@ -167,12 +211,26 @@ class DeleteServiceThreshold(tables.DeleteAction):
class DeleteFieldThreshold(tables.DeleteAction):
name = "deletefieldthreshold"
verbose_name = _("Delete Field Threshold")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("Field Threshold")
data_type_plural = _("Field Thresholds")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Field Threshold",
u"Delete Field Thresholds",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Field Threshold",
u"Deleted Field Thresholds",
count
)
def action(self, request, threshold_id):
api.cloudkittyclient(request).hashmap.thresholds.delete(
threshold_id=threshold_id)
@ -294,12 +352,26 @@ class FieldThresholdsTab(tabs.TableTab):
class DeleteField(tables.DeleteAction):
name = "deletefield"
verbose_name = _("Delete Field")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("Field")
data_type_plural = _("Fields")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Field",
u"Delete Fields",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Field",
u"Deleted Fields",
count
)
def action(self, request, field_id):
api.cloudkittyclient(request).hashmap.fields.delete(
field_id=field_id)
@ -352,12 +424,26 @@ class FieldsTab(tabs.TableTab):
class DeleteMapping(tables.DeleteAction):
name = "deletemapping"
verbose_name = _("Delete Mapping")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("Mapping")
data_type_plural = _("Mappings")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Mapping",
u"Delete Mappings",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Mapping",
u"Deleted Mappings",
count
)
def action(self, request, mapping_id):
api.cloudkittyclient(request).hashmap.mappings.delete(
mapping_id=mapping_id)

View File

@ -14,6 +14,8 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
from cloudkittydashboard.api import cloudkitty as api
@ -37,12 +39,26 @@ class EditModulePriority(tables.LinkAction):
class ToggleEnabledModule(tables.BatchAction):
name = "toggle_module"
action_present = (_("Enable"), _("Disable"))
action_past = (_("Enabled"), _("Disabled"))
data_type_singular = _("Module")
data_type_plural = _("Modules")
classes = ("btn-toggle",)
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Enable Module",
u"Disable Module",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Enabled Module",
u"Disabled Module",
count
)
def allowed(self, request, module=None):
self.enabled = module.enabled
if self.enabled:

View File

@ -14,6 +14,8 @@
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
from cloudkittydashboard.api import cloudkitty as api
@ -48,12 +50,26 @@ class UpdateScript(tables.LinkAction):
class DeletePyScript(tables.DeleteAction):
name = "deletepyscript"
verbose_name = _("Delete Script")
action_present = _("Delete")
action_past = _("Deleted")
data_type_singular = _("PyScript")
data_type_plural = _("PyScripts")
icon = "remove"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete PyScript",
u"Delete PyScripts",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted PyScript",
u"Deleted PyScripts",
count
)
def action(self, request, script_id):
api.cloudkittyclient(request).pyscripts.scripts.delete(
script_id=script_id)