lino.core.actions

This defines the Action class and the action() decorator, and some of the standard actions. See Introduction to actions.

(This module's source code is available here.)

Functions

action(*args, **kw)

Return a decorator which turns an instance method on a model or a class method on an actor into an action of this class.

discover_choosers()

get_view_permission(e)

install_layout(cls, k, layout_class, **options)

  • cls is the actor (a class object)

make_params_layout_handle(self)

register_params(cls)

cls is either an actor (a class object) or an action (an instance).

setup_params_choosers(self)

Classes

Action([label])

Abstract base class for all actions.

CreateRow([label])

Called when user edited a cell of a phantom record in a grid.

DeleteSelected([label])

Delete the selected row(s).

ExplicitRefresh([label])

MultipleRowAction([label])

Base class for actions that update something on every selected row.

SaveGridCell([label])

Called when user edited a cell of a non-phantom record in a grid.

ShowDetail(dl[, label])

ShowEmptyTable(dl[, label])

The default action for lino.utils.report.EmptyTable.

ShowInsert([label])

ShowSlaveTable(slave_table, **kw)

An action which opens a window showing another table (to be specified when instantiating the action).

ShowTable([label])

SubmitDetail([label])

Save changes in the detail form.

SubmitInsert([label])

TableAction([label])

ValidateForm([label])

lino.core.actions.install_layout(cls, k, layout_class, **options)
  • cls is the actor (a class object)

  • k is one of 'detail_layout', 'insert_layout', 'params_layout', 'card_layout'

  • layout_class

lino.core.actions.register_params(cls)

cls is either an actor (a class object) or an action (an instance).

class lino.core.actions.Action(label=None, **kwargs)

Bases: lino.core.utils.Parametrizable, lino.core.permissions.Permittable

Abstract base class for all actions.

The first argument is the optional label, other arguments should be specified as keywords and can be any of the existing class attributes.

button_text = None

The text to appear on buttons for this action. If this is not defined, the label is used.

button_color = None

The color to be used on icon-less buttons for this action (i.e. which have no icon_name). See also lino.core.site.Site.use_silk_icons.

Not yet implemented. This is currently being ignored.

disable_primary_key = True

Whether primary key fields should be disabled when using this action. This is True for all actions except ShowInsert.

keep_user_values = False

Whether the parameter window should keep its values between different calls. If this is True, Lino does not fill any default values and leaves those from a previous call.

Deprecated because it (1) is not used on any production site, (2) has a least two side effect: the fields never get a default value, even not on first execution, and you cannot explicitly specify programmatic field values. And (3) we actually wouldn't want to specify this per action but per field.

icon_name = None

The class name of an icon to be used for this action when rendered as toolbar button. Allowed icon names are defined in lino.core.constants.ICON_NAMES.

combo_group = None

The name of another action to which to "attach" this action. Both actions will then be rendered as a single combobutton.

use_param_panel = False

Used internally. This is True for window actions whose window use the parameter panel: grid and emptytable (but not showdetail)

no_params_window = False

Set this to True if your action has parameters but you do not want it to open a window where the user can edit these parameters before calling the action.

Setting this attribute to True means that the calling code must explicitly set all parameter values. Usage example are the lino_xl.lib.polls.models.AnswersByResponse.answer_buttons and lino_xl.lib-tickets.Ticket.quick_assign_to virtual fields.

sort_index = 90

Determines the sort order in which the actions will be presented to the user.

List actions are negative and come first.

Predefined sort_index values are:

value

action

-1

as_pdf

10

ShowInsert

11

duplicate

20

detail

30

delete

31

merge

50

Print

51

Clear Cache

52

lino.modlib.users.UserPlan.start_plan

53

lino.modlib.users.UserPlan.update_plan

60

ShowSlaveTable

90

default for all custom row actions

100

SubmitDetail

200

default for all workflow actions (ChangeStateAction)

help_text = None

A help text that shortly explains what this action does. In a graphical user interface this will be rendered as a tooltip text.

If this is not given by the code, Lino will potentially set it at startup when loading the help_texts.py files.

submit_form_data = False

Should the running of the action include all known form values in the request.

auto_save = True

What to do when this action is being called while the user is on a dirty record.

  • False means: forget any changes in current record and run the action.

  • True means: save any changes in current record before running the action. None means: ask the user.

extjs_main_panel = None

Used by lino_xl.lib.extensible and lino.modlib.awesome_uploader.

Example:

class CalendarAction(dd.Action):
    extjs_main_panel = "Lino.CalendarApp().get_main_panel()"
    ...
js_handler = None

This is usually None. Otherwise it is the name of a Javascript callable to be called without arguments. That callable must have been defined in a lino.core.plugin.Plugin.site_js_snippets of the plugin.

action_name = None

Internally used to store the name of this action within the defining Actor's namespace.

defining_actor = None

The lino.core.actors.Actor who uses this action for the first time. This is set during attach_to_actor(). This is used internally e.g. by lino.modlib.extjs when generating JavaScript code for certain actions.

parameters = None

See lino.core.utils.Parametrizable.parameters.

key = None

Not used. The keyboard hotkey to associate to this action in a user interface.

default_format = 'html'

Used internally.

editable = True

Whether the parameter fields should be editable. Setting this to False seems nonsense.

hide_top_toolbar = False

Used internally if opens_a_window to say whether the window has a top toolbar.

hide_navigator = False

Used internally if opens_a_window to say whether the window has a navigator.

show_in_plain = False

Whether this action should be displayed as a button in the toolbar of a plain html view.

show_in_bbar = True

Whether this action should be displayed as a button in the toolbar and the context menu of a full grid.

For example the CheckinVisitor, ReceiveVisitor and CheckoutVisitor actions have this attribute explicitly set to False because otherwise they would be visible in the toolbar.

show_in_workflow = False

Whether this action should be displayed in the workflow_buttons column. If this is True, then Lino will automatically set custom_handler to True.

select_rows = True

True if this action needs an object to act on.

Set this to False if this action is a list action, not a row action.

http_method = 'GET'

HTTP method to use when this action is called using an AJAX call.

preprocessor = 'null'

Name of a Javascript function to be invoked on the web client when this action is called.

window_type = None

On actions that opens_a_window this must be a unique one-letter string expressing the window type.

Allowed values are:

  • None : opens_a_window is False

  • 't' : ShowTable

  • 'd' : ShowDetail

  • 'i' : ShowInsert

This can be used e.g. by a summary view to decide how to present the summary data (usage example lino.modlib.uploads.AreaUploads.get_table_summary()).

callable_from = 'td'

A string that specifies from which window_type this action is callable. None means that it is only callable from code.

Default value is 'td' which means from both table and detail (including ShowEmptyTable which is subclass of ShowDetail). But not callable from ShowInsert.

label = None

The label of this action. A short descriptive text in user language. Used e.g. on menu items. Also on toolbar buttons if they have neither icon_name nor button_text.

custom_handler = False

Whether this action is implemented as Javascript function call. This is necessary if you want your action to be callable using an "action link" (html button).

get_django_form()

returns a django form object based on the params of this action

classmethod decorate(*args, **kw)

Return a decorator which turns an instance method on a model or a class method on an actor into an action of this class.

The decorated method will be installed as the actions's run_from_ui method.

All arguments are forwarded to Action.__init__().

is_callable_from(caller)

Return True if this action makes sense as a button from within the specified caller (an action instance which must have a window_type). Do not override this method on your subclass ; rather specify callable_from.

is_window_action()

Return True if this is a "window action" (i.e. which opens a GUI window on the client before executin).

get_label()

Return the label of this action, or the action_name if the action has no explicit label.

attach_to_actor(owner, name)

Called once per actor and per action on startup before a BoundAction instance is created. If this returns False, then the action won't be attached to the given actor.

The owner is the actor which "defines" the action, i.e. uses that instance for the first time. Subclasses of the owner may re-use the same instance without becoming the owner.

get_action_permission(ar, obj, state)

Return (True or False) whether the given ActionRequest ar should get permission to run on the given Model instance obj (which is in the given state).

Derived Action classes may override this to add vetos. E.g. the MoveUp action of a Sequenced is not available on the first row of given ar.

This should be used only for light-weight tests. If this requires a database lookup, consider disabling the action in disabled_fields where you can disable multiple actions and fields at once.

get_view_permission(user_type)

Return True if this action is visible for users of given user_type.

run_from_ui(ar, **kwargs)

Execute the action. ar is an ActionRequest object representing the context in which the action is running.

run_from_code(ar=None, *args, **kwargs)

Probably to be deprecated. Execute the action. The default calls run_from_ui(). You may override this to define special behaviour

action_param_defaults(ar, obj, **kw)

Same as lino.core.actors.Actor.param_defaults(), except that on an action it is a instance method.

Note that this method is not called for actions which are rendered in a toolbar (#1336).

Usage examples: lino.modlib.users.actions.SendWelcomeMail

get_layout_aliases()

Yield a series of (ALIAS, repl) tuples that cause a name ALIAS in a layout based on this action to be replaced by its replacement repl.

class lino.core.actions.ShowEmptyTable(dl, label=None, **kwargs)

Bases: lino.core.actions.ShowDetail

The default action for lino.utils.report.EmptyTable.

class lino.core.actions.SaveGridCell(label=None, **kwargs)

Bases: lino.core.actions.Action

Called when user edited a cell of a non-phantom record in a grid. Installed as update_action on every Actor.

class lino.core.actions.SubmitDetail(label=None, **kwargs)

Bases: lino.core.actions.SaveGridCell

Save changes in the detail form.

This is rendered as the "Save" button of a detail window.

Installed as submit_detail on every actor.

class lino.core.actions.CreateRow(label=None, **kwargs)

Bases: lino.core.actions.Action

Called when user edited a cell of a phantom record in a grid.

save_new_instances(ar, elems)

Currently only used for file uploads.

class lino.core.actions.ShowSlaveTable(slave_table, **kw)

Bases: lino.core.actions.Action

An action which opens a window showing another table (to be specified when instantiating the action).

class lino.core.actions.MultipleRowAction(label=None, **kwargs)

Bases: lino.core.actions.Action

Base class for actions that update something on every selected row.

run_on_row(obj, ar)

This is being called on every selected row.

class lino.core.actions.DeleteSelected(label=None, **kwargs)

Bases: lino.core.actions.MultipleRowAction

Delete the selected row(s).

This action is automatically installed on every editable actor.

lino.core.actions.action(*args, **kw)

Return a decorator which turns an instance method on a model or a class method on an actor into an action of this class.

The decorated method will be installed as the actions's run_from_ui method.

All arguments are forwarded to Action.__init__().