lino.core.store

Defines the "store" and its "fields" .

During startup, Lino instantiates a "store" and its "fields" (aka "atomizers") for every table. These were used originally for dealing with Sencha ExtJS GridPanels and FormPanels, but the concept turned out useful for other features.

Some usages specific to Sencha ExtJS:

  • for generating the JS code of the GridPanel definition

  • for generating an "atomized" JSON representation when rendering data for that GridPanel

  • for parsing the JSON sent by GridPanel and FormPanel

Other usages:

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

Functions

create_atomizer(holder, fld, name)

The holder is where the (potential) choices come from.

get_atomizer(holder, fld, name)

Return the atomizer for this database field.

Classes

AutoStoreField(field, name, **kw)

A StoreField for AutoField

BaseStore()

BooleanStoreField(field, name, **kw)

A StoreField for BooleanField.

ComboStoreField(field, name, **options)

An atomizer for all kinds of fields which use a ComboBox.

DateStoreField(field, name, **kw)

DateTimeStoreField(field, name, **options)

DecimalStoreField(field, name, **options)

DisableEditingStoreField(store)

A field whose value is the result of the get_row_permission method on that row.

DisabledFieldsStoreField(store)

See also blog entries 20100803, 20111003, 20120901

DisplayStoreField(field, name, **options)

FileFieldStoreField(field, name, **options)

ForeignKeyStoreField(field, name, **options)

An atomizer used for all ForeignKey fields.

GenericForeignKeyField(field, name, **options)

GenericRelField(field, name, **options)

IncompleteDateStoreField(field, name, **options)

IntegerStoreField(field, name, **kw)

MethodStoreField(field, name, **options)

Deprecated.

OneToOneRelStoreField(field, name, **options)

OneToOneStoreField(field, name, **options)

ParameterStore(params_layout_handle, url_param)

PasswordStoreField(field, name, **options)

RelatedMixin()

Common methods for ForeignKeyStoreField and OneToOneStoreField.

RequestStoreField(vf, delegate, name)

StoreField for lino.core.fields.RequestField.

RowClassStoreField(store)

SpecialStoreField(store)

Store(rh, **options)

A Store is the collection of StoreFields for a given actor.

StoreField(field, name, **options)

Base class for the fields of a Store.

TimeStoreField(field, name, **options)

VirtStoreField(vf, delegate, name)

class lino.core.store.StoreField(field, name, **options)

Bases: object

Base class for the fields of a Store.

field

The database field (a subclass of django.db.models.fields.Field)

options

A dict with options to be used by as_js().

Note: value_from_object and full_value_from_object are similar, but for ForeignKeyStoreField and GenericForeignKeyField one returns the primary key while the latter returns the full instance.

form2obj_default = None

because checkboxes are not submitted when they are off

list_values_count = 1

Necessary to compute Store.pk_index.

as_js(name)

Return a Javascript string which defines this atomizer as an object. This is used by lino.modlib.extjs.ext_renderer. and in case of virtual remote fields they use the virtual field's delegate as_js method but with their own name.

form2obj(ar, instance, post_data, is_new)

Test cases:

  • setting a CharField to '' will store either '' or None, depending on whether the field is nullable or not.

  • sales.Invoice.number may be blank

format_value(ar, v)

Return a plain textual representation as a unicode string of the given value v. Note that v might be None.

class lino.core.store.RelatedMixin

Bases: object

Common methods for ForeignKeyStoreField and OneToOneStoreField.

class lino.core.store.ComboStoreField(field, name, **options)

Bases: lino.core.store.StoreField

An atomizer for all kinds of fields which use a ComboBox.

class lino.core.store.ForeignKeyStoreField(field, name, **options)

Bases: lino.core.store.RelatedMixin, lino.core.store.ComboStoreField

An atomizer used for all ForeignKey fields.

parse_form_value(v, obj)

Convert the form field value (expected to contain a primary key) into the corresponding database object. If it is an invalid primary key, return None.

If this comes from a learning ExtJS ComboBox (i.e. can_create_choice is True) the value will be the text entered by the user. In that case, call create_choice.

class lino.core.store.RequestStoreField(vf, delegate, name)

Bases: lino.core.store.StoreField

StoreField for lino.core.fields.RequestField.

class lino.core.store.DisabledFieldsStoreField(store)

Bases: lino.core.store.SpecialStoreField

See also blog entries 20100803, 20111003, 20120901

Note some special cases:

  • lino.modlib.vat.VatDocument.total_incl (readonly virtual PriceField) must be disabled and may not get submitted. ExtJS requires us to set this dynamically each time.

  • JobsOverview.body (a virtual HtmlBox) or Model.workflow_buttons (a displayfield) must not have the 'disabled' css class.

  • after submitting a Lockable, the

class lino.core.store.DisableEditingStoreField(store)

Bases: lino.core.store.SpecialStoreField

A field whose value is the result of the get_row_permission method on that row. New feature since /blog/2011/0830

class lino.core.store.BooleanStoreField(field, name, **kw)

Bases: lino.core.store.StoreField

A StoreField for BooleanField.

parse_form_value(v, obj)

Ext.ensible CalendarPanel sends boolean values as

class lino.core.store.AutoStoreField(field, name, **kw)

Bases: lino.core.store.StoreField

A StoreField for AutoField

class lino.core.store.MethodStoreField(field, name, **options)

Bases: lino.core.store.StoreField

Deprecated. See /blog/2012/0327. Still used for display_mode 'html'.

lino.core.store.get_atomizer(holder, fld, name)

Return the atomizer for this database field. The atomizer is an instance of a subclass of StoreField.

lino.core.store.create_atomizer(holder, fld, name)

The holder is where the (potential) choices come from. It can be a model, an actor or an action.

class lino.core.store.Store(rh, **options)

Bases: lino.core.store.BaseStore

A Store is the collection of StoreFields for a given actor. Instantiated in kernel

collect_fields(fields, *layouts)

fields is a pointer to either self.detail_fields or self.list_fields. Each of these must contain a primary key field.

form2obj(ar, form_values, instance, is_new)

Store the form_values into the instance by calling form2obj() for every store field.

column_index(name)

Used to set disabled_actions_index. Was used to write definition of Ext.ensible.cal.CalendarMappings and Ext.ensible.cal.EventMappings