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

lino.mixins.registrable

This defines the Registable model mixin.

Classes

Registrable(*args, **kwargs)

Base class to anything that may be "registered" and "deregistered", where "registered" means "this object has been taken account of".

RegistrableState([value, text, names])

Base class for the choices of the choicelist that defines the state field of any Registrable.

class lino.mixins.registrable.RegistrableState(value=None, text=None, names=None, **kwargs)

Bases: State

Base class for the choices of the choicelist that defines the state field of any Registrable.

is_editable = True

Whether the registrable object having this state should be editable or not.

class lino.mixins.registrable.Registrable(*args, **kwargs)

Bases: Model

Base class to anything that may be “registered” and “deregistered”, where “registered” means “this object has been taken account of”.

For example, when a ledger voucher is registered, its associated ledger movements have been generated. Deregistering a voucher will first delete these movements.

Registered objects are usually not editable, but this readonlyness is usually limited to certain fields.

lino_xl.lib.cal.Reservation is an example of a registrable that is not a ledger voucher.

Subclasses must themselves define a field state.

state

The workflow state field.

This field must be a choicelist field, and the choices representing these states must be subclasses of RegistrableState.

There must be one state named “draft”, which will be set e.g. after duplicating a registered object.

There is no need to have a state named “registered”. Actually “registered” means “in a non editable state”.

classmethod get_registrable_fields(site)

Return a list of the fields that are disabled when this is registered (i.e. state is not editable).

Usage example:

class MyModel(dd.Registrable):

    @classmethod
    def get_registrable_fields(self, site):
        for f in super(MyModel, self).get_registrable_fields(site):
            yield f
        yield 'user'
        yield 'date'
get_row_permission(ar, state, ba)

Only rows in an editable state may be edited.

Note that ba is the action being requested while ar.bound_action is the action from which the request was started.

register(ar)

Register this object. The base implementation just sets the state to “registered”.

Subclasses may override this to add custom behaviour. Instead of subclassing you can also override set_workflow_state, before_state_change or after_state_change.

deregister(ar)

Deregister this object. The base implementation just sets the state to “draft”.

Subclasses may override this to add custom behaviour. Instead of subclassing you can also override set_workflow_state, before_state_change or after_state_change.