The horizon.tables.actions Module

class horizon.tables.actions.Action(single_func=None, multiple_func=None, handle_func=None, attrs=None, **kwargs)[source]

Bases: horizon.tables.actions.BaseAction

Represents an action which can be taken on this table’s data.

name

Required. The short name or “slug” representing this action. This name should not be changed at runtime.

verbose_name

A descriptive name used for display purposes. Defaults to the value of name with the first letter of each word capitalized.

verbose_name_plural

Used like verbose_name in cases where handles_multiple is True. Defaults to verbose_name with the letter “s” appended.

method

The HTTP method for this action. Defaults to POST. Other methods may or may not succeed currently.

requires_input

Boolean value indicating whether or not this action can be taken without any additional input (e.g. an object id). Defaults to True.

preempt

Boolean value indicating whether this action should be evaluated in the period after the table is instantiated but before the data has been loaded.

This can allow actions which don’t need access to the full table data to bypass any API calls and processing which would otherwise be required to load the table.

allowed_data_types

A list that contains the allowed data types of the action. If the datum’s type is in this list, the action will be shown on the row for the datum.

Default to be an empty list ([]). When set to empty, the action will accept any kind of data.

policy_rules

list of scope and rule tuples to do policy checks on, the composition of which is (scope, rule)

scope: service type managing the policy for action rule: string representing the action to be checked

for a policy that requires a single rule check:
policy_rules should look like
“((“compute”, “compute:create_instance”),)”
for a policy that requires multiple rule checks:
rules should look like
“((“identity”, “identity:list_users”),
(“identity”, “identity:list_roles”))”

At least one of the following methods must be defined:

single(self, data_table, request, object_id)

Handler for a single-object action.

multiple(self, data_table, request, object_ids)

Handler for multi-object actions.

handle(self, data_table, request, object_ids)

If a single function can work for both single-object and multi-object cases then simply providing a handle function will internally route both single and multiple requests to handle with the calls from single being transformed into a list containing only the single object id.

