Bloks

Blok anyblok-core

class anyblok.bloks.anyblok_core.AnyBlokCore(registry)

Bases: anyblok.blok.Blok

This blok is required by all anyblok application. This blok define the main fonctionnality to install, update and uninstall blok. And also list the known models, fields, columns and relationships

author = 'Suzanne Jean-Sébastien'
autoinstall = True
conditional_by = []
conflicting_by = []
classmethod import_declaration_module()
logo = '../anyblok-logo_alpha_256.png'
name = 'anyblok-core'
optional_by = []
pre_migration(latest_version)
pre_migration_0_4_1_fields_become_polymorphic(latest_version)
priority = 0
classmethod reload_declaration_module(reload)
required_by = ['anyblok-io']
version = '0.16.1'

This blok is required by all anyblok application. This blok define the main fonctionnality to install, update and uninstall blok. And also list the known models, fields, columns and relationships:

  • Core Model
    • Base: inherited by all the Model
    • SqlBase: Inherited only by the model with table
    • SqlViewBase: Inherited only by the sql view model
  • System Models
    • Blok: List the bloks
    • Model: List the models
    • Field: List of the fields
    • Column: List of the columns
    • Relationship: List of the relation ship
    • Sequence: Define database sequence
    • Parameter: Define application parameter

Sequence

Some behaviours need to have sequence:

sequence = registry.System.Sequence.insert(
    code="string code",
    formater="One prefix {seq} One suffix")

Note

It is a python formater, you can use the variable:

  • seq: numero of the current data base sequence
  • code: code field
  • id: id field

Get the next value of the sequence:

sequence.nextval()

exemple:

seq = Sequence.insert(code='SO', formater="{code}-{seq:06d}")
seq.nextval()
>>> SO-000001
seq.nextval()
>>> SO-000002

Parameter

Parameter is a simple model key / value:

  • key: must be a String
  • value: any type

Add new value in the paramter model:

registry.System.Parameter.set(key, value)

Note

If the key already exist, then the value of the key is updated

Get an existing value:

registry.System.Parameter.get(key)

Warning

If the key does not existing then an ExceptionParameter will raise

Check the key exist:

registry.System.Parameter.is_exist(key)  # return a Boolean

Return and remove the parameter:

registry.System.Parameter.pop(key)

API doc

Authorization

class anyblok.bloks.anyblok_core.authorization.Authorization

Bases: object

Namespace for models supporting authorization policies.

class anyblok.bloks.anyblok_core.authorization.DefaultModelDeclaration

Bases: object

Pseudo model to represent the default value.

Core

class anyblok.bloks.anyblok_core.core.base.Base

Bases: object

Inherited by all the models

Declaration type:
 Core
Registry name:Core.Base
classmethod fire(event, *args, **kwargs)

Call a specific event on the model

Parameters:event – Name of the event
classmethod from_primary_keys(**pks)

No SQL Model has not primary key

classmethod get_primary_keys(**pks)

No SQL Model has not primary key

classmethod has_model_perm(principals, permission)

Check that one of principals has permission on given model.

Since this is a classmethod, even if called on a record, only its model class will be considered for the permission check.

has_perm(principals, permission)

Check that one of principals has permission on given record.

Since this is an ordinary instance method, it can’t be used on the model class itself. For this use case, see has_model_perm()

classmethod initialize_model()

This method is called to initialize a model during the creation of the registry

classmethod postcommit_hook(method, *args, **kwargs)

Same in the registry a hook to call just after the commit

you can choice if the hook is called in function of call_only_if:

  • commited: Call if the commit is done without exception
  • raised: Call if one exception was raised
  • always: Always call

Warning

Only one instance with same paramters of the hook is called after the commit

Parameters:
  • method – the method to call on this model
  • put_at_the_end_if_exist – If True the hook is move at the end
  • call_only_if – [‘commited’ (default), ‘raised’, ‘always’]
classmethod precommit_hook(method, *args, **kwargs)

Same in the registry a hook to call just before the commit

Warning

Only one instance with same parameters of the hook is called before the commit

Parameters:
  • method – the method to call on this model
  • put_at_the_end_if_exist – If True the hook is move at the end
to_primary_keys()

No SQL Model has not primary key

class anyblok.bloks.anyblok_core.core.sqlbase.SqlMixin

Bases: object

classmethod aliased(*args, **kwargs)

Facility to Apply an aliased on the model:

MyModelAliased = MyModel.aliased()

is equal at:

from sqlalchemy.orm import aliased
MyModelAliased = aliased(MyModel)
Return type:SqlAlchemy aliased of the model
classmethod from_multi_primary_keys(*pks)

return the instances of the model from the primary keys

Parameters:*pks – list of dict [{primary_key: value, …}]
Return type:instances of the model
classmethod from_primary_keys(**pks)

return the instance of the model from the primary keys

Parameters:**pks – dict {primary_key: value, …}
Return type:instance of the model
classmethod getFieldType(name)

Return the type of the column

TheModel.getFieldType(nameOfTheColumn)

this method take care if it is a polymorphic model or not

Parameters:name – name of the column
Return type:String, the name of the Type of column used
get_hybrid_property_columns()

Return the hybrid properties columns name from the Model and the inherited model if they come from polymorphisme

Cached classmethod with size=128

classmethod get_primary_keys()

return the name of the primary keys of the model

Type:list of the primary keys name
classmethod get_where_clause_from_primary_keys(**pks)

return the where clause to find object from pks

Parameters:**pks – dict {primary_key: value, …}
Return type:where clause
Exception:SqlBaseException
classmethod query(*elements)

