Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

lino.core.requests

See introduction in Using action requests and API reference in lino.api.core.Request.

Functions

bool2text(x)

column_header(col)

noop(ar)

sliced_data_iterator(qs, offset, limit)

Classes

ActionRequest([actor, action, rqdata])

Holds information about an individual web request and provides methods like

BaseRequest([request, parent, ...])

SearchQuery()

SearchQuerySet()

StringLogger(parent, level)

ValidActionResponses()

These are the allowed keyword arguments for ar.set_response, and the action responses supported by Lino.handle_action_result() (defined in linolib.js).

class lino.core.requests.ValidActionResponses

Bases: object

These are the allowed keyword arguments for ar.set_response, and the action responses supported by Lino.handle_action_result() (defined in linolib.js).

This class is never instantiated, but used as a placeholder for these names and their documentation.

message = None

A translatable message text to be shown to the user.

alert = None

Set this to some translatable text to specify that the message is rather important and should alert and should be presented in a dialog box to be confirmed by the user. The text is used as the title of the alert box. If you specify True, then Lino uses a default text like “Alert” or “Warning” (depending on context).

alert_eval_js = None

Javascript code to be evaluated after the confirmation of the alert dialog.

rows = None

An iterable of database objects that will be serialized as a list.

title = None

The dynamic title to give to the window or component which shows this response. TODO: is this still being used?

count = None

The number of rows in a list response.

data_record = None

Certain requests are expected to return detailed information about a single data record. That’s done in data_record which must itself be a dict with the following keys:

  • id : the primary key of this record_deleted

  • title : the title of the detail window

  • data : a dict with one key for every data element

  • navinfo : an object with information for the navigator

  • disable_delete : either null (if that record may be deleted, or otherwise a message explaining why.

record_id = None

When an action returns a record_id, it asks the user interface to jump to the given record.

refresh_delayed_value = None

A string referencing an actor_id corresponding to a DelayedValue equivalent element or boolean True meaning all the DelayedValue(s) should be refreshed.

xcallback = None

Used for dialogs asking simple yes/no/later style questions. Includes all the data the client needs in order to send the same action request again, but with some extra confirmation values.

Is a dict which includes the following values:

  • actor_id : The id of the actor

  • an : The action name of the action which was run

  • sr : List of selected values

goto_url = None

Leave current page and go to the given URL.

open_url = None

Open the given URL in a new browser window.

warning_message = None

deprecated

detail_handler_name = None

The name of the detail handler to be used. Application code should not need to use this. It is automatically set by ActorRequest.goto_instance().

class lino.core.requests.ActionRequest(actor=None, action=None, rqdata=None, **kw)

Bases: BaseRequest

Holds information about an individual web request and provides methods like

  • get_user

  • confirm

  • spawn

An ActionRequest is also a BaseRequest and inherits its methods.

An ActionRequest is instantiated from different shortcut methods:

gen_insert_button(target=None, button_attrs={'style': 'float: right;'}, **values)

Generate an insert button using a cached insertable object.

This is functionally equivalent to saying:

if self.insert_action is not None:
    ir = self.insert_action.request_from(ar)
    if ir.get_permission():
        return ir.ar2button()

The difference is that gen_insert_button is more efficient when you do this more than once during a single request.

target is the actor into which we want to insert an object. When this is None, Lino uses self.actor. button_attrs if given, are forwarded to ar2button(). values is a dict of extra default values to apply to the insertable object.

The values must be atomized by the caller, which is especially important when you want to set a foreign key field. So instead of saying:

gen_insert_button(None, user=u)

you must say:

gen_insert_button(None, user=u.pk, userHidden=str(u))

First usage example is in lino_xl.lib.calview. Second usage example is lino_prima.lib.prima.PupilsAndProjects.

run(*args, **kw)

Runs this action request.

execute()

This will actually call the get_data_iterator() and run the database query.

Automatically called when either data_iterator or sliced_data_iterator is accesed.

get_total_count()

Return the number of rows.

When actor is not a table, we assume that there is one row. This is used e.g. when courses.StatusReport is shown in the the dashboard. A Report must return 1 because otherwise the dashboard believes it is empty.

Calling len() on a QuerySet would execute the whole SELECT. See /blog/2012/0124

create_instance(**kw)

Create a row (a model instance if this is a database table) using the specified keyword arguments.

get_status(**kw)

Return a dict with the “status”, i.e. a json representation of this request.

clear_cached_status()

Remove any previously computed status information.

The status information of a request is cached to avoid performance issues e.g. in calendar views where a many buttons can be rendered for a same request and where the status information can be relatively heavy.

But sometimes you don’t want this. In that case you call clear_cached_status().

to_rst(*args, **kw)

Returns a string representing this table request in reStructuredText markup.

table2rst(*args, **kwargs)

Print a reStructuredText representation of this table request to stdout.

table2xhtml(**kwargs)

Return an HTML representation of this table request.

dump2html(tble, data_iterator, column_names=None, header_links=False, max_width=None, show_links=None, hide_sums=None)

Render this table into an existing etgen.html.Table instance. This central method is used by all Lino renderers.

Arguments:

tble An instance of etgen.html.Table.

data_iterator the iterable provider of table rows. This can be a queryset or a list.

column_names is an optional string with space-separated column names. If this is None, the table’s column_names is used.

header_links says whether to render column headers clickable with a link that sorts the table.

hide_sums : whether to hide sums. If this is not given, use the hide_sums of the actor.

get_field_info(column_names=None)

Return a tuple (fields, headers, widths) which expresses which columns, headers and widths the user wants for this request. If self has web request info (request is not None), checks for GET parameters cn, cw and ch. Also calls the tables’s override_column_headers method.

row2text(fields, row, sums)

Render the given row into an iteration of text cells, using the given list of fields and collecting sums into sums.