lino.utils.instantiator

Defines the Instantiator class and some other utilities used for generating database objects in python fixtures.

Example values:

>>> import json
>>> s = '<a href="javascript:Lino.pcsw.Clients.detail.run(null,{ &quot;record_id&quot;: 116 })">BASTIAENSEN Laurent (116)</a>'
>>> print(json.dumps(GFK_HACK.match(s).groups()))
["pcsw.Clients", "116"]
>>> s = '<a href="javascript:Lino.cal.Guests.detail.run(null,{ &quot;record_id&quot;: 6 })">Gast #6 ("Termin #51")</a>'
>>> print(json.dumps(GFK_HACK.match(s).groups()))
["cal.Guests", "6"]

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

Functions

create(model, **kw)

Instantiate, full_clean, save and return a database object.

create_and_get(model, **kw)

Create and then read back from database (the latter to avoid certain Django side effects)

create_or_update_row(model, lookup_values, ...)

Update a single existing row that can be found using param: lookup values, with new_values.

create_row(model, **kw)

Instantiate, full_clean, save and return a database object.

make_converter(f[, lookup_fields])

Classes

ChoiceConverter(field)

Converter for ChoiceListField.

Converter(field)

DateConverter(field)

DecimalConverter(field)

ForeignKeyConverter(field, lookup_field)

Converter for ForeignKey fields.

GenericForeignKeyConverter(field)

Converter for GenericForeignKey fields.

InstanceGenerator()

Usage example see lino_xl.lib.humanlinks.fixtures.

Instantiator(model[, fieldnames, ...])

A utility class to make python fixtures more compact.

LookupConverter(field, lookup_field)

A Converter for ForeignKey and ManyToManyField.

ManyToManyConverter(field, lookup_field)

Converter for ManyToMany fields.

Exceptions

DataError

class lino.utils.instantiator.LookupConverter(field, lookup_field)

Bases: lino.utils.instantiator.Converter

A Converter for ForeignKey and ManyToManyField. If the lookup_field is a BabelField, then it tries all available languages.

class lino.utils.instantiator.ChoiceConverter(field)

Bases: lino.utils.instantiator.Converter

Converter for ChoiceListField.

class lino.utils.instantiator.ForeignKeyConverter(field, lookup_field)

Bases: lino.utils.instantiator.LookupConverter

Converter for ForeignKey fields.

class lino.utils.instantiator.GenericForeignKeyConverter(field)

Bases: lino.utils.instantiator.Converter

Converter for GenericForeignKey fields.

class lino.utils.instantiator.ManyToManyConverter(field, lookup_field)

Bases: lino.utils.instantiator.LookupConverter

Converter for ManyToMany fields.

class lino.utils.instantiator.Instantiator(model, fieldnames=None, converter_classes={}, **kw)

Bases: object

A utility class to make python fixtures more compact. See The Instantiator class.

An instantiator is a

build(*values, **kw)

Instantiate an object using the default values of this instantiator, overridden by the given specified values. The number of positional arguments may not exceed the number of fieldnames specified when creating this Instantiator.

class lino.utils.instantiator.InstanceGenerator

Bases: object

Usage example see lino_xl.lib.humanlinks.fixtures.

lino.utils.instantiator.create_row(model, **kw)

Instantiate, full_clean, save and return a database object.

lino.utils.instantiator.create_or_update_row(model, lookup_values, new_values)

Update a single existing row that can be found using param: lookup values, with new_values. If one doesn't exist, instantiates, full_cleans, saves and returns a database object

lino.utils.instantiator.create(model, **kw)

Instantiate, full_clean, save and return a database object.

lino.utils.instantiator.create_and_get(model, **kw)

Create and then read back from database (the latter to avoid certain Django side effects)