Facility to do a SqlAlchemy query:

query = MyModel.query()

is equal at:

query = self.registry.session.query(MyModel)
Parameters:elements – pass at the SqlAlchemy query, if the element is a string then thet are see as field of the model
Return type:SqlAlchemy Query
to_dict(*fields)

Transform a record to the dict of value

Parameters:fields

list of fields to put in dict; if not selected, fields then take them all. A field is either one of these:

  • a string (which is the name of the field)
  • a 2-tuple if the field is a relationship (name of the field, tuple of foreign model fields)
Return type:dict

Here are some examples:

=>> instance.to_dict()  # get all fields
{"id": 1,
 "column1": "value 1",
 "column2": "value 2",
 "column3": "value 3",
 "relation1": {"relation_pk_1": 42, "relation_pk_2": "also 42"}
                                # m2o or o2o : this is a dictionary
 "relation2": [{"id": 28}, {"id": 1}, {"id": 34}]
                    # o2m or m2m : this is a list of dictionaries
 }

=>> instance.to_dict("column1", "column2", "relation1")
            # get selected fields only (without any constraints)
{"column1": "value 1",
 "column2": "value 2",
 "relation1": {"relation_pk_1": 42, "relation_pk_2": "also 42"}
 }

=>> instance.to_dict("column1", "column2", (
            # select fields to use in the relation related model
    "relation1", ("relation_pk1", "name", "value")
                # there is no constraints in the choice of fields
    ))
{"column1": "value",
 "column2": "value",
 "relation1": {"relation_pk_1": 42, "name": "H2G2", "value": "42"}
 }

=>> instance.to_dict("column1", "column2", ("relation1", ))
# or
=>> instance.to_dict("column1", "column2", ("relation1", None))
# or
=>> instance.to_dict("column1", "column2", ("relation1", ()))
                      # select all the fields of the relation ship
{"column1": "value",
 "column2": "value",
 "relation1": {"relation_pk_1": 42, "name": "H2G2", "value": "42"}
 }

=>> instance.to_dict("column1", "column2", (
                            # select relation fields recursively
    "relation1", ("name", "value", (
        "relation", ("a", "b", "c")
        ))
    ))
{"column1": "value",
 "column2": "value",
 "relation1": {"name": "H2G2", "value": "42", "relation": [
     {"a": 10, "b": 20, "c": 30},
     {"a": 11, "b": 22, "c": 33},
     ]}
 }
to_primary_keys()

return the primary keys and values for this instance

Return type:dict {primary key: value, ..}
class anyblok.bloks.anyblok_core.core.sqlbase.SqlBase

Bases: anyblok.bloks.anyblok_core.core.sqlbase.SqlMixin

this class is inherited by all the SQL model

Declaration type:
 Core
Registry name:Core.SqlBase
delete(byquery=False, flush=True)

Call the SqlAlchemy Query.delete method on the instance of the model:

self.delete()

is equal at:

flush the session
remove the instance of the session
and expire all the session, to reload the relation ship
expire(*fields)

Expire the attribute of the instance, theses attributes will be load at the next call of the instance

see: http://docs.sqlalchemy.org/en/latest/orm/session_api.html #sqlalchemy.orm.session.Session.expire

expire_relationship_mapped(mappers)

Expire the objects linked with this object, in function of the mappers definition

expunge()

Expunge the instance in the session

find_relationship(*fields)

Find column and relation ship link with the column or relationship passed in fields.

Parameters:*fields – lists of the attribute name
Return type:list of the attribute name of the attribute and relation ship

Cached classmethod with size=128

classmethod insert(**kwargs)

Insert in the table of the model:

MyModel.insert(...)

is equal at:

mymodel = MyModel(...)
MyModel.registry.session.add(mymodel)
MyModel.registry.flush()
classmethod multi_insert(*args)

Insert in the table one or more entry of the model:

MyModel.multi_insert([{...}, ...])

the flush will be done only one time at the end of the insert

Exception:SqlBaseException
refresh(*fields)

Expire and reload all the attribute of the instance

See: http://docs.sqlalchemy.org/en/latest/orm/session_api.html #sqlalchemy.orm.session.Session.refresh

update(**values)

Hight livel method to update the session for the instance

self.update(val1=.., val2= ...)

..warning:

the columns and values is passed as named arguments to show
a difference with Query.update meth
class anyblok.bloks.anyblok_core.core.sqlviewbase.SqlViewBase

Bases: anyblok.bloks.anyblok_core.core.sqlbase.SqlMixin

this class is inherited by all the SQL view

Declaration type:
 Core
Registry name:Core.SqlViewBase
class anyblok.bloks.anyblok_core.core.instrumentedlist.InstrumentedList

Bases: object

class of the return of the query.all() or the relationship list

Declaration type:
 Core
Registry name:Core.InstrumentedList
class anyblok.bloks.anyblok_core.core.query.Query(entities, session=None)

Bases: sqlalchemy.orm.query.Query

Overload the SqlAlchemy Query

Declaration type:
 Core
Registry name:Core.Query
all()

Return an instrumented list of the result of the query

with_perm(principals, permission)

Add authorization pre- and post-filtering to query.

This must be last in the construction chain of the query. Queries too complicated for the authorization system to infer safely will be refused.

Parameters:
  • principals – list, set or tuple of strings
  • permission (str) – the permission to filter for
Returns:

a query-like object, with only the returning methods, such as all(), count() etc. available.

class anyblok.bloks.anyblok_core.core.session.Session(*args, **kwargs)

Bases: sqlalchemy.orm.session.Session

