Contents
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
-
autoinstall
= True
-
conditional_by
= []
-
conflicting_by
= []
-
classmethod
import_declaration_module
()
-
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.9.5'
-
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
- Core
- 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
-
to_primary_keys
() No SQL Model has not primary key
-
classmethod
-
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
-
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, ...}
-
classmethod
-
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
(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
-
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
-
classmethod
precommit_hook
(method, *args, **kwargs) Same in the registry a hook to call just before the commit
Warning
Only one instance 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
-
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 Tablename: system Registry name: Model.System Inherit model or mixin:
-
class
anyblok.bloks.anyblok_core.system.blok.
Blok
Bases:
object
Declaration type: Model Tablename: system_blok Registry name: Model.System.Blok Inherit model or mixin: field name Description name default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
long_description Label
- NoneField type
- <class ‘anyblok.field.Function’>fget
- get_long_descriptionContext
:
state default
- uninstallednullable
- FalseField type
- <class ‘anyblok.column.Selection’>is crypted
- Falseselections
:
touninstall
- To uninstallundefined
- Undefineduninstalled
- Uninstalledtoinstall
- To installinstalled
- Installedtoupdate
- To update
DB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
installed_version default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
version default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
order default
- -1nullable
- FalseField type
- <class ‘anyblok.column.Integer’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
short_description Label
- NoneField type
- <class ‘anyblok.field.Function’>fget
- get_short_descriptionContext
:
-
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_long_description
() fget of the
long_description
Column.SelectionReturn type: the readme file of the blok
-
get_short_description
() fget of the
short_description
Column.SelectionReturn 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 beforeParameters: 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 Tablename: system_cache Registry name: Model.System.Cache Inherit model or mixin: field name Description registry_name default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
method default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
id default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Integer’>Context
:DB column name
- Noneis crypted
- FalseLabel
- Noneprimary_key
- Trueforeign_key
- Noneautoincrement
- True
-
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 Tablename: system_field Registry name: Model.System.Field Inherit model or mixin: field name Description label default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
name default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
code default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- TrueField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
entity_type default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- TrueField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
ftype default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- TrueField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Typesize
- 64foreign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
-
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
Tablename: system_column
Registry name: Model.System.Column
Inherit model or mixin: - <class ‘anyblok.model.Field’>
field name Description unique default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
name default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
nullable default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
remote_model default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
primary_key default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
foreign_key default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
autoincrement default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Auto incrementforeign_key
- NoneContext
:
-
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
Tablename: system_relationship
Registry name: Model.System.RelationShip
Inherit model or mixin: - <class ‘anyblok.model.Field’>
field name Description remote_column default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
name default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
nullable default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
remote_model default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
remote_name default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
remote default
- FalseField type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
local_column default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
-
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.cron.
Cron
Bases:
object
Declaration type: Model Tablename: system_cron Registry name: Model.System.Cron Inherit model or mixin:
-
class
anyblok.bloks.anyblok_core.system.cron.
Job
Bases:
object
Declaration type: Model Tablename: system_cron_job Registry name: Model.System.Cron.Job Inherit model or mixin: field name Description method default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
id default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Integer’>Context
:DB column name
- Noneis crypted
- FalseLabel
- Noneprimary_key
- Trueforeign_key
- Noneautoincrement
- True
error default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Text’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
available_at default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.DateTime’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
done_at default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.DateTime’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
params default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Json’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- Model.System.Model => nameContext
:
is_a_class_method default
- TrueField type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
-
class
anyblok.bloks.anyblok_core.system.cron.
Worker
(job) Bases:
threading.Thread
Declaration type: Model Tablename: system_cron_worker Registry name: Model.System.Cron.Worker Inherit model or mixin:
-
class
anyblok.bloks.anyblok_core.system.model.
Model
Bases:
object
Models assembled
Declaration type: Model Tablename: system_model Registry name: Model.System.Model Inherit model or mixin: field name Description name default
- <class ‘anyblok.column.NoDefaultValue’>size
- 256Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
is_sql_model default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Is a SQL modelforeign_key
- NoneContext
:
table default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 256foreign_key
- NoneContext
:
description Label
- NoneField type
- <class ‘anyblok.field.Function’>fget
- get_model_doc_stringContext
:
-
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 Tablename: system_parameter Registry name: Model.System.Parameter Inherit model or mixin: field name Description multi default
- FalseField type
- <class ‘anyblok.column.Boolean’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
key default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
value default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.Json’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
-
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 Tablename: system_sequence Registry name: Model.System.Sequence Inherit model or mixin: field name Description code default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
seq_name default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
number default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.Integer’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
formater default
- {seq}nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
id default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Integer’>Context
:DB column name
- Noneis crypted
- FalseLabel
- Noneprimary_key
- Trueforeign_key
- Noneautoincrement
- True
-
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
Tablename: documentation
Registry name: Model.Documentation
Inherit model or mixin: - <class ‘anyblok.mixin.DocElement’>
-
class
anyblok.bloks.anyblok_core.documentation.blok.
Blok
(blok) Bases:
object
Declaration type: Model Tablename: documentation_blok Registry name: Model.Documentation.Blok Inherit model or mixin:
-
class
anyblok.bloks.anyblok_core.documentation.model.
Model
(model) Bases:
anyblok.mixin.DocElement
Declaration type: Model
Tablename: documentation_model
Registry name: Model.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 Tablename: documentation_model_attribute Registry name: Model.Documentation.Model.Attribute Inherit model or mixin:
-
class
anyblok.bloks.anyblok_core.documentation.model.field.
Field
(field) Bases:
object
Declaration type: Model Tablename: documentation_model_field Registry name: Model.Documentation.Model.Field Inherit model or mixin:
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.
CronWorkerException
Bases:
Exception
Simple exception for System.Parameter
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,
-
conditional_by
= []
-
conflicting_by
= []
-
classmethod
declare_io
()
-
classmethod
import_declaration_module
()
-
name
= 'anyblok-io'
-
optional_by
= []
-
classmethod
reload_declaration_module
(reload)
-
required
= ['anyblok-core']
-
required_by
= ['anyblok-io-csv', 'anyblok-io-xml']
-
version
= '0.9.5'
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
mapping
-
class
anyblok.bloks.io.mapping.
Mapping
Bases:
object
Declaration type: Model Tablename: io_mapping Registry name: Model.IO.Mapping Inherit model or mixin: field name Description primary_key default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.Json’>is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- Model.System.Model => nameContext
:
key default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
-
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
delete
(model, key, mapping_only=True) 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
-
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) 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
Exception: IOMappingSetException
-
classmethod
set_primary_keys
(model, key, pks, raiseifexist=True) 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
Exception: IOMappingSetException
mixin
-
class
anyblok.bloks.io.mixin.
IOMixin
Bases:
object
Declaration type: Mixin Inherit model or mixin: field name Description mode default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.Selection’>is crypted
- Falseselections
- get_mode_choicesDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- Model.System.Model => nameContext
:
id default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Integer’>Context
:DB column name
- Noneis crypted
- FalseLabel
- Noneprimary_key
- Trueforeign_key
- Noneautoincrement
- True
importer
-
class
anyblok.bloks.io.importer.
Importer
Bases:
anyblok.mixin.IOMixin
Declaration type: Model
Tablename: io_importer
Registry name: Model.IO.Importer
Inherit model or mixin: - <class ‘anyblok.mixin.IOMixin’>
field name Description check_import default
- FalseField type
- <class
- ‘anyblok.column.Boolean’>
is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
nb_grouped_lines default
- 50nullable
- FalseField type
- <class
- ‘anyblok.column.Integer’>
is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
file_to_import default
- <class
- ‘anyblok.column.NoDefaultValue’>
nullable
- FalseField type
- <class
- ‘anyblok.column.LargeBinary’>
is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
offset default
- 0Field type
- <class
- ‘anyblok.column.Integer’>
is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
commit_at_each_grouped default
- TrueField type
- <class
- ‘anyblok.column.Boolean’>
is crypted
- FalseDB column name
- NoneLabel
- Noneforeign_key
- NoneContext
:
exporter
-
class
anyblok.bloks.io.exporter.
Exporter
Bases:
anyblok.mixin.IOMixin
Declaration type: Model
Tablename: io_exporter
Registry name: Model.IO.Exporter
Inherit model or mixin: - <class ‘anyblok.mixin.IOMixin’>
formater
-
class
anyblok.bloks.io.formater.
Formater
Bases:
object
Declaration type: Model Tablename: io_formater Registry name: Model.IO.Formater Inherit model or mixin:
-
class
anyblok.bloks.io.formater.
Float
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_float
Registry name: Model.IO.Formater.Float
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Decimal
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_decimal
Registry name: Model.IO.Formater.Decimal
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Json
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_json
Registry name: Model.IO.Formater.Json
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Interval
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_interval
Registry name: Model.IO.Formater.Interval
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Integer
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_integer
Registry name: Model.IO.Formater.Integer
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
SmallInteger
Bases:
anyblok.model.Integer
Declaration type: Model
Tablename: io_formater_smallinteger
Registry name: Model.IO.Formater.SmallInteger
Inherit model or mixin: - <class ‘anyblok.model.Integer’>
-
class
anyblok.bloks.io.formater.
BigInteger
Bases:
anyblok.model.Integer
Declaration type: Model
Tablename: io_formater_biginteger
Registry name: Model.IO.Formater.BigInteger
Inherit model or mixin: - <class ‘anyblok.model.Integer’>
-
class
anyblok.bloks.io.formater.
Boolean
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_boolean
Registry name: Model.IO.Formater.Boolean
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Time
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_time
Registry name: Model.IO.Formater.Time
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Date
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_date
Registry name: Model.IO.Formater.Date
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
DateTime
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_datetime
Registry name: Model.IO.Formater.DateTime
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
Many2One
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_many2one
Registry name: Model.IO.Formater.Many2One
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
One2One
Bases:
anyblok.model.Many2One
Declaration type: Model
Tablename: io_formater_one2one
Registry name: Model.IO.Formater.One2One
Inherit model or mixin: - <class ‘anyblok.model.Many2One’>
-
class
anyblok.bloks.io.formater.
Many2Many
Bases:
anyblok.model.Formater
Declaration type: Model
Tablename: io_formater_many2many
Registry name: Model.IO.Formater.Many2Many
Inherit model or mixin: - <class ‘anyblok.model.Formater’>
-
class
anyblok.bloks.io.formater.
One2Many
Bases:
anyblok.model.Many2Many
Declaration type: Model
Tablename: io_formater_one2many
Registry name: Model.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
-
conditional_by
= []
-
conflicting_by
= []
-
classmethod
import_declaration_module
()
-
name
= 'anyblok-io-csv'
-
optional_by
= []
-
classmethod
reload_declaration_module
(reload)
-
required
= ['anyblok-io']
-
required_by
= []
-
version
= '0.9.5'
-
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 Exporter:
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 default
- <class ‘anyblok.column.NoDefaultValue’>nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
id default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.Integer’>Context
:DB column name
- Noneis crypted
- FalseLabel
- Noneprimary_key
- Trueforeign_key
- Noneautoincrement
- True
-
class
anyblok.bloks.io_csv.mixin.
IOCSVMixin
Bases:
object
Declaration type: Mixin Inherit model or mixin: field name Description csv_quotechar default
- “nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
csv_delimiter default
- ,nullable
- FalseField type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
importer
-
class
anyblok.bloks.io_csv.importer.
Importer
Bases:
anyblok.mixin.IOCSVMixin
Declaration type: Model
Tablename: io_importer
Registry name: Model.IO.Importer
Inherit model or mixin: - <class ‘anyblok.mixin.IOCSVMixin’>
field name Description csv_on_error default
- raise_at_the_endField type
- <class
- ‘anyblok.column.Selection’>
is crypted
- Falseselections
:- (‘raise_now’, ‘Raise now’)
- (‘raise_at_the_end’, ‘Raise at
- the end’)
- (‘ignore’, ‘Ignore and continue’)
DB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
csv_if_exist default
- overwriteField type
- <class
- ‘anyblok.column.Selection’>
is crypted
- Falseselections
:- (‘pass’, ‘Pass to the next
- record’)
- (‘overwrite’, ‘Update the
- record’)
- (‘create’, ‘Create another
- record’)
- (‘raise’, ‘Raise an exception’)
DB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
csv_if_does_not_exist default
- createField type
- <class
- ‘anyblok.column.Selection’>
is crypted
- Falseselections
:- (‘pass’, ‘Pass to the next
- record’)
- (‘create’, ‘Create the record’)
- (‘raise’, ‘Raise an exception’)
DB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
-
class
anyblok.bloks.io_csv.importer.
CSV
(importer) Bases:
object
Declaration type: Model Tablename: io_importer_csv Registry name: Model.IO.Importer.CSV Inherit model or mixin:
exporter
-
class
anyblok.bloks.io_csv.exporter.
Exporter
Bases:
anyblok.mixin.IOCSVMixin
Declaration type: Model
Tablename: io_exporter
Registry name: Model.IO.Exporter
Inherit model or mixin: - <class ‘anyblok.mixin.IOCSVMixin’>
-
class
anyblok.bloks.io_csv.exporter.
Field
Bases:
anyblok.mixin.IOCSVFieldMixin
Declaration type: Model
Tablename: io_exporter_field
Registry name: Model.IO.Exporter.Field
Inherit model or mixin: - <class ‘anyblok.mixin.IOCSVFieldMixin’>
field name Description mode default
- anynullable
- FalseField type
- <class ‘anyblok.column.Selection’>is crypted
- Falseselections
- get_selectionDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
mapping default
- <class ‘anyblok.column.NoDefaultValue’>Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Nonesize
- 64foreign_key
- NoneContext
:
exporter _column_names
- NoneLabel
- NoneContext
:_remote_columns
- Nonebackref
- fields_to_exportinfo
:
nullable
- Falseremote_model
- Model.IO.Exporterremote_name
- fields_to_export
unique
- Falsemodel
- Model.IO.ExporterField type
- <class ‘anyblok.relationship.Many2One’>
-
class
anyblok.bloks.io_csv.exporter.
CSV
(exporter) Bases:
object
Declaration type: Model Tablename: io_exporter_csv Registry name: Model.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
-
conditional_by
= []
-
conflicting_by
= []
-
classmethod
import_declaration_module
()
-
name
= 'anyblok-io-xml'
-
optional_by
= []
-
classmethod
reload_declaration_module
(reload)
-
required
= ['anyblok-io']
-
required_by
= []
-
version
= '0.9.5'
-
Note
Require the anyblok-io-xml blok
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 Exporter:
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>
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 Tablename: io_importer Registry name: Model.IO.Importer Inherit model or mixin:
-
class
anyblok.bloks.io_xml.importer.
XML
(importer) Bases:
object
Declaration type: Model Tablename: io_importer_xml Registry name: Model.IO.Importer.XML Inherit model or mixin:
exporter
-
class
anyblok.bloks.io_xml.exporter.
Exporter
Bases:
object
Declaration type: Model Tablename: io_exporter Registry name: Model.IO.Exporter Inherit model or mixin:
-
class
anyblok.bloks.io_xml.exporter.
XML
(exporter) Bases:
object
Declaration type: Model Tablename: io_exporter_xml Registry name: Model.IO.Exporter.XML Inherit model or mixin:
Blok Model Auth¶
-
class
anyblok.bloks.model_authz.
ModelBasedAuthorizationBlok
(registry) Bases:
anyblok.blok.Blok
-
conditional_by
= []
-
conflicting_by
= []
-
classmethod
import_declaration_module
()
-
name
= 'model_authz'
-
optional_by
= []
-
classmethod
reload_declaration_module
(reload)
-
required_by
= []
-
version
= '0.9.5'
-
API doc¶
-
class
anyblok.bloks.model_authz.models.
ModelPermissionGrant
Bases:
object
Default model for ModelBasedAuthorizationRule
Declaration type: Model Tablename: authorization_modelpermissiongrant Registry name: Model.Authorization.ModelPermissionGrant Inherit model or mixin: field name Description permission default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
principal default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
:
model default
- <class ‘anyblok.column.NoDefaultValue’>size
- 64Field type
- <class ‘anyblok.column.String’>is crypted
- FalseDB column name
- NoneLabel
- Noneprimary_key
- Trueforeign_key
- NoneContext
: