Convert present/past action to methods
Table data_type_singular and data_type_plural attributes are deprecated. action_present and action_past strings are also deprecated: they must be converted to methods. This change converts action_present/action_past strings to methods. Note: MyToggleAction.action_past() is a regular method, not a static method, because we need to get the state (up/down). Change-Id: I1639844aa51ada6778c2b06392c25f7ad72c5da6
This commit is contained in:
parent
95dc25bf8a
commit
c393a6651f
@ -954,13 +954,26 @@ class DeleteAction(BatchAction):
|
||||
class UpdateAction(object):
|
||||
"""A table action for cell updates by inline editing."""
|
||||
name = "update"
|
||||
action_present = _("Update")
|
||||
action_past = _("Updated")
|
||||
data_type_singular = "update"
|
||||
|
||||
def action(self, request, datum, obj_id, cell_name, new_cell_value):
|
||||
self.update_cell(request, datum, obj_id, cell_name, new_cell_value)
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Update Item",
|
||||
u"Update Items",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Updated Item",
|
||||
u"Updated Items",
|
||||
count
|
||||
)
|
||||
|
||||
def update_cell(self, request, datum, obj_id, cell_name, new_cell_value):
|
||||
"""Method for saving data of the cell.
|
||||
|
||||
|
@ -20,6 +20,7 @@ from django import forms
|
||||
from django import http
|
||||
from django import shortcuts
|
||||
from django.template import defaultfilters
|
||||
from django.utils.translation import ungettext_lazy
|
||||
|
||||
from mox3.mox import IsA # noqa
|
||||
import six
|
||||
@ -128,28 +129,72 @@ class MyRow(tables.Row):
|
||||
|
||||
class MyBatchAction(tables.BatchAction):
|
||||
name = "batch"
|
||||
action_present = "Batch"
|
||||
action_past = "Batched"
|
||||
data_type_singular = "Item"
|
||||
data_type_plural = "Items"
|
||||
|
||||
def action(self, request, object_ids):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Batch Item",
|
||||
u"Batch Items",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Batched Item",
|
||||
u"Batched Items",
|
||||
count
|
||||
)
|
||||
|
||||
|
||||
class MyBatchActionWithHelpText(MyBatchAction):
|
||||
name = "batch_help"
|
||||
help_text = "this is help."
|
||||
action_present = "BatchHelp"
|
||||
action_past = "BatchedHelp"
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
# No translation
|
||||
return u"BatchHelp Item"
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
# No translation
|
||||
return u"BatchedHelp Item"
|
||||
|
||||
|
||||
class MyToggleAction(tables.BatchAction):
|
||||
name = "toggle"
|
||||
action_present = ("Down", "Up")
|
||||
action_past = ("Downed", "Upped")
|
||||
data_type_singular = "Item"
|
||||
data_type_plural = "Items"
|
||||
|
||||
def action_present(self, count):
|
||||
if self.current_present_action:
|
||||
return ungettext_lazy(
|
||||
u"Up Item",
|
||||
u"Up Items",
|
||||
count
|
||||
)
|
||||
else:
|
||||
return ungettext_lazy(
|
||||
u"Down Item",
|
||||
u"Down Items",
|
||||
count
|
||||
)
|
||||
|
||||
def action_past(self, count):
|
||||
if self.current_past_action:
|
||||
return ungettext_lazy(
|
||||
u"Upped Item",
|
||||
u"Upped Items",
|
||||
count
|
||||
)
|
||||
else:
|
||||
return ungettext_lazy(
|
||||
u"Downed Item",
|
||||
u"Downed Items",
|
||||
count
|
||||
)
|
||||
|
||||
def allowed(self, request, obj=None):
|
||||
if not obj:
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
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
|
||||
|
||||
@ -32,8 +33,21 @@ class SpecCreateKeyValuePair(tables.LinkAction):
|
||||
|
||||
|
||||
class SpecDeleteKeyValuePair(tables.DeleteAction):
|
||||
data_type_singular = _("Spec")
|
||||
data_type_plural = _("Specs")
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Delete Spec",
|
||||
u"Delete Specs",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Deleted Spec",
|
||||
u"Deleted Specs",
|
||||
count
|
||||
)
|
||||
|
||||
def delete(self, request, obj_ids):
|
||||
qos_spec_id = self.table.kwargs['qos_spec_id']
|
||||
|
Loading…
Reference in New Issue
Block a user