The horizon.tables.actions Module

class horizon.tables.actions.Action(verbose_name=None, verbose_name_plural=None, single_func=None, multiple_func=None, handle_func=None, handles_multiple=False, attrs=None, requires_input=True, allowed_data_types=[], datum=None)[source]

Bases: horizon.tables.actions.BaseAction

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

horizon.tables.actions.name

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

horizon.tables.actions.verbose_name

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

horizon.tables.actions.verbose_name_plural

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

horizon.tables.actions.method

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

horizon.tables.actions.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.

horizon.tables.actions.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.

horizon.tables.actions.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.

At least one of the following methods must be defined:

horizon.tables.actions.single(self, data_table, request, object_id)

Handler for a single-object action.

horizon.tables.actions.multiple(self, data_table, request, object_ids)

Handler for multi-object actions.

horizon.tables.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.

Action.get_param_name()[source]

Returns the full POST parameter name for this action.

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

Action.method = 'POST'
Action.requires_input = True
class horizon.tables.actions.BaseAction(datum=None)[source]

Bases: horizon.utils.html.HTMLElement

Common base class for all Action classes.

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

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

BaseAction.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 }}.

BaseAction.get_default_classes()[source]

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

BaseAction.handles_multiple = False
BaseAction.preempt = False
BaseAction.requires_input = False
BaseAction.table = None
BaseAction.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.BatchAction[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.
horizon.tables.actions.name

An internal name for this action.

horizon.tables.actions.action_present

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

horizon.tables.actions.action_past

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

horizon.tables.actions.data_type_singular

A display name for the type of data that receives the action. (“Keypair”, “Floating IP”, etc.)

horizon.tables.actions.data_type_plural

Optional plural word 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.

horizon.tables.actions.success_url

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

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

BatchAction.get_success_url(request=None)[source]

Returns the URL to redirect to after a successful action.

BatchAction.handle(table, request, obj_ids)[source]
BatchAction.success_url = None
BatchAction.update(request, datum)[source]

Switches the action verbose name, if needed

class horizon.tables.actions.DeleteAction[source]

Bases: horizon.tables.actions.BatchAction

DeleteAction.action(request, obj_id)[source]
DeleteAction.action_past = <django.utils.functional.__proxy__ object at 0x64dbed0>
DeleteAction.action_present = <django.utils.functional.__proxy__ object at 0x64dbe50>
DeleteAction.delete(request, obj_id)[source]
DeleteAction.get_default_classes()[source]
DeleteAction.name = 'delete'
class horizon.tables.actions.FilterAction(verbose_name=None, param_name=None)[source]

Bases: horizon.tables.actions.BaseAction

A base class representing a filter action for a table.

horizon.tables.actions.name

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

horizon.tables.actions.verbose_name

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

horizon.tables.actions.param_name

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

FilterAction.assign_type_string(table, data, type_string)[source]
FilterAction.data_type_filter(table, data, filter_string)[source]
FilterAction.filter(table, data, filter_string)[source]

Provides the actual filtering logic.

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

FilterAction.filter_type = 'query'
FilterAction.get_default_classes()[source]
FilterAction.get_param_name()[source]

Returns the full query parameter name for this action.

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

FilterAction.method = 'POST'
FilterAction.name = 'filter'
FilterAction.needs_preloading = False
FilterAction.verbose_name = <django.utils.functional.__proxy__ object at 0x64dbc90>
class horizon.tables.actions.FixedFilterAction(*args, **kwargs)[source]

Bases: horizon.tables.actions.FilterAction

A filter action with fixed buttons.

FixedFilterAction.categorize(table, images)[source]

Override to separate images into categories.

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

FixedFilterAction.filter(table, images, filter_string)[source]
FixedFilterAction.filter_type = 'fixed'
FixedFilterAction.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 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.
FixedFilterAction.needs_preloading = True
class horizon.tables.actions.LinkAction(verbose_name=None, allowed_data_types=[], url=None, attrs=None)[source]

Bases: horizon.tables.actions.BaseAction

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

horizon.tables.actions.name

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

horizon.tables.actions.verbose_name

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

horizon.tables.actions.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.

horizon.tables.actions.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.

LinkAction.bound_url = None
LinkAction.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.

LinkAction.method = 'GET'

Previous topic

The horizon.tables.base Module

Next topic

The horizon.utils.memoized Module

This Page