Overload of the SqlAlchemy session

Declaration type:
 Core
Registry name:Core.Session

system

class anyblok.bloks.anyblok_core.system.System

Bases: object

Declaration type:
 Model
Registry name:Model.System
Tablename:system
Inherit model or mixin:
 
class anyblok.bloks.anyblok_core.system.blok.Blok

Bases: object

Declaration type:
 Model
Registry name:Model.System.Blok
Tablename:system_blok
Inherit model or mixin:
 
field name Description
logo
  • fget - get_logo
  • Field type - <class ‘anyblok.field.Function’>
  • Label - None
  • Context:
version
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
installed_version
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
state
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • selections:
  • toupdate - To update
  • uninstalled - Uninstalled
  • undefined - Undefined
  • touninstall - To uninstall
  • installed - Installed
  • toinstall - To install
  • Field type - <class ‘anyblok.column.Selection’>
  • DB column name - None
  • default - uninstalled
  • Context:
author
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
order
  • nullable - False
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Integer’>
  • DB column name - None
  • default - -1
  • Context:
long_description
  • fget - get_long_description
  • Field type - <class ‘anyblok.field.Function’>
  • Label - None
  • Context:
short_description
  • fget - get_short_description
  • Field type - <class ‘anyblok.field.Function’>
  • Label - None
  • Context:
name
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
classmethod apply_state(*bloks)

Call the rigth method is the blok state change

Warning

for the uninstallation the method called is uninstall_all

Parameters:bloks – list of the blok name load by the registry
classmethod check_if_the_conditional_are_installed(blok)

Return True if all the conditions to install the blok are satisfied

Parameters:blok – blok name
Return type:boolean
get_logo()

fget of logo return the path in the blok of the logo

Return type:absolute path or None if unexiste logo
get_long_description()

fget of the long_description Column.Selection

Return type:the readme file of the blok
get_short_description()

fget of the short_description Column.Selection

Return type:the docstring of the blok
install()

Method to install the blok

classmethod list_by_state(*states)

Return the blok name in function of the wanted states

Parameters:states – list of the state
Return type:list if state is a state, dict if the states is a list
load()

Method to load the blok when the registry is completly loaded

classmethod load_all()

Load all the installed bloks

uninstall()

Method to uninstall the blok

classmethod uninstall_all(*bloksname)

Search and call the uninstall method for all the uninstalled bloks

Warning

Use the desc order to uninstall because we can’t uninstall a dependancies before

Parameters:bloksname – list of the blok name to uninstall
classmethod update_list()

Populate the bloks list and update the state of existing bloks

upgrade()

Method to update the blok

class anyblok.bloks.anyblok_core.system.cache.Cache

Bases: object

Declaration type:
 Model
Registry name:Model.System.Cache
Tablename:system_cache
Inherit model or mixin:
 
field name Description
registry_name
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
method
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
id
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • primary_key - True
  • autoincrement - True
  • Field type - <class ‘anyblok.column.Integer’>
  • DB column name - None
  • is crypted - False
  • Context:
classmethod clear_invalidate_cache()

Invalidate the cache that needs to be invalidated

classmethod detect_invalidation()

Return True if a new invalidation is found in the table

Return type:Boolean
classmethod get_invalidation()

Return the pointer of the method to invalidate

classmethod get_last_id()

Return the last primary key id value

classmethod initialize_model()

Initialize the last_cache_id known

classmethod invalidate(registry_name, method)

Call the invalidation for a specific method cached on a model

Parameters:
  • registry_name – namespace of the model
  • method – name of the method on the model
Exception:

CacheException

class anyblok.bloks.anyblok_core.system.field.Field

Bases: object

Declaration type:
 Model
Registry name:Model.System.Field
Tablename:system_field
Inherit model or mixin:
 
field name Description
name
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
entity_type
  • nullable - True
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
code
  • nullable - True
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
ftype
  • nullable - True
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - Type
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
label
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
classmethod add_field(rname, label, model, table, ftype)

Insert a field definition

Parameters:
  • rname – name of the field
  • label – label of the field
  • model – namespace of the model
  • table – name of the table of the model
  • ftype – type of the AnyBlok Field
classmethod alter_field(field, label, ftype)

Update an existing field

Parameters:
  • field – instance of the Field model to update
  • label – label of the field
  • ftype – type of the AnyBlok Field
class anyblok.bloks.anyblok_core.system.column.Column

Bases: anyblok.model.Field

Declaration type:
 

Model

Registry name:

Model.System.Column

Tablename:

system_column

Inherit model or mixin:
 
  • <class ‘anyblok.model.Field’>
field name Description
nullable
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
unique
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
foreign_key
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
primary_key
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
autoincrement
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - Auto increment
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
name
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
remote_model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
classmethod add_field(cname, column, model, table, ftype)

Insert a column definition

Parameters:
  • cname – name of the column
  • column – instance of the column
  • model – namespace of the model
  • table – name of the table of the model
  • ftype – type of the AnyBlok Field
classmethod alter_field(column, meta_column, ftype)

Update an existing column

Parameters:
  • column – instance of the Column model to update
  • meta_column – instance of the SqlAlchemy column
  • ftype – type of the AnyBlok Field
classmethod get_cname(field, cname)

Return the real name of the column

Parameters:
  • field – the instance of the column
  • cname – Not use here
Return type:

string of the real column name

class anyblok.bloks.anyblok_core.system.relationship.RelationShip

Bases: anyblok.model.Field

Declaration type:
 

Model

Registry name:

Model.System.RelationShip

Tablename:

system_relationship

