Elements

Declaration

Elements must be declared in the YAML file under the elements entry. Every element is declared by its identifier, and its definition is:

  • either a list of parameters, e.g.:

    elements:
        do_something:
            type: ACTION
            label: Do something
    
  • or just a string, in which case Rapido will assume it is the type parameter, e.g.:

    elements:
        message: BASIC
    

    is equivalent to:

    elements:
        message:
            type: BASIC
    

Types

There are different types of elements (defined by the type parameter):

  • BASIC: a piece of HTML returned by its implementation function.
  • ACTION: a button that will execute the implementation function when clicked. Its label is provided by the label parameter.
  • TEXT: a text input field.
  • NUMBER: a number input field.
  • DATETIME: a date/time input field.

Input elements

Input elements (i.e. TEXT, NUMBER, or DATETIME) can be indexed as field or text. Indexing is indicated using the index_type parameter.

By default, input elements are editable but they might also have a different mode:

  • COMPUTED_ON_SAVE: the value is computed every time the record is saved,
  • COMPUTED_ON_CREATION: the value is computed when the record is created.

Action elements

Action elements are rendered as submit buttons and allow to trigger a call to an associated Python function.

If the function returns a value, it must be a string, and it will be used as a redirection URL for the current request.

This is the way to redirect to another location once the action has been executed.

Builtin actions

The following actions can be included in our block HTML layout, and do not require an associated Python function:

  • _save: creates a record based on the field elements’ submitted values, and then redirects to the record display in read mode;
  • _edit: opens the current record in edit mode;
  • _delete: deletes the current record.

Direct HTTP call to elements

We usually want to display blocks, but we can also call an element by its URL:

Both GET and POST requests are supported.

If the element is an action, its Python function will be executed; the returned value is supposed to be a string and will be used as a redirection URL. When building an application, it allows us to create links that will redirect the user to the proper location depending on our business criteria (e.g. if the user belongs to group A, go to page1, else go to page2).

If the element is not an action, its Python function will be executed, and the result is returned as a response.

Note

We can change the response content type like this:

def my_element(context):
    context.request.reponse.setHeader('content-type', 'text/csv')
    return "one,two,three\n1,2,3"