base_options = {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_param_name': <function get_param_name at 0x7f424923c9b0>, 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Represents an action which can be taken on this table\'s data.\n\n .. attribute:: name\n\n Required. The short name or "slug" representing this\n action. This name should not be changed at runtime.\n\n .. attribute:: verbose_name\n\n A descriptive name used for display purposes. Defaults to the\n value of ``name`` with the first letter of each word capitalized.\n\n .. attribute:: verbose_name_plural\n\n Used like ``verbose_name`` in cases where ``handles_multiple`` is\n ``True``. Defaults to ``verbose_name`` with the letter "s" appended.\n\n .. attribute:: method\n\n The HTTP method for this action. Defaults to ``POST``. Other methods\n may or may not succeed currently.\n\n .. attribute:: requires_input\n\n Boolean value indicating whether or not this action can be taken\n without any additional input (e.g. an object id). Defaults to ``True``.\n\n .. attribute:: preempt\n\n Boolean value indicating whether this action should be evaluated in\n the period after the table is instantiated but before the data has\n been loaded.\n\n This can allow actions which don\'t need access to the full table data\n to bypass any API calls and processing which would otherwise be\n required to load the table.\n\n .. attribute:: allowed_data_types\n\n A list that contains the allowed data types of the action. If the\n datum\'s type is in this list, the action will be shown on the row\n for the datum.\n\n Default to be an empty list (``[]``). When set to empty, the action\n will accept any kind of data.\n\n .. attribute:: policy_rules\n\n list of scope and rule tuples to do policy checks on, the\n composition of which is (scope, rule)\n\n scope: service type managing the policy for action\n rule: string representing the action to be checked\n\n for a policy that requires a single rule check:\n policy_rules should look like\n "(("compute", "compute:create_instance"),)"\n for a policy that requires multiple rule checks:\n rules should look like\n "(("identity", "identity:list_users"),\n ("identity", "identity:list_roles"))"\n\n At least one of the following methods must be defined:\n\n .. method:: single(self, data_table, request, object_id)\n\n Handler for a single-object action.\n\n .. method:: multiple(self, data_table, request, object_ids)\n\n Handler for multi-object actions.\n\n .. method:: handle(self, data_table, request, object_ids)\n\n If a single function can work for both single-object and\n multi-object cases then simply providing a ``handle`` function\n will internally route both ``single`` and ``multiple`` requests\n to ``handle`` with the calls from ``single`` being transformed\n into a list containing only the single object id.\n ', 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, '__init__': <function __init__ at 0x7f424923c488>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
get_param_name()[source]

Returns the full POST parameter name for this action.

Defaults to {{ table.name }}__{{ action.name }}.

class horizon.tables.actions.BaseAction(**kwargs)[source]

Bases: horizon.utils.html.HTMLElement

Common base class for all Action classes.

allowed(request, datum)[source]

Determine whether this action is allowed for the current request.

This method is meant to be overridden with more specific checks.

associate_with_table(table)[source]
base_options = {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
data_type_matched(datum)[source]

Method to see if the action is allowed for a certain type of data. Only affects mixed data type tables.

get_default_attrs()[source]

Returns a list of the default HTML attributes for the action. Defaults to returning an id attribute with the value {{ table.name }}__action_{{ action.name }}__{{ creation counter }}.

get_default_classes()[source]

Returns a list of the default classes for the action. Defaults to ["btn", "btn-default", "btn-sm"].

get_policy_target(request, datum)[source]

Provide the target for a policy request.

This method is meant to be overridden to return target details when one of the policy checks requires them. E.g., {“user_id”: datum.id}

update(request, datum)[source]

Allows per-action customization based on current conditions.

This is particularly useful when you wish to create a “toggle” action that will be rendered differently based on the value of an attribute on the current row’s data.

By default this method is a no-op.

class horizon.tables.actions.BaseActionMetaClass[source]

Bases: type

Metaclass for adding all actions options from inheritance tree to action. This way actions can inherit from each other but still use the class attributes DSL. Meaning, all attributes of Actions are defined as class attributes, but in the background, it will be used as parameters for the initializer of the object. The object is then initialized clean way. Similar principle is used in DataTableMetaclass.

class horizon.tables.actions.BatchAction(**kwargs)[source]

Bases: horizon.tables.actions.Action

A table action which takes batch action on one or more objects. This action should not require user input on a per-object basis.

name

An internal name for this action.

action_present()

Method accepting an integer/long parameter and returning the display forms of the name properly pluralised (depending on the integer) and translated in a string or tuple/list.

action_present(Deprecated)

String or tuple/list. The display forms of the name. Should be a transitive verb, capitalized and translated. (“Delete”, “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.

action_past()

Method accepting an integer/long parameter and returning the display forms of the name properly pluralised (depending on the integer) and translated in a string or tuple/list.

action_past(Deprecated)

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.

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.)

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.

success_url

Optional location to redirect after completion of the delete action. Defaults to the current page.

help_text

Optional message for providing an appropriate help text for the horizon user.

action(request, datum_id)[source]

Required. Accepts a single object id and performs the specific action.

Return values are discarded, errors raised are caught and logged.

base_options = {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'get_param_name': <function get_param_name at 0x7f424923c9b0>, 'help_text': <django.utils.functional.__proxy__ object at 0x7f4249228850>, 'handle': <function handle at 0x7f424922f5f0>, 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, '__init__': <function __init__ at 0x7f424922f2a8>, '_allowed': <function _allowed at 0x7f424922f320>, '_get_action_name': <function _get_action_name at 0x7f424922f398>, 'update': <function update at 0x7f424922f488>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'action': <function action at 0x7f424922f410>, 'get_default_attrs': <function get_default_attrs at 0x7f424922f578>, '__doc__': 'A table action which takes batch action on one or more\n objects. This action should not require user input on a\n per-object basis.\n\n .. attribute:: name\n\n An internal name for this action.\n\n .. method:: action_present\n\n Method accepting an integer/long parameter and returning the display\n forms of the name properly pluralised (depending on the integer) and\n translated in a string or tuple/list.\n\n .. attribute:: action_present (Deprecated)\n\n String or tuple/list. The display forms of the name.\n Should be a transitive verb, capitalized and translated. ("Delete",\n "Rotate", etc.) If tuple or list - then setting\n self.current_present_action = n will set the current active item\n from the list(action_present[n])\n\n You can pass a complete action name including \'data_type\' by specifying\n \'%(data_type)s\' substitution in action_present ("Delete %(data_type)s").\n Otherwise a complete action name is a format of "<action> <data_type>".\n <data_type> is determined based on the number of items.\n By passing a complete action name you allow translators to control\n the order of words as they want.\n\n NOTE: action_present attribute is bad for translations and should be\n avoided. Please use the action_present method instead.\n This form is kept for legacy.\n\n .. method:: action_past\n\n Method accepting an integer/long parameter and returning the display\n forms of the name properly pluralised (depending on the integer) and\n translated in a string or tuple/list.\n\n .. attribute:: action_past (Deprecated)\n\n String or tuple/list. The past tense of action_present. ("Deleted",\n "Rotated", etc.) If tuple or list - then\n setting self.current_past_action = n will set the current active item\n from the list(action_past[n])\n\n NOTE: action_past attribute is bad for translations and should be\n avoided. Please use the action_past method instead.\n This form is kept for legacy.\n\n .. attribute:: data_type_singular (Deprecated)\n\n Optional display name (if the data_type method is not defined) for the\n type of data that receives the action. ("Key Pair", "Floating IP", etc.)\n\n .. attribute:: data_type_plural (Deprecated)\n\n Optional plural word (if the data_type method is not defined) for the\n type of data being acted on. Defaults to appending \'s\'. Relying on the\n default is bad for translations and should not be done, so it\'s absence\n will raise a DeprecationWarning. It is currently kept as optional for\n legacy code.\n\n NOTE: data_type_singular and data_type_plural attributes are bad for\n translations and should not be used. Please use the action_present and\n action_past methods. This form is kept temporarily for legacy code but\n will be removed.\n\n .. attribute:: success_url\n\n Optional location to redirect after completion of the delete\n action. Defaults to the current page.\n\n .. attribute:: help_text\n\n Optional message for providing an appropriate help text for\n the horizon user.\n ', 'get_success_url': <function get_success_url at 0x7f424922f500>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
get_default_attrs()[source]

Returns a list of the default HTML attributes for the action.

get_success_url(request=None)[source]

Returns the URL to redirect to after a successful action.

handle(table, request, obj_ids)[source]
help_text = <django.utils.functional.__proxy__ object at 0x7f4249228850>
update(request, datum)[source]

Switches the action verbose name, if needed.

class horizon.tables.actions.DeleteAction(**kwargs)[source]

Bases: horizon.tables.actions.BatchAction

A table action used to perform delete operations on table data.

name

A short name or “slug” representing this action. Defaults to ‘delete’

action_present()

Method accepting an integer/long parameter and returning the display forms of the name properly pluralised (depending on the integer) and translated in a string or tuple/list.

action_present(Deprecated)

A string containing the transitive verb describing the delete action. Defaults to ‘Delete’

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.

action_past()

Method accepting an integer/long parameter and returning the display forms of the name properly pluralised (depending on the integer) and translated in a string or tuple/list.

action_past(Deprecated)

A string set to the past tense of action_present. Defaults to ‘Deleted’

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.

data_type_singular(Deprecated)

A string used to name the data to be deleted.

data_type_plural(Deprecated)

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.

action(request, obj_id)[source]

Action entry point. Overrides base class’ action method.

Accepts a single object id passing it over to the delete method responsible for the object’s destruction.

base_options = {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'get_param_name': <function get_param_name at 0x7f424923c9b0>, 'handle': <function handle at 0x7f424922f5f0>, 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, '__init__': <function __init__ at 0x7f424922f668>, '_allowed': <function _allowed at 0x7f424922f320>, '_get_action_name': <function _get_action_name at 0x7f424922f398>, 'update': <function update at 0x7f424922f488>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'name': 'delete', 'help_text': <django.utils.functional.__proxy__ object at 0x7f4249228850>, 'get_default_attrs': <function get_default_attrs at 0x7f424922f578>, '__doc__': 'A table action used to perform delete operations on table data.\n\n .. attribute:: name\n\n A short name or "slug" representing this action.\n Defaults to \'delete\'\n\n .. method:: action_present\n\n Method accepting an integer/long parameter and returning the display\n forms of the name properly pluralised (depending on the integer) and\n translated in a string or tuple/list.\n\n .. attribute:: action_present (Deprecated)\n\n A string containing the transitive verb describing the delete action.\n Defaults to \'Delete\'\n\n NOTE: action_present attribute is bad for translations and should be\n avoided. Please use the action_present method instead.\n This form is kept for legacy.\n\n .. method:: action_past\n\n Method accepting an integer/long parameter and returning the display\n forms of the name properly pluralised (depending on the integer) and\n translated in a string or tuple/list.\n\n .. attribute:: action_past (Deprecated)\n\n A string set to the past tense of action_present.\n Defaults to \'Deleted\'\n\n NOTE: action_past attribute is bad for translations and should be\n avoided. Please use the action_past method instead.\n This form is kept for legacy.\n\n .. attribute:: data_type_singular (Deprecated)\n\n A string used to name the data to be deleted.\n\n .. attribute:: data_type_plural (Deprecated)\n\n Optional. Plural of ``data_type_singular``.\n Defaults to ``data_type_singular`` appended with an \'s\'. Relying on\n the default is bad for translations and should not be done, so it\'s\n absence will raise a DeprecationWarning. It is currently kept as\n optional for legacy code.\n\n NOTE: data_type_singular and data_type_plural attributes are bad for\n translations and should not be used. Please use the action_present and\n action_past methods. This form is kept temporarily for legacy code but\n will be removed.\n ', 'delete': <function delete at 0x7f424922f758>, 'get_success_url': <function get_success_url at 0x7f424922f500>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, 'action': <function action at 0x7f424922f6e0>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
delete(request, obj_id)[source]

Required. Deletes an object referenced by obj_id.

Override to provide delete functionality specific to your data.

name = 'delete'
class horizon.tables.actions.Deprecated[source]

Bases: type

class horizon.tables.actions.FilterAction(**kwargs)[source]

Bases: horizon.tables.actions.BaseAction

A base class representing a filter action for a table.

name

The short name or “slug” representing this action. Defaults to "filter".

verbose_name

A descriptive name used for display purposes. Defaults to the value of name with the first letter of each word capitalized.

param_name

A string representing the name of the request parameter used for the search term. Default: "q".

filter_type

A string representing the type of this filter. If this is set to "server" then filter_choices must also be provided. Default: "query".

filter_choices

Required for server type filters. A tuple of tuples representing the filter options. Tuple composition should evaluate to (string, string, boolean), representing the filter parameter, display value, and whether or not it should be applied to the API request as an API query attribute. API type filters do not need to be accounted for in the filter method since the API will do the filtering. However, server type filters in general will need to be performed in the filter method. By default this attribute is not provided.

needs_preloading

If True, the filter function will be called for the initial GET request with an empty filter_string, regardless of the value of method.

assign_type_string(table, data, type_string)[source]
base_options = {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'get_param_name': <function get_param_name at 0x7f424923ccf8>, 'get_select_options': <function get_select_options at 0x7f424923cf50>, 'data_type_filter': <function data_type_filter at 0x7f424923cde8>, 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, '__init__': <function __init__ at 0x7f424923cc80>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'filter': <function filter at 0x7f424923ce60>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, 'is_api_filter': <function is_api_filter at 0x7f424923ced8>, '__module__': 'horizon.tables.actions', 'name': 'filter', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'A base class representing a filter action for a table.\n\n .. attribute:: name\n\n The short name or "slug" representing this action. Defaults to\n ``"filter"``.\n\n .. attribute:: verbose_name\n\n A descriptive name used for display purposes. Defaults to the\n value of ``name`` with the first letter of each word capitalized.\n\n .. attribute:: param_name\n\n A string representing the name of the request parameter used for the\n search term. Default: ``"q"``.\n\n .. attribute:: filter_type\n\n A string representing the type of this filter. If this is set to\n ``"server"`` then ``filter_choices`` must also be provided.\n Default: ``"query"``.\n\n .. attribute:: filter_choices\n\n Required for server type filters. A tuple of tuples representing the\n filter options. Tuple composition should evaluate to (string, string,\n boolean), representing the filter parameter, display value, and whether\n or not it should be applied to the API request as an API query\n attribute. API type filters do not need to be accounted for in the\n filter method since the API will do the filtering. However, server\n type filters in general will need to be performed in the filter method.\n By default this attribute is not provided.\n\n .. attribute:: needs_preloading\n\n If True, the filter function will be called for the initial\n GET request with an empty ``filter_string``, regardless of the\n value of ``method``.\n ', 'assign_type_string': <function assign_type_string at 0x7f424923cd70>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
data_type_filter(table, data, filter_string)[source]
filter(table, data, filter_string)[source]

Provides the actual filtering logic.

This method must be overridden by subclasses and return the filtered data.

get_param_name()[source]

Returns the full query parameter name for this action.

Defaults to {{ table.name }}__{{ action.name }}__{{ action.param_name }}.

get_select_options()[source]

Provide the value, string, and help_text (if applicable) for the template to render.

is_api_filter(filter_field)[source]

Determine if the given filter field should be used as an API filter.

name = 'filter'
class horizon.tables.actions.FixedFilterAction(**kwargs)[source]

Bases: horizon.tables.actions.FilterAction

A filter action with fixed buttons.

base_options = {'associate_with_table': <function associate_with_table at 0x7f424923c938>, 'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'get_param_name': <function get_param_name at 0x7f424923ccf8>, '__init__': <function __init__ at 0x7f424922f0c8>, 'categorize': <function categorize at 0x7f424922f230>, 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, 'get_select_options': <function get_select_options at 0x7f424923cf50>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'filter': <function filter at 0x7f424922f140>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, 'is_api_filter': <function is_api_filter at 0x7f424923ced8>, '__module__': 'horizon.tables.actions', 'name': 'filter', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'A filter action with fixed buttons.', 'assign_type_string': <function assign_type_string at 0x7f424923cd70>, 'data_type_filter': <function data_type_filter at 0x7f424923cde8>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'get_fixed_buttons': <function get_fixed_buttons at 0x7f424922f1b8>, 'allowed': <function allowed at 0x7f424923c668>}
categorize(table, rows)[source]

Override to separate rows into categories.

To have filtering working properly on the client, each row will need CSS class(es) beginning with ‘category-‘, followed by the value of the fixed button.

Return a dict with a key for the value of each fixed button, and a value that is a list of rows in that category.

filter(table, images, filter_string)[source]
get_fixed_buttons()[source]

Returns a list of dictionaries describing the fixed buttons to use for filtering.

Each list item should be a dict with the following keys:

  • text: Text to display on the button
  • icon: Icon class for icon element (inserted before text).
  • value: Value returned when the button is clicked. This value is passed to filter() as filter_string.
class horizon.tables.actions.LinkAction(attrs=None, **kwargs)[source]

Bases: horizon.tables.actions.BaseAction

A table action which is simply a link rather than a form POST.

name

Required. The short name or “slug” representing this action. This name should not be changed at runtime.

verbose_name

A string which will be rendered as the link text. (Required)

url

A string or a callable which resolves to a url to be used as the link target. You must either define the url attribute or override the get_link_url method on the class.

allowed_data_types

A list that contains the allowed data types of the action. If the datum’s type is in this list, the action will be shown on the row for the datum.

Defaults to be an empty list ([]). When set to empty, the action will accept any kind of data.

ajax = False
associate_with_table(table)[source]
base_options = {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'render': <function render at 0x7f424923cb18>, 'get_link_url': <function get_link_url at 0x7f424923cc08>, 'get_ajax_update_url': <function get_ajax_update_url at 0x7f424923caa0>, 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, '__init__': <function __init__ at 0x7f424923ca28>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'ajax': False, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'name': 'link', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'A table action which is simply a link rather than a form POST.\n\n .. attribute:: name\n\n Required. The short name or "slug" representing this\n action. This name should not be changed at runtime.\n\n .. attribute:: verbose_name\n\n A string which will be rendered as the link text. (Required)\n\n .. attribute:: url\n\n A string or a callable which resolves to a url to be used as the link\n target. You must either define the ``url`` attribute or override\n the ``get_link_url`` method on the class.\n\n .. attribute:: allowed_data_types\n\n A list that contains the allowed data types of the action. If the\n datum\'s type is in this list, the action will be shown on the row\n for the datum.\n\n Defaults to be an empty list (``[]``). When set to empty, the action\n will accept any kind of data.\n ', 'associate_with_table': <function associate_with_table at 0x7f424923cb90>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
get_ajax_update_url()[source]
get_link_url(datum=None)[source]

Returns the final URL based on the value of url.

If url is callable it will call the function. If not, it will then try to call reverse on url. Failing that, it will simply return the value of url as-is.

When called for a row action, the current row data object will be passed as the first parameter.

name = 'link'
render(**kwargs)[source]
class horizon.tables.actions.NameFilterAction(**kwargs)[source]

Bases: horizon.tables.actions.FilterAction

A filter action for name property.

base_options = {'associate_with_table': <function associate_with_table at 0x7f424923c938>, 'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'get_param_name': <function get_param_name at 0x7f424923ccf8>, '__init__': <function __init__ at 0x7f424923cc80>, 'base_options': {'data_type_matched': <function data_type_matched at 0x7f424923c578>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, '__module__': 'horizon.tables.actions', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'Common base class for all ``Action`` classes.', 'base_options': {...}, '__init__': <function __init__ at 0x7f424923c500>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'associate_with_table': <function associate_with_table at 0x7f424923c938>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}, 'get_select_options': <function get_select_options at 0x7f424923cf50>, '_allowed': <function _allowed at 0x7f424923c6e0>, 'filter': <function filter at 0x7f424922f050>, 'update': <function update at 0x7f424923c758>, 'get_default_classes': <function get_default_classes at 0x7f424923c7d0>, 'get_policy_target': <function get_policy_target at 0x7f424923c5f0>, 'is_api_filter': <function is_api_filter at 0x7f424923ced8>, '__module__': 'horizon.tables.actions', 'name': 'filter', 'get_default_attrs': <function get_default_attrs at 0x7f424923c848>, '__doc__': 'A filter action for name property.', 'assign_type_string': <function assign_type_string at 0x7f424923cd70>, 'data_type_filter': <function data_type_filter at 0x7f424923cde8>, '__repr__': <function __repr__ at 0x7f424923c8c0>, 'allowed': <function allowed at 0x7f424923c668>}
filter(table, items, filter_string)[source]

Naive case-insensitive search.

class horizon.tables.actions.UpdateAction[source]

Bases: object

A table action for cell updates by inline editing.

action(request, datum, obj_id, cell_name, new_cell_value)[source]
static action_past(count)[source]
static action_present(count)[source]
allowed(request, datum, cell)[source]

Determine whether updating is allowed for the current request.

This method is meant to be overridden with more specific checks. Data of the row and of the cell are passed to the method.

name = 'update'
update_cell(request, datum, obj_id, cell_name, new_cell_value)[source]

Method for saving data of the cell.

This method must implements saving logic of the inline edited table cell.

Previous topic

The horizon.loaders Module

Next topic

The horizon.tables.base Module

Project Source

This Page