Inherit model or mixin:
 
  • <class ‘anyblok.model.Field’>
field name Description
nullable
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
local_column
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
remote_column
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
remote
  • default - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
name
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
remote_model
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
remote_name
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
classmethod add_field(rname, relation, model, table, ftype)

Insert a relationship definition

Parameters:
  • rname – name of the relationship
  • relation – instance of the relationship
  • model – namespace of the model
  • table – name of the table of the model
  • ftype – type of the AnyBlok Field
class anyblok.bloks.anyblok_core.system.model.Model

Bases: object

Models assembled

Declaration type:
 Model
Registry name:Model.System.Model
Tablename:system_model
Inherit model or mixin:
 
field name Description
is_sql_model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - Is a SQL model
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
description
  • fget - get_model_doc_string
  • Field type - <class ‘anyblok.field.Function’>
  • Label - None
  • Context:
table
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 256
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
name
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 256
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
get_model_doc_string()

Return the docstring of the model

classmethod update_list()

Insert and update the table of models

Exception:Exception
class anyblok.bloks.anyblok_core.system.parameter.Parameter

Bases: object

System Parameter

Declaration type:
 Model
Registry name:Model.System.Parameter
Tablename:system_parameter
Inherit model or mixin:
 
field name Description
multi
  • default - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
value
  • nullable - False
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Json’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
key
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
classmethod get(key)

Return the value of the key

Parameters:key – key to check
Return type:return value
Exception:ExceptionParameter
classmethod is_exist(key)

Check if one parameter exist for the key

Parameters:key – key to check
Return type:Boolean, True if exist
classmethod pop(key)

Remove return the value of the key

Parameters:key – key to check
Return type:return value
Exception:ExceptionParameter
classmethod set(key, value)

Insert or Update parameter for the key

Parameters:
  • key – key to save
  • value – value to save
class anyblok.bloks.anyblok_core.system.sequence.Sequence

Bases: object

System sequence

Declaration type:
 Model
Registry name:Model.System.Sequence
Tablename:system_sequence
Inherit model or mixin:
 
field name Description
seq_name
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
code
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
id
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • primary_key - True
  • autoincrement - True
  • Field type - <class ‘anyblok.column.Integer’>
  • DB column name - None
  • is crypted - False
  • Context:
number
  • nullable - False
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Integer’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
formater
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - {seq}
  • Context:
classmethod create_sequence(values)

create the sequence for one instance

classmethod initialize_model()

Create the sequence to determine name

classmethod insert(**kwargs)

Overwrite insert

classmethod multi_insert(*args)

Overwrite multi_insert

nextval()

return the next value of the sequence

classmethod nextvalBy(**kwargs)

Get the first sequence filtering by entries and return the next value

documentation

class anyblok.bloks.anyblok_core.documentation.DocElement

Bases: object

Declaration type:
 Mixin
Inherit model or mixin:
 
class anyblok.bloks.anyblok_core.documentation.Documentation

Bases: anyblok.mixin.DocElement

Declaration type:
 

Model

Registry name:

Model.Documentation

Tablename:

documentation

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.DocElement’>
class anyblok.bloks.anyblok_core.documentation.blok.Blok(blok)

Bases: object

Declaration type:
 Model
Registry name:Model.Documentation.Blok
Tablename:documentation_blok
Inherit model or mixin:
 
class anyblok.bloks.anyblok_core.documentation.model.Model(model)

Bases: anyblok.mixin.DocElement

Declaration type:
 

Model

Registry name:

Model.Documentation.Model

Tablename:

documentation_model

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.DocElement’>
class anyblok.bloks.anyblok_core.documentation.model.attribute.Attribute(attribute)

Bases: object

Declaration type:
 Model
Registry name:Model.Documentation.Model.Attribute
Tablename:documentation_model_attribute
Inherit model or mixin:
 
class anyblok.bloks.anyblok_core.documentation.model.field.Field(field)

Bases: object

Declaration type:
 Model
Registry name:Model.Documentation.Model.Field
Tablename:documentation_model_field
Inherit model or mixin:
 

Mixins

class anyblok.bloks.anyblok_core.mixins.ForbidUpdate

Bases: object

Declaration type:
 Mixin
Inherit model or mixin:
 
class anyblok.bloks.anyblok_core.mixins.ForbidDelete

Bases: object

Declaration type:
 Mixin
Inherit model or mixin:
 
class anyblok.bloks.anyblok_core.mixins.ReadOnly

Bases: anyblok.mixin.ForbidUpdate, anyblok.mixin.ForbidDelete

Declaration type:
 

Mixin

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.ForbidUpdate’>
  • <class ‘anyblok.mixin.ForbidDelete’>

exception

exception anyblok.bloks.anyblok_core.exceptions.CoreBaseException

Bases: TypeError

Exception for Core.Base

exception anyblok.bloks.anyblok_core.exceptions.SqlBaseException

Bases: Exception

Simple Exception for sql base

exception anyblok.bloks.anyblok_core.exceptions.QueryException

Bases: Exception

Simple Exception for query

exception anyblok.bloks.anyblok_core.exceptions.CacheException

Bases: Exception

Simple Exception for the cache Model

exception anyblok.bloks.anyblok_core.exceptions.ParameterException

Bases: Exception

Simple exception for System.Parameter

exception anyblok.bloks.anyblok_core.exceptions.ForbidUpdateException

Bases: Exception

Simple exception for Mixin.ForbiddenUpdate

exception anyblok.bloks.anyblok_core.exceptions.ForbidDeleteException

Bases: Exception

Simple exception for Mixin.ForbiddenDelete

Blok IO

