portal_web.models package¶
Submodules¶
portal_web.models.address module¶
- class portal_web.models.address.Address[source]¶
Bases:
Tdb
,MixinSearchByName
Model wrapper for Tryton model object ‘party.address’.
- classmethod create(vlist)[source]¶
Creates parties.
- Parameters:
vlist (list) –
List of dictionaries with attributes of a address. [
- {
‘name’: str (required), …
}, {
…
}
]
- Returns:
List of created parties. None: If no object was created.
- Return type:
list (obj[party.address])
- Raises:
KeyError – If required field is missing.
- classmethod search_all()[source]¶
Gets all parties.
- Returns:
List of parties. None: if no match is found.
- Return type:
list (obj[party.address])
portal_web.models.bank_account_number module¶
- class portal_web.models.bank_account_number.BankAccountNumber[source]¶
Bases:
Tdb
Model wrapper for Tryton model object ‘bank.account.number’.
- classmethod create(party, vlist)[source]¶
Creates bank account numbers.
Currently only the type IBAN is implemented.
2DO: Implement other types.
- Cascades:
Creates a bank with the bic as name if not existant.
- Parameters:
vlist (list) –
List of dictionaries with attributes of a web user. [
- {
‘type’: str (required), ‘bic’: str (required), ‘number’: str (required)
}, {
…
}
]
- Returns:
- List of created bank account
numbers.
None: If no object was created.
- Return type:
list (obj[bank.account.number])
- Raises:
KeyError – If required field is missing.
NotImplementedError – If type is not implemented.
portal_web.models.base module¶
- class portal_web.models.base.MixinSearchAll[source]¶
Bases:
object
Modelwrapper mixin for models that can return all records of a table
- class portal_web.models.base.MixinSearchByCode[source]¶
Bases:
object
Modelwrapper mixin for models that can be searched by its code
- class portal_web.models.base.MixinSearchById[source]¶
Bases:
object
Modelwrapper mixin for models that can be searched by id
- class portal_web.models.base.MixinSearchByName[source]¶
Bases:
object
Modelwrapper mixin for models that can be searched by its name field
- class portal_web.models.base.MixinSearchByOid[source]¶
Bases:
object
Modelwrapper mixin for models that can be searched by its oid field. The oid is exposed via the public api as an identifier for an object.
- class portal_web.models.base.MixinSearchByUuid[source]¶
Bases:
object
Modelwrapper mixin for models that can be searched by its UUID field
- class portal_web.models.base.MixinWebuser[source]¶
Bases:
object
Modelwrapper mixin for models that need to filter by webusers acl restrictions, for example if the webuser is allowed to view or edit items.
- classmethod current_editable(request)[source]¶
Searches objects, which the current web_user is allowed to edit.
- Parameters:
request (pyramid.request.Request) – Current request.
- Returns:
editable objects of web_user None: if no match is found
- Return type:
list
- classmethod current_viewable(request)[source]¶
Searches objects, which the current web_user is allowed to view.
- Parameters:
request (pyramid.request.Request) – Current request.
- Returns:
viewable objects of web_user None: if no match is found
- Return type:
list
- classmethod search_editable_by_web_user(web_user_id, active=True)[source]¶
Searches objects, which the web_user is allowed to edit. The view permission is expected to have the form ‘edit_<modelname>’.
- Parameters:
web_user_id (int) – web.user.id
- Returns:
viewable objects of web_user, empty if none were found
- Return type:
list
- classmethod search_viewable_by_web_user(web_user_id, active=True)[source]¶
Searches objects, which the web_user is allowed to view. The view permission is expected to have the form ‘view_<modelname>’.
- Parameters:
web_user_id (int) – web.user.id
- Returns:
viewable objects of web_user, empty if none were found
- Return type:
list
- class portal_web.models.base.Tdb[source]¶
Bases:
object
Base Class for model wrappers and communication handling using trytond.
Includes functions to
initialize the tryton database
wrap database communication with transaction handling
Includes helper functions for getting the pool, context and models.
- Classattributes:
_db (str): Name of database. _configfile (str): Tryton config file. _retry (int): Number of retries in transactions. _user (int): Default id of tryton backend user for transactions. _company (int): Default company id. __name__ (str): Name of the tryton model to be initialized.
- classmethod create(vlist)[source]¶
Generic creation method to use in model wrappers.
- Parameters:
vlist (list) –
- list of dicts with attributes to create records.
For example:
- [
- {
‘code’: …, ‘uuid’: …, ‘name’: …
}, {
…
}
]
- Raises:
KeyError – if required field is missing
- Returns:
created devices None: if no object was created
- Return type:
list
- classmethod get(model=None)[source]¶
Gets a Tryton model object.
If no Tryton model descriptor is passed, the class variable __name__ is assumed to be set to it’s default Tryton model descriptor, which then will be used to get the Tryton model.
- Parameters:
model (str) – Tryton model descriptor or None.
- Returns:
Tryton model.
- Return type:
obj
- classmethod init()[source]¶
Initializes a Tryton database.
Configuration is done by assigning the desired values to the following class attributes prior to the call:
_db
_configfile
_company
_user
Updates the tryton config and reads out the configured number of retries before initialization.
Note
This function is expected to be called only once.
Examples
>>> Tdb._db = 'db' >>> Tdb._configfile = '/path/to/configfile' >>> Tdb._company = 1 >>> Tdb._user = 'user' >>> Tdb.init()
- static transaction(readonly=None, user=None, context=None)[source]¶
Decorater function to wrap database communication with transactions.
The wrapping function handles:
start and stop of transactions
caching in case of multithreading environments
commit and rollback of cursors on error
retries in case of an operational error of Tryton
chaining of multiple decorated functions within one transaction
2DO: Chaining multiple calls to the database could result in different cursors. This works in principle (commented out) but still has a problem with the combination of different rw/ro calls.
- Parameters:
readonly (bool) – Type of transaction. If None and kwargs contains a request object, then the transaction will be readonly except for PUT, POST, DELETE and PATCH request methods. If None and kwargs contains no request object, then the transaction will be readonly.
user (int) – Tryton backend user id for transaction. If None, then the default user will be used for transaction
context (dict) – Context for transaction. If None, then the context of transaction will be empty.
- Raises:
DatabaseOperationalError – if Tryton or the database has a problem.
Note
This work is based on the flask_tryton package by Cedric Krier <ced@b2ck.com> licensed under GPLv3 (see flask_tryton.py)
- wraps = 0¶
portal_web.models.checksum module¶
- class portal_web.models.checksum.Checksum[source]¶
Bases:
Tdb
,MixinSearchByCode
Model wrapper for Tryton model object ‘checksum’.
- classmethod create(vlist)[source]¶
Creates a checksum.
- Parameters:
vlist (list) –
List of dictionaries with attributes of a checksum. [
- {
‘origin’: obj content||harddisk (required), ‘code’: str (required) ‘timestamp’: obj (required), ‘algorithm’: str (required), ‘begin’: int, ‘end’: int
}, {
…
}
]
- Returns:
- List of created bank account
numbers.
None: If no object was created.
- Return type:
list (obj[checksum])
- Raises:
KeyError – If required field is missing.
NotImplementedError – If type is not implemented.
- classmethod search_collision(code, algorithm=None, begin=None, end=None)[source]¶
Searches for a checksum collision.
- Parameters:
begin (int) – First byte for checksum.
end (int) – Last byte for checksum.
algorithm (str) – Algorithm for checksum.
code (str) – Code of checksum.
- Returns:
List of collided checksums. list ([]): If no match is found.
- Return type:
list (obj[Checksum])
portal_web.models.company module¶
- class portal_web.models.company.Company[source]¶
Bases:
Tdb
,MixinSearchById
Model wrapper for Tryton model object ‘company.company’.
portal_web.models.country module¶
- class portal_web.models.country.Country[source]¶
Bases:
Tdb
,MixinSearchById
,MixinSearchByCode
,MixinSearchByName
,MixinSearchAll
Model wrapper for Tryton model object ‘country.country’.
- class portal_web.models.country.Subdivision[source]¶
Bases:
Tdb
,MixinSearchById
,MixinSearchByCode
,MixinSearchByName
,MixinSearchAll
Model wrapper for Tryton model object ‘country.subdivision’.
portal_web.models.party module¶
- class portal_web.models.party.Party[source]¶
Bases:
Tdb
,MixinSearchByName
Model wrapper for Tryton model object ‘party.party’.
- classmethod create(vlist)[source]¶
Creates parties.
- Parameters:
vlist (list) –
List of dictionaries with attributes of a party. [
- {
‘name’: str (required), …
}, {
…
}
]
- Returns:
List of created parties. None: If no object was created.
- Return type:
list (obj[party.party])
- Raises:
KeyError – If required field is missing.
- classmethod search_all()[source]¶
Gets all parties.
- Returns:
List of parties. None: if no match is found.
- Return type:
list (obj[party.party])
portal_web.models.web_user module¶
- class portal_web.models.web_user.WebUser[source]¶
Bases:
Tdb
Model wrapper for Tryton model object ‘web.user’.
- classmethod authenticate(email, password)[source]¶
Checks authentication of a web user with email and password.
- Parameters:
email (str) – Email of the web user.
password (str) – Password of the web user.
- Returns:
Web user. None: If authentication check failed.
- Return type:
obj (web.user)
- classmethod create(vlist)[source]¶
Creates web users.
- Parameters:
vlist (list) –
List of dictionaries with attributes of a web user. [
- {
‘email’: str (required), ‘password’: str (required)
}, {
…
}
]
- Returns:
List of created web users. None: If no object was created.
- Return type:
list (obj[web.user])
- Raises:
KeyError – If required field is missing.
- classmethod current_party(request)[source]¶
Gets the party of the currently logged in web user.
- Parameters:
request (pyramid.request.Request) – Current request.
- Returns:
Party of the web user. None: If no web user is logged in
- Return type:
obj (web.user.party)
- classmethod current_roles(request)[source]¶
Gets the roles of the currently logged in web user.
- Parameters:
request (pyramid.request.Request) – Current request.
- Returns:
List of roles of the current web user. None: If no web user is logged in.
- Return type:
list
- classmethod current_user(request)[source]¶
Gets the party of the currently logged in web user.
- Parameters:
request (pyramid.request.Request) – Current request.
- Returns:
Party of the web user. None: If no web user is logged in
- Return type:
obj (web.user.party)
- classmethod current_web_user(request)[source]¶
Gets the currently logged in web user.
- Parameters:
request (pyramid.request.Request) – Current request.
- Returns:
Web user. None: If no web user is logged in.
- Return type:
obj (web.user)
- classmethod get_opt_in_state_by_email(email)[source]¶
Searches the opt in state for the web user by email.
- Parameters:
email (string) – Email of the web user.
- Returns:
Opt in state. None: If no match is found.
- Return type:
str
- classmethod get_opt_in_uuid_by_id(uid)[source]¶
Searches an opt in uuid by web user id.
- Parameters:
uid (string) – Id of the web user.
- Returns:
Opt in uuid. None: If no match is found.
- Return type:
str
- classmethod groupfinder(email, request)[source]¶
Gets the roles of a web user for effective principals.
- Parameters:
email (str) – Email of the web user.
request (pyramid.request.Request) – Current request.
- Returns:
List of roles of the current web user. None: If no web user is logged in.
- Return type:
list
- classmethod roles(web_user)[source]¶
Gets the roles of a web user.
- Parameters:
web_user (obj[web.user]) – Web user.
- Returns:
List of roles of the web user.
- Return type:
list
- classmethod search_all()[source]¶
Gets all web users.
- Returns:
List of web users. None: if no match is found.
- Return type:
list (obj[web.user])
- classmethod search_by_email(email)[source]¶
Searches a web user by email.
- Parameters:
email (str) – Email of the web user.
- Returns:
Web user. None: If no match is found.
- Return type:
obj (web.user)
- classmethod search_by_id(uid)[source]¶
Searches a web user by id.
- Parameters:
uid (string) – Id of the web user.
- Returns:
Web user. None: If no match is found.
- Return type:
obj (web.user)
portal_web.models.web_user_role module¶
- class portal_web.models.web_user_role.WebUserRole[source]¶
Bases:
Tdb
,MixinSearchByCode
Model wrapper for Tryton model object ‘web.user.role’.