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.8.2'
-
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
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 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 long_description Context
:fget
- get_long_descriptionLabel
- NoneField type
- <class ‘anyblok.field.Function’>
order DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- -1Context
:Field type
- <class ‘anyblok.column.Integer’>foreign_key
- Nonenullable
- False
short_description Context
:fget
- get_short_descriptionLabel
- NoneField type
- <class ‘anyblok.field.Function’>
version DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Noneprimary_key
- Truenullable
- False
state DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- uninstalledselections
:
uninstalled
- Uninstalledtoupdate
- To updateundefined
- Undefinedtoinstall
- To installinstalled
- Installedtouninstall
- To uninstall
Context
:size
- 64Field type
- <class ‘anyblok.column.Selection’>foreign_key
- Nonenullable
- False
installed_version DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
-
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 Registry name: Model.System.Cache Tablename: system_cache Inherit model or mixin: field name Description id DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.Integer’>
registry_name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
method DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
-
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 label DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
ftype DB column name
- NoneLabel
- Typeis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- True
code DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- True
model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
entity_type DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- True
-
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 autoincrement DB column name
- NoneLabel
- Auto incrementis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
unique DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
remote_model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
foreign_key DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
primary_key DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
nullable DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
-
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 model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
remote_name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
remote_model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
local_column DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
remote_column DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
remote DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- FalseContext
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
nullable DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
-
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 Registry name: Model.System.Cron Tablename: system_cron Inherit model or mixin:
-
class
anyblok.bloks.anyblok_core.system.cron.
Job
Bases:
object
Declaration type: Model Registry name: Model.System.Cron.Job Tablename: system_cron_job Inherit model or mixin: field name Description id DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.Integer’>
done_at DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.DateTime’>
error DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Text’>
params DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Json’>
is_a_class_method DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- TrueContext
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Model.System.Model => namenullable
- False
available_at DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.DateTime’>
method DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
-
class
anyblok.bloks.anyblok_core.system.cron.
Worker
(job) Bases:
threading.Thread
Declaration type: Model Registry name: Model.System.Cron.Worker Tablename: system_cron_worker Inherit model or mixin:
-
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 description Context
:fget
- get_model_doc_stringLabel
- NoneField type
- <class ‘anyblok.field.Function’>
table DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 256foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
is_sql_model DB column name
- NoneLabel
- Is a SQL modelis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 256foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
-
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 DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- FalseContext
:foreign_key
- NoneField type
- <class ‘anyblok.column.Boolean’>
value DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:Field type
- <class ‘anyblok.column.Json’>foreign_key
- Nonenullable
- False
key DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
-
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 id DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.Integer’>
formater DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- {seq}Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
seq_name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
code DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
number DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:Field type
- <class ‘anyblok.column.Integer’>foreign_key
- Nonenullable
- False
-
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:
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.8.2'
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 Registry name: Model.IO.Mapping Tablename: io_mapping Inherit model or mixin: field name Description model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Model.System.Model => nameprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
primary_key DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:Field type
- <class ‘anyblok.column.Json’>foreign_key
- Nonenullable
- False
key DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
-
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 id DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.Integer’>
mode DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>selections
- get_mode_choicesContext
:size
- 64Field type
- <class ‘anyblok.column.Selection’>foreign_key
- Nonenullable
- False
model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Model.System.Model => namenullable
- False
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 DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- 50Context
:Field type
- <class
- ‘anyblok.column.Integer’>
foreign_key
- Nonenullable
- False
check_import DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- FalseContext
:foreign_key
- NoneField type
- <class
‘anyblok.column.Boolean’>
offset DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- 0Context
:foreign_key
- NoneField type
- <class
‘anyblok.column.Integer’>
file_to_import DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class
- ‘anyblok.column.NoDefaultValue’>
Context
:Field type
- <class
- ‘anyblok.column.LargeBinary’>
foreign_key
- Nonenullable
- False
commit_at_each_grouped DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- TrueContext
:foreign_key
- NoneField type
- <class
‘anyblok.column.Boolean’>
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
-
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.8.2'
-
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 id DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.Integer’>
name DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
-
class
anyblok.bloks.io_csv.mixin.
IOCSVMixin
Bases:
object
Declaration type: Mixin Inherit model or mixin: field name Description csv_quotechar DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- “Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
csv_delimiter DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- ,Context
:size
- 64Field type
- <class ‘anyblok.column.String’>foreign_key
- Nonenullable
- False
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_does_not_exist DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- createselections
:- (‘pass’, ‘Pass to the next
- record’)
- (‘create’, ‘Create the record’)
- (‘raise’, ‘Raise an exception’)
Context
:size
- 64foreign_key
- NoneField type
- <class
‘anyblok.column.Selection’>
csv_on_error DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- raise_at_the_endselections
:- (‘raise_now’, ‘Raise now’)
- (‘raise_at_the_end’, ‘Raise at
- the end’)
- (‘ignore’, ‘Ignore and continue’)
Context
:size
- 64foreign_key
- NoneField type
- <class
‘anyblok.column.Selection’>
csv_if_exist DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- overwriteselections
:- (‘pass’, ‘Pass to the next
- record’)
- (‘overwrite’, ‘Update the
- record’)
- (‘create’, ‘Create another
- record’)
- (‘raise’, ‘Raise an exception’)
Context
:size
- 64foreign_key
- NoneField type
- <class
‘anyblok.column.Selection’>
-
class
anyblok.bloks.io_csv.importer.
CSV
(importer) 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 mapping DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- NoneField type
- <class ‘anyblok.column.String’>
exporter _remote_columns
- NoneLabel
- Noneinfo
:
remote_name
- fields_to_exportremote_model
- Model.IO.Exporternullable
- False
model
- Model.IO.ExporterContext
:unique
- False_column_names
- Nonebackref
- fields_to_exportField type
- <class ‘anyblok.relationship.Many2One’>
mode DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- anyselections
- get_selectionContext
:size
- 64Field type
- <class ‘anyblok.column.Selection’>foreign_key
- Nonenullable
- False
-
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
-
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.8.2'
-
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 Registry name: Model.IO.Importer Tablename: io_importer Inherit model or mixin:
-
class
anyblok.bloks.io_xml.importer.
XML
(importer) 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
-
conditional_by
= []
-
conflicting_by
= []
-
classmethod
import_declaration_module
()
-
name
= 'model_authz'
-
optional_by
= []
-
classmethod
reload_declaration_module
(reload)
-
required_by
= []
-
version
= '0.8.2'
-
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 DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
permission DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>
model DB column name
- NoneLabel
- Noneis crypted
- Falsedefault
- <class ‘anyblok.column.NoDefaultValue’>Context
:size
- 64foreign_key
- Noneprimary_key
- TrueField type
- <class ‘anyblok.column.String’>