class anyblok.bloks.io.AnyBlokIO(registry)

Bases: anyblok.blok.Blok

In / Out tool’s:

  • Formater: convert value 2 str or str 2 value in function of the field,
  • Importer: main model to define an import,
  • Exporter: main model to define an export,
author = 'Suzanne Jean-Sébastien'
conditional_by = []
conflicting_by = []
classmethod declare_io()
classmethod import_declaration_module()
logo = '../anyblok-logo_alpha_256.png'
name = 'anyblok-io'
optional_by = []
classmethod reload_declaration_module(reload)
required = ['anyblok-core']
required_by = ['anyblok-io-csv', 'anyblok-io-xml']
version = '0.16.1'

Note

Require the anyblok-io blok

Mapping

Model.IO.Mapping allows to link a Model instance by a Model namesapce and str key. this key is an external ID

Save an instance with a key:

Blok = self.registry.System.Blok
blok = Blok.query().filter(Blok.name == 'anyblok-core').first()
self.registry.IO.Mapping.set('External ID', blok)

Warning

By default if you save another instance with the same key and the same model, an IOMapingSetException will be raised. Il really you want this mapping you must call the set method with the named argument raiseifexist=False:

self.registry.IO.Mapping.set('External ID', blok, raiseifexist=False)

Get an entry in the mapping:

blok2 = self.registry.IO.Mapping.get('Model.System.Blok', 'External ID')
assert blok2 is blok

Formater

The goal of the formater is to get:

  • value from string
  • value from mapping key
  • string from value
  • mapping key from value

The value is the value of the field.

Warning

The relation ships are particulare cases. The value is the json of the primary keys. The Many2Many and the One2Many are the json of the list of the primary keys

Exporter

The Model.IO.Exporter export some entries in fonction of configuration. anyblok-io blok doesn’t give complete exporter, just the base Model to standardize all the possible export:

exporter = registry.IO.Exporter.insert(...)  # create a exporter
entries = ...  # entries are instance of model
fp = exporter.run(entries)
# fp is un handler on the opened file (StringIO)

Importer

The Model.IO.Importer import some entries in fonction of configuration. anyblok-io blok doesn’t give complete importer, just the base Model to standardize all the possible import:

importer = registry.IO.Importer.insert(...)  # create an importer
# the file to import are filled in the parameter
entries = importer.run()

API doc

exceptions

exception anyblok.bloks.io.exceptions.IOException

Bases: Exception

IO exception

exception anyblok.bloks.io.exceptions.IOMappingCheckException

Bases: anyblok.bloks.io.exceptions.IOException

IO Exception for setter

exception anyblok.bloks.io.exceptions.IOMappingSetException

Bases: anyblok.bloks.io.exceptions.IOException

IO Exception for setter

exception anyblok.bloks.io.exceptions.ImporterException

Bases: Exception

Simple Exception for importer

exception anyblok.bloks.io.exceptions.ExporterException

Bases: Exception

Simple Exception for exporter

exception anyblok.bloks.io.exceptions.FormaterException

Bases: Exception

Simple Exception for importer

core

class anyblok.bloks.io.core.Query

Bases: object

Declaration type:
 Core
Registry name:Core.Query
delete(*args, **kwargs)

Inherit the Query.delete methods.:

Model.query().delete(remove_mapping=True)
Parameters:remove_mapping – boolean, if check (default) the mapping is removed
class anyblok.bloks.io.core.SqlBase

Bases: object

Declaration type:
 Core
Registry name:Core.SqlBase
delete(*args, **kwargs)

Inherit the Model.delete methods.:

instance.delete(remove_mapping=True)
Parameters:remove_mapping – boolean, if check (default) the mapping is removed

mapping

class anyblok.bloks.io.mapping.Mapping

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Mapping
Tablename:io_mapping
Inherit model or mixin:
 
field name Description
primary_key
  • nullable - False
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.Json’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
blokname
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - Model.System.Blok => name
  • Label - Blok name
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
key
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - Model.System.Model => name
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
classmethod check_primary_keys(model, *pks)

check if the all the primary keys match with primary keys of the model

Parameters:
  • model – model to check
  • pks – list of the primary keys to check
Exception:

IOMappingCheckException

classmethod clean(bloknames=None, models=None)

Clean all mapping with removed object linked:

Mapping.clean(bloknames=['My blok'])

Warning

For filter only the no blokname:

Mapping.clean(bloknames=[None])
Params bloknames:
 filter by blok, keep the order to remove the mapping
Params models:filter by model, keep the order to remove the mapping
classmethod delete(model, key, mapping_only=True, byquery=False)

Delete the key for this model

Parameters:
  • model – model of the mapping
  • key – string of the key
Return type:

Boolean True if the mapping is removed

classmethod delete_for_blokname(blokname, models=None, byquery=False)

Clean all mapping with removed object linked:

Mapping.clean('My blok')

Warning

For filter only the no blokname:

Mapping.clean(None)
Params blokname:
 filter by blok
Params models:filter by model, keep the order to remove the mapping
filter_by_model_and_key(model, key)

SQLAlechemy hybrid method to filter by model and key

Parameters:
  • model – model of the mapping
  • key – external key of the mapping

Hybrid method

filter_by_model_and_keys(model, *keys)

SQLAlechemy hybrid method to filter by model and key

Parameters:
  • model – model of the mapping
  • key – external key of the mapping

Hybrid method

classmethod get(model, key)

return instance of the model with this external key

Parameters:
  • model – model of the mapping
  • key – string of the key
Return type:

instance of the model

classmethod get_mapping_primary_keys(model, key)

