table action: drop deprecated action_present/past attributes
action_present and action_past "attributes" have been deprecated since the middle of Mitaka development cycle. There is no consumer in the horizon repository and the deprecation warnings were emitted appropriately so horizon plugins are expected not to use them already. Now we are in the early stage for the next release (Pike), so it is time to drop the deprecated way. Change-Id: Ia93a6b17561068777845366b2b4c57b7144fab9f
This commit is contained in:
@@ -17,7 +17,6 @@ from collections import OrderedDict
|
|||||||
import copy
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import types
|
import types
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
@@ -25,7 +24,6 @@ from django import shortcuts
|
|||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.utils.translation import pgettext_lazy
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.translation import ungettext_lazy
|
from django.utils.translation import ungettext_lazy
|
||||||
import six
|
import six
|
||||||
@@ -605,63 +603,29 @@ class BatchAction(Action):
|
|||||||
|
|
||||||
.. method:: action_present
|
.. method:: action_present
|
||||||
|
|
||||||
Method accepting an integer/long parameter and returning the display
|
Method returning a present action name. This is used as an action label.
|
||||||
|
|
||||||
|
Method must accept an integer/long parameter and return the display
|
||||||
forms of the name properly pluralised (depending on the integer) and
|
forms of the name properly pluralised (depending on the integer) and
|
||||||
translated in a string or tuple/list.
|
translated in a string or tuple/list.
|
||||||
|
|
||||||
.. attribute:: action_present (Deprecated)
|
The returned display form is highly recommended to be a complete action
|
||||||
|
name with a form of a transitive verb and an object noun. Each word is
|
||||||
|
capitalized and the string should be marked as translatable.
|
||||||
|
|
||||||
String or tuple/list. The display forms of the name.
|
If tuple or list - then setting self.current_present_action = n will
|
||||||
Should be a transitive verb, capitalized and translated. ("Delete",
|
set the current active item from the list(action_present[n])
|
||||||
"Rotate", etc.) If tuple or list - then setting
|
|
||||||
self.current_present_action = n will set the current active item
|
|
||||||
from the list(action_present[n])
|
|
||||||
|
|
||||||
You can pass a complete action name including 'data_type' by specifying
|
|
||||||
'%(data_type)s' substitution in action_present ("Delete %(data_type)s").
|
|
||||||
Otherwise a complete action name is a format of "<action> <data_type>".
|
|
||||||
<data_type> is determined based on the number of items.
|
|
||||||
By passing a complete action name you allow translators to control
|
|
||||||
the order of words as they want.
|
|
||||||
|
|
||||||
NOTE: action_present attribute is bad for translations and should be
|
|
||||||
avoided. Please use the action_present method instead.
|
|
||||||
This form is kept for legacy.
|
|
||||||
|
|
||||||
.. method:: action_past
|
.. method:: action_past
|
||||||
|
|
||||||
Method accepting an integer/long parameter and returning the display
|
Method returning a past action name. This is usually used to display
|
||||||
|
a message when the action is completed.
|
||||||
|
|
||||||
|
Method must accept an integer/long parameter and return the display
|
||||||
forms of the name properly pluralised (depending on the integer) and
|
forms of the name properly pluralised (depending on the integer) and
|
||||||
translated in a string or tuple/list.
|
translated in a string or tuple/list.
|
||||||
|
|
||||||
.. attribute:: action_past (Deprecated)
|
The detail is same as that of ``action_present``.
|
||||||
|
|
||||||
String or tuple/list. The past tense of action_present. ("Deleted",
|
|
||||||
"Rotated", etc.) If tuple or list - then
|
|
||||||
setting self.current_past_action = n will set the current active item
|
|
||||||
from the list(action_past[n])
|
|
||||||
|
|
||||||
NOTE: action_past attribute is bad for translations and should be
|
|
||||||
avoided. Please use the action_past method instead.
|
|
||||||
This form is kept for legacy.
|
|
||||||
|
|
||||||
.. attribute:: data_type_singular (Deprecated)
|
|
||||||
|
|
||||||
Optional display name (if the data_type method is not defined) for the
|
|
||||||
type of data that receives the action. ("Key Pair", "Floating IP", etc.)
|
|
||||||
|
|
||||||
.. attribute:: data_type_plural (Deprecated)
|
|
||||||
|
|
||||||
Optional plural word (if the data_type method is not defined) for the
|
|
||||||
type of data being acted on. Defaults to appending 's'. Relying on the
|
|
||||||
default is bad for translations and should not be done, so it's absence
|
|
||||||
will raise a DeprecationWarning. It is currently kept as optional for
|
|
||||||
legacy code.
|
|
||||||
|
|
||||||
NOTE: data_type_singular and data_type_plural attributes are bad for
|
|
||||||
translations and should not be used. Please use the action_present and
|
|
||||||
action_past methods. This form is kept temporarily for legacy code but
|
|
||||||
will be removed.
|
|
||||||
|
|
||||||
.. attribute:: success_url
|
.. attribute:: success_url
|
||||||
|
|
||||||
@@ -672,6 +636,7 @@ class BatchAction(Action):
|
|||||||
|
|
||||||
Optional message for providing an appropriate help text for
|
Optional message for providing an appropriate help text for
|
||||||
the horizon user.
|
the horizon user.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
help_text = _("This action cannot be undone.")
|
help_text = _("This action cannot be undone.")
|
||||||
@@ -679,50 +644,15 @@ class BatchAction(Action):
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(BatchAction, self).__init__(**kwargs)
|
super(BatchAction, self).__init__(**kwargs)
|
||||||
|
|
||||||
action_present_method = False
|
action_present_method = callable(getattr(self, 'action_present', None))
|
||||||
if hasattr(self, 'action_present'):
|
action_past_method = callable(getattr(self, 'action_past', None))
|
||||||
if callable(self.action_present):
|
|
||||||
action_present_method = True
|
|
||||||
else:
|
|
||||||
warnings.warn(DeprecationWarning(
|
|
||||||
'The %s BatchAction class must have an action_present '
|
|
||||||
'method instead of attribute.' % self.__class__.__name__
|
|
||||||
))
|
|
||||||
|
|
||||||
action_past_method = False
|
if not action_present_method or not action_past_method:
|
||||||
if hasattr(self, 'action_past'):
|
|
||||||
if callable(self.action_past):
|
|
||||||
action_past_method = True
|
|
||||||
else:
|
|
||||||
warnings.warn(DeprecationWarning(
|
|
||||||
'The %s BatchAction class must have an action_past '
|
|
||||||
'method instead of attribute.' % self.__class__.__name__
|
|
||||||
))
|
|
||||||
|
|
||||||
action_methods = action_present_method and action_past_method
|
|
||||||
has_action_method = action_present_method or action_past_method
|
|
||||||
|
|
||||||
if has_action_method and not action_methods:
|
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'The %s BatchAction class must have both action_past and'
|
'The %s BatchAction class must have both action_past and'
|
||||||
'action_present methods.' % self.__class__.__name__
|
'action_present methods.' % self.__class__.__name__
|
||||||
)
|
)
|
||||||
|
|
||||||
if not action_methods:
|
|
||||||
if not kwargs.get('data_type_singular'):
|
|
||||||
raise NotImplementedError(
|
|
||||||
'The %s BatchAction class must have a data_type_singular '
|
|
||||||
'attribute when action_past and action_present attributes '
|
|
||||||
'are used.' % self.__class__.__name__
|
|
||||||
)
|
|
||||||
self.data_type_singular = kwargs.get('data_type_singular')
|
|
||||||
self.data_type_plural = kwargs.get('data_type_plural',
|
|
||||||
self.data_type_singular + 's')
|
|
||||||
|
|
||||||
# TODO(ygbo): get rid of self.use_action_method once action_present and
|
|
||||||
# action_past are changed to methods handling plurals.
|
|
||||||
self.use_action_method = action_methods
|
|
||||||
|
|
||||||
self.success_url = kwargs.get('success_url', None)
|
self.success_url = kwargs.get('success_url', None)
|
||||||
# If setting a default name, don't initialize it too early
|
# If setting a default name, don't initialize it too early
|
||||||
self.verbose_name = kwargs.get('verbose_name', self._get_action_name)
|
self.verbose_name = kwargs.get('verbose_name', self._get_action_name)
|
||||||
@@ -745,8 +675,7 @@ class BatchAction(Action):
|
|||||||
return super(BatchAction, self)._allowed(request, datum)
|
return super(BatchAction, self)._allowed(request, datum)
|
||||||
|
|
||||||
def _get_action_name(self, items=None, past=False):
|
def _get_action_name(self, items=None, past=False):
|
||||||
"""Builds combinations like 'Delete Object' and 'Deleted
|
"""Retreive action name based on the number of items and `past` flag.
|
||||||
Objects' based on the number of items and `past` flag.
|
|
||||||
|
|
||||||
:param items:
|
:param items:
|
||||||
|
|
||||||
@@ -771,35 +700,14 @@ class BatchAction(Action):
|
|||||||
else:
|
else:
|
||||||
count = len(items)
|
count = len(items)
|
||||||
|
|
||||||
# TODO(ygbo): get rid of self.use_action_method once action_present and
|
action_attr = getattr(self, "action_%s" % action_type)(count)
|
||||||
# action_past are changed to methods handling plurals.
|
|
||||||
action_attr = getattr(self, "action_%s" % action_type)
|
|
||||||
if self.use_action_method:
|
|
||||||
action_attr = action_attr(count)
|
|
||||||
if isinstance(action_attr, (six.string_types, Promise)):
|
if isinstance(action_attr, (six.string_types, Promise)):
|
||||||
action = action_attr
|
action = action_attr
|
||||||
else:
|
else:
|
||||||
toggle_selection = getattr(self, "current_%s_action" % action_type)
|
toggle_selection = getattr(self, "current_%s_action" % action_type)
|
||||||
action = action_attr[toggle_selection]
|
action = action_attr[toggle_selection]
|
||||||
|
|
||||||
if self.use_action_method:
|
return action
|
||||||
return action
|
|
||||||
# TODO(ygbo): get rid of all this bellow once action_present and
|
|
||||||
# action_past are changed to methods handling plurals.
|
|
||||||
data_type = ungettext_lazy(
|
|
||||||
self.data_type_singular,
|
|
||||||
self.data_type_plural,
|
|
||||||
count
|
|
||||||
)
|
|
||||||
if '%(data_type)s' in action:
|
|
||||||
# If full action string is specified, use action as format string.
|
|
||||||
msgstr = action
|
|
||||||
else:
|
|
||||||
if action_type == "past":
|
|
||||||
msgstr = pgettext_lazy(u"past", "%(action)s %(data_type)s")
|
|
||||||
else:
|
|
||||||
msgstr = pgettext_lazy(u"present", "%(action)s %(data_type)s")
|
|
||||||
return msgstr % {'action': action, 'data_type': data_type}
|
|
||||||
|
|
||||||
def action(self, request, datum_id):
|
def action(self, request, datum_id):
|
||||||
"""Required. Accepts a single object id and performs the specific
|
"""Required. Accepts a single object id and performs the specific
|
||||||
@@ -894,50 +802,40 @@ class DeleteAction(BatchAction):
|
|||||||
|
|
||||||
.. method:: action_present
|
.. method:: action_present
|
||||||
|
|
||||||
Method accepting an integer/long parameter and returning the display
|
Method returning a present action name. This is used as an action label.
|
||||||
forms of the name properly pluralised (depending on the integer) and
|
|
||||||
translated in a string or tuple/list.
|
|
||||||
|
|
||||||
.. attribute:: action_present (Deprecated)
|
Method must accept an integer/long parameter and return the display
|
||||||
|
forms of the name properly pluralised (depending on the integer) and
|
||||||
|
translated in a string or tuple/list.
|
||||||
|
|
||||||
A string containing the transitive verb describing the delete action.
|
The returned display form is highly recommended to be a complete action
|
||||||
Defaults to 'Delete'
|
name with a form of a transitive verb and an object noun. Each word is
|
||||||
|
capitalized and the string should be marked as translatable.
|
||||||
|
|
||||||
NOTE: action_present attribute is bad for translations and should be
|
If tuple or list - then setting self.current_present_action = n will
|
||||||
avoided. Please use the action_present method instead.
|
set the current active item from the list(action_present[n])
|
||||||
This form is kept for legacy.
|
|
||||||
|
|
||||||
.. method:: action_past
|
.. method:: action_past
|
||||||
|
|
||||||
Method accepting an integer/long parameter and returning the display
|
Method returning a past action name. This is usually used to display
|
||||||
forms of the name properly pluralised (depending on the integer) and
|
a message when the action is completed.
|
||||||
translated in a string or tuple/list.
|
|
||||||
|
|
||||||
.. attribute:: action_past (Deprecated)
|
Method must accept an integer/long parameter and return the display
|
||||||
|
forms of the name properly pluralised (depending on the integer) and
|
||||||
|
translated in a string or tuple/list.
|
||||||
|
|
||||||
A string set to the past tense of action_present.
|
The detail is same as that of ``action_present``.
|
||||||
Defaults to 'Deleted'
|
|
||||||
|
|
||||||
NOTE: action_past attribute is bad for translations and should be
|
.. attribute:: success_url
|
||||||
avoided. Please use the action_past method instead.
|
|
||||||
This form is kept for legacy.
|
|
||||||
|
|
||||||
.. attribute:: data_type_singular (Deprecated)
|
Optional location to redirect after completion of the delete
|
||||||
|
action. Defaults to the current page.
|
||||||
|
|
||||||
A string used to name the data to be deleted.
|
.. attribute:: help_text
|
||||||
|
|
||||||
.. attribute:: data_type_plural (Deprecated)
|
Optional message for providing an appropriate help text for
|
||||||
|
the horizon user.
|
||||||
|
|
||||||
Optional. Plural of ``data_type_singular``.
|
|
||||||
Defaults to ``data_type_singular`` appended with an 's'. Relying on
|
|
||||||
the default is bad for translations and should not be done, so it's
|
|
||||||
absence will raise a DeprecationWarning. It is currently kept as
|
|
||||||
optional for legacy code.
|
|
||||||
|
|
||||||
NOTE: data_type_singular and data_type_plural attributes are bad for
|
|
||||||
translations and should not be used. Please use the action_present and
|
|
||||||
action_past methods. This form is kept temporarily for legacy code but
|
|
||||||
will be removed.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name = "delete"
|
name = "delete"
|
||||||
@@ -945,10 +843,6 @@ class DeleteAction(BatchAction):
|
|||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(DeleteAction, self).__init__(**kwargs)
|
super(DeleteAction, self).__init__(**kwargs)
|
||||||
self.name = kwargs.get('name', self.name)
|
self.name = kwargs.get('name', self.name)
|
||||||
if not hasattr(self, "action_present"):
|
|
||||||
self.action_present = kwargs.get('action_present', _("Delete"))
|
|
||||||
if not hasattr(self, "action_past"):
|
|
||||||
self.action_past = kwargs.get('action_past', _("Deleted"))
|
|
||||||
self.icon = "trash"
|
self.icon = "trash"
|
||||||
self.action_type = "danger"
|
self.action_type = "danger"
|
||||||
|
|
||||||
|
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
String attributes ``action_present`` and ``action_past`` were dropped
|
||||||
|
from ``horizon.tables.BatchAction``. ``action_present`` and ``action_past``
|
||||||
|
*methods* are the recommended way to define action labels for BatchAction.
|
||||||
|
The offical way allows us to define more complete strings for action labels
|
||||||
|
and this also allows translators to translate more flexibily.
|
Reference in New Issue
Block a user