return primary key for a model and an external key

Parameters:
  • model – model of the mapping
  • key – string of the key
Return type:

dict primary key: value or None

classmethod multi_delete(model, *keys, **kwargs)

Delete all the keys for this model

Parameters:
  • model – model of the mapping
  • *keys – list of the key
Return type:

Boolean True if the mappings are removed

classmethod set(key, instance, raiseifexist=True, blokname=None)

Add or update a mmping with a model and a external key

Parameters:
  • model – model to check
  • key – string of the key
  • instance – instance of the model to save
  • raiseifexist – boolean (True by default), if True and the entry exist then an exception is raised
  • blokname – name of the blok where come from the mapping
Exception:

IOMappingSetException

classmethod set_primary_keys(model, key, pks, raiseifexist=True, blokname=None)

Add or update a mmping with a model and a external key

Parameters:
  • model – model to check
  • key – string of the key
  • pks – dict of the primary key to save
  • raiseifexist – boolean (True by default), if True and the entry exist then an exception is raised
  • blokname – name of the blok where come from the mapping
Exception:

IOMappingSetException

mixin

class anyblok.bloks.io.mixin.IOMixin

Bases: object

Declaration type:
 Mixin
Inherit model or mixin:
 
field name Description
id
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • primary_key - True
  • autoincrement - True
  • Field type - <class ‘anyblok.column.Integer’>
  • DB column name - None
  • is crypted - False
  • Context:
mode
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • selections - get_mode_choices
  • Field type - <class ‘anyblok.column.Selection’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
model
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - Model.System.Model => name
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:

importer

class anyblok.bloks.io.importer.Importer

Bases: anyblok.mixin.IOMixin

Declaration type:
 

Model

Registry name:

Model.IO.Importer

Tablename:

io_importer

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.IOMixin’>
field name Description
nb_grouped_lines
  • nullable - False
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Integer’>
  • DB column name - None
  • default - 50
  • Context:
file_to_import
  • nullable - False
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.LargeBinary’>
  • DB column name - None
  • default - <class
‘anyblok.column.NoDefaultValue’>
  • Context:
check_import
  • default - False
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None
offset
  • default - 0
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Integer’>
  • Context:
  • is crypted - False
  • DB column name - None
commit_at_each_grouped
  • default - True
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Boolean’>
  • Context:
  • is crypted - False
  • DB column name - None

exporter

class anyblok.bloks.io.exporter.Exporter

Bases: anyblok.mixin.IOMixin

Declaration type:
 

Model

Registry name:

Model.IO.Exporter

Tablename:

io_exporter

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.IOMixin’>

formater

class anyblok.bloks.io.formater.Formater

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Formater
Tablename:io_formater
Inherit model or mixin:
 
class anyblok.bloks.io.formater.Float

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Float

Tablename:

io_formater_float

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Decimal

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Decimal

Tablename:

io_formater_decimal

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Json

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Json

Tablename:

io_formater_json

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Interval

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Interval

Tablename:

io_formater_interval

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Integer

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Integer

Tablename:

io_formater_integer

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.SmallInteger

Bases: anyblok.model.Integer

Declaration type:
 

Model

Registry name:

Model.IO.Formater.SmallInteger

Tablename:

io_formater_smallinteger

Inherit model or mixin:
 
  • <class ‘anyblok.model.Integer’>
class anyblok.bloks.io.formater.BigInteger

Bases: anyblok.model.Integer

Declaration type:
 

Model

Registry name:

Model.IO.Formater.BigInteger

Tablename:

io_formater_biginteger

Inherit model or mixin:
 
  • <class ‘anyblok.model.Integer’>
class anyblok.bloks.io.formater.Boolean

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Boolean

Tablename:

io_formater_boolean

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Time

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Time

Tablename:

io_formater_time

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Date

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Date

Tablename:

io_formater_date

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.DateTime

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.DateTime

Tablename:

io_formater_datetime

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.Many2One

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Many2One

Tablename:

io_formater_many2one

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.One2One

Bases: anyblok.model.Many2One

Declaration type:
 

Model

Registry name:

Model.IO.Formater.One2One

Tablename:

io_formater_one2one

Inherit model or mixin:
 
  • <class ‘anyblok.model.Many2One’>
class anyblok.bloks.io.formater.Many2Many

Bases: anyblok.model.Formater

Declaration type:
 

Model

Registry name:

Model.IO.Formater.Many2Many

Tablename:

io_formater_many2many

Inherit model or mixin:
 
  • <class ‘anyblok.model.Formater’>
class anyblok.bloks.io.formater.One2Many

Bases: anyblok.model.Many2Many

Declaration type:
 

Model

Registry name:

Model.IO.Formater.One2Many

Tablename:

io_formater_one2many

Inherit model or mixin:
 
  • <class ‘anyblok.model.Many2Many’>

Blok IO CSV

class anyblok.bloks.io_csv.AnyBlokIOCSV(registry)

Bases: anyblok.blok.Blok

CSV Importer / Exporter behaviour

author = 'Suzanne Jean-Sébastien'
conditional_by = []
conflicting_by = []
classmethod import_declaration_module()
logo = '../anyblok-logo_alpha_256.png'
name = 'anyblok-io-csv'
optional_by = []
classmethod reload_declaration_module(reload)
required = ['anyblok-io']
required_by = []
version = '0.16.1'

Note

Require the anyblok-io-csv blok

Exporter

Add an exporter mode (CSV) in AnyBlok:

Exporter = registry.IO.Exporter.CSV

Define what export:

csv_delimiter = ','
csv_quotechar = '"'
model = ``Existing model name``
fields = [
    {'name': 'field name'},
    {'name': 'fieldname1.fieldname2. ... .fieldnamen}  #  fieldname1, fieldname 2 must be Many2One or have foreign keys
    {'name': 'field', model="external_id"}  # field must be Many2One or foreign_keys or primary keys
    ...
]

Create the Exporter:

exporter = Exporter.insert(csv_delimiter=csv_delimiter,
                           csv_quotechar=csv_quotechar,
                           model=model,
                           fields=fields)

Warning

You can also make insert with registry.IO.Exporter directly

Run the export:

fp = exporter.run(entries)  # entries are instance of the ``model``

Importer

Add an importer mode (CSV) in AnyBlok:

Importer = registry.IO.Importer.CSV

Define what import:

csv_delimiter = ','
csv_quotechar = '"'
model = ``Existing model name``
with open(..., 'rb') as fp:
    file_to_import = fp.read()

Create the Importer:

importer = Importer.insert(csv_delimiter=csv_delimiter,
                           csv_quotechar=csv_quotechar,
                           model=model,
                           file_to_import=file_to_import)

Warning

You can also make insert with registry.IO.Importer directly

Run the import:

res = importer.run()

The result is a dict with:

  • error_found: List the error, durring the import
  • created_entries: Entries created by the import
  • updated_entries: Entries updated by the import

List of the options for the import:

  • csv_on_error:
    • raise_now: Raise now
    • raise_at_the_end (default): Raise at the end
    • ignore: Ignore and continue
  • csv_if_exist:
    • pass: Pass to the next record
    • overwrite (default): Update the record
    • create: Create another record
    • raise: Raise an exception
  • csv_if_does_not_exist:
    • pass: Pass to the next record
    • create (default): Create another record
    • raise: Raise an exception

API doc

exceptions

exception anyblok.bloks.io_csv.exceptions.CSVImporterException

Bases: anyblok.bloks.io.exceptions.ImporterException

Simple exception for CSV importer

exception anyblok.bloks.io_csv.exceptions.CSVExporterException

Bases: anyblok.bloks.io.exceptions.ExporterException

Simple exception for CSV exporter

mixin

class anyblok.bloks.io_csv.mixin.IOCSVFieldMixin

Bases: object

Declaration type:
 Mixin
Inherit model or mixin:
 
field name Description
name
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • Context:
id
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • foreign_key - None
  • Label - None
  • primary_key - True
  • autoincrement - True
  • Field type - <class ‘anyblok.column.Integer’>
  • DB column name - None
  • is crypted - False
  • Context:
class anyblok.bloks.io_csv.mixin.IOCSVMixin

Bases: object

Declaration type:
 Mixin
Inherit model or mixin:
 
field name Description
csv_quotechar
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - “
  • Context:
csv_delimiter
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • default - ,
  • Context:

importer

class anyblok.bloks.io_csv.importer.Importer

Bases: anyblok.mixin.IOCSVMixin

Declaration type:
 

Model

Registry name:

Model.IO.Importer

Tablename:

io_importer

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.IOCSVMixin’>
field name Description
csv_if_exist
  • default - overwrite
  • size - 64
  • selections:
  • (‘pass’, ‘Pass to the next record’)
  • (‘overwrite’, ‘Update the record’)
  • (‘create’, ‘Create another record’)
  • (‘raise’, ‘Raise an exception’)
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Selection’>
  • Context:
  • is crypted - False
  • DB column name - None
csv_on_error
  • default - raise_at_the_end
  • size - 64
  • selections:
  • (‘raise_now’, ‘Raise now’)
  • (‘raise_at_the_end’, ‘Raise at the end’)
  • (‘ignore’, ‘Ignore and continue’)
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Selection’>
  • Context:
  • is crypted - False
  • DB column name - None
csv_if_does_not_exist
  • default - create
  • size - 64
  • selections:
  • (‘pass’, ‘Pass to the next record’)
  • (‘create’, ‘Create the record’)
  • (‘raise’, ‘Raise an exception’)
  • foreign_key - None
  • Label - None
  • Field type - <class
‘anyblok.column.Selection’>
  • Context:
  • is crypted - False
  • DB column name - None
class anyblok.bloks.io_csv.importer.CSV(importer, blokname=None)

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Importer.CSV
Tablename:io_importer_csv
Inherit model or mixin:
 

exporter

class anyblok.bloks.io_csv.exporter.Exporter

Bases: anyblok.mixin.IOCSVMixin

Declaration type:
 

Model

Registry name:

Model.IO.Exporter

Tablename:

io_exporter

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.IOCSVMixin’>
class anyblok.bloks.io_csv.exporter.Field

Bases: anyblok.mixin.IOCSVFieldMixin

Declaration type:
 

Model

Registry name:

Model.IO.Exporter.Field

Tablename:

io_exporter_field

Inherit model or mixin:
 
  • <class ‘anyblok.mixin.IOCSVFieldMixin’>
field name Description
exporter
  • model - Model.IO.Exporter
  • info:
  • nullable - False
  • remote_name - fields_to_export
  • remote_model - Model.IO.Exporter
  • _column_names - None
  • unique - False
  • backref - fields_to_export
  • Field type - <class ‘anyblok.relationship.Many2One’>
  • Label - None
  • _remote_columns - None
  • Context:
mode
  • nullable - False
  • size - 64
  • is crypted - False
  • foreign_key - None
  • Label - None
  • selections - get_selection
  • Field type - <class ‘anyblok.column.Selection’>
  • DB column name - None
  • default - any
  • Context:
mapping
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • Field type - <class ‘anyblok.column.String’>
  • Context:
  • is crypted - False
  • DB column name - None
class anyblok.bloks.io_csv.exporter.CSV(exporter)

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Exporter.CSV
Tablename:io_exporter_csv
Inherit model or mixin:
 

Blok IO XML

class anyblok.bloks.io_xml.AnyBlokIOXML(registry)

Bases: anyblok.blok.Blok

XML Importer / Exporter behaviour

Warning

Importer and Exporter are not implemented yet

author = 'Suzanne Jean-Sébastien'
conditional_by = []
conflicting_by = []
classmethod import_declaration_module()
logo = '../anyblok-logo_alpha_256.png'
name = 'anyblok-io-xml'
optional_by = []
classmethod reload_declaration_module(reload)
required = ['anyblok-io']
required_by = []
version = '0.16.1'

Note

Require the anyblok-io-xml blok

Exporter

TODO

Importer

Add an importer mode (XML) in AnyBlok:

Importer = registry.IO.Importer.XML

Define what import:

model = ``Existing model name``
with open(..., 'rb') as fp:
    file_to_import = fp.read()

Create the Importer:

importer = Importer.insert(model=model,
                           file_to_import=file_to_import)

Warning

You can also make insert with registry.IO.Importer directly

Run the import:

res = importer.run()

The result is a dict with:

  • error_found: List the error, durring the import
  • created_entries: Entries created by the import
  • updated_entries: Entries updated by the import

Root structure of the XML file:

<records on_error="...">
    ...
</records>

raise can have the value:

  • raise (dafault)
  • ignore

records node can have:

  • commit: commit the import, only if no error found
  • record: import one record

Add a record:

<records>
    <record>
        ...
        <field name="..." />
        ...
    </record>
</records>

Record attribute:

  • model: if not filled, then the importer will indicate the model
  • external_id: Mapping key
  • param: Mapping key only for the import (not save)
  • on_error:
    • raise
    • ignore (default)
  • if_exist:
    • overwrite (default)
    • create
    • pass: continue to the next record
    • continue: continue on the sub record without take this record
    • raise
  • id_does_not_exist:
    • create (default)
    • pass
    • raise

The field node represente a Field, a Column or RelationShip, the attribute are:

  • name (required): name of the field, column or relation ship

Case of the relation ship, they have some more attribute:

  • external_id:
  • param:
  • on_error:
    • raise
    • ignore (default)
  • if_exist:
    • overwrite (default)
    • create
    • pass: continue to the next record
    • continue: continue on the sub record without take this record
    • raise
  • id_does_not_exist:
    • create (default)
    • pass
    • raise

Many2One and One2One declaration is directly in the field node:

<records
    <record
        ...
        <field name="Many2One or One2One">
            ...
            <field name="..." />
            ...
        </field>
        ...
    </record>
</records>

One2Many and Many2Many declarations is also in the field but with a record node:

<records
    <record
        ...
        <field name="Many2Many or One2Many">
            ...
            <record>
                ...
                <field name="..." />
                ...
            </record>
            ...
        </field>
        ...
    </record>
</records>

In the case of polymorphisme you may use the attribute model on record:

<records
    <record
        ...
        <field name="Many2Many or One2Many">
            ...
            <record model="``polymophic model``">
                ...
                <field name="..." />
                ...
            </record>
            <record model="``another polymophic model``">
                ...
                <field name="..." />
                ...
            </record>
            ...
        </field>
        ...
    </record>
</records>

API doc

exceptions

exception anyblok.bloks.io_xml.exceptions.XMLImporterException

Bases: anyblok.bloks.io.exceptions.ImporterException

Simple exception for XML importer

exception anyblok.bloks.io_xml.exceptions.XMLExporterException

Bases: anyblok.bloks.io.exceptions.ExporterException

Simple exception for XML exporter

importer

class anyblok.bloks.io_xml.importer.Importer

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Importer
Tablename:io_importer
Inherit model or mixin:
 
class anyblok.bloks.io_xml.importer.XML(importer, blokname=None)

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Importer.XML
Tablename:io_importer_xml
Inherit model or mixin:
 

exporter

class anyblok.bloks.io_xml.exporter.Exporter

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Exporter
Tablename:io_exporter
Inherit model or mixin:
 
class anyblok.bloks.io_xml.exporter.XML(exporter)

Bases: object

Declaration type:
 Model
Registry name:Model.IO.Exporter.XML
Tablename:io_exporter_xml
Inherit model or mixin:
 

Blok Model Auth

class anyblok.bloks.model_authz.ModelBasedAuthorizationBlok(registry)

Bases: anyblok.blok.Blok

author = 'Suzanne Jean-Sébastien'
conditional_by = []
conflicting_by = []
classmethod import_declaration_module()
logo = '../anyblok-logo_alpha_256.png'
name = 'model_authz'
optional_by = []
classmethod reload_declaration_module(reload)
required_by = []
version = '0.16.1'

API doc

class anyblok.bloks.model_authz.models.ModelPermissionGrant

Bases: object

Default model for ModelBasedAuthorizationRule

Declaration type:
 Model
Registry name:Model.Authorization.ModelPermissionGrant
Tablename:authorization_modelpermissiongrant
Inherit model or mixin:
 
field name Description
principal
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
permission
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context:
model
  • default - <class ‘anyblok.column.NoDefaultValue’>
  • size - 64
  • foreign_key - None
  • Label - None
  • primary_key - True
  • Field type - <class ‘anyblok.column.String’>
  • DB column name - None
  • is crypted - False
  • Context: