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])

classmethod search_by_id(uid)[source]

Searches a address by id.

Parameters:

uid (string) – Id of the address.

Returns:

Address. None: If no match is found.

Return type:

obj (party.address)

classmethod search_by_party(id_party)[source]

Searches an address by it’s owning party

Parameters:

id_party (string) – Id of the adresses party

Returns:

Address None: If no match is found

Return type:

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.

classmethod search_by_number(number)[source]

Searches a bank account number by number.

Parameters:

number (str) – Number of bank account number.

Returns:

Bank account number. None: If no match is found.

Return type:

obj

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

classmethod search_all()[source]

Fetches all records

Returns:

list of records None: if table is empty

class portal_web.models.base.MixinSearchByCode[source]

Bases: object

Modelwrapper mixin for models that can be searched by its code

classmethod search_by_code(code)[source]

Searches an object by its code.

Parameters:

code (str) – Code of the object.

Returns:

Checksum. None: If no match is found.

Return type:

obj

class portal_web.models.base.MixinSearchById[source]

Bases: object

Modelwrapper mixin for models that can be searched by id

classmethod search_by_id(id)[source]

Searches a model by id

Parameters:

id (int) – model.id

Note

This is a search for the internal database id.

Returns:

model None: if no match is found

Return type:

obj

class portal_web.models.base.MixinSearchByName[source]

Bases: object

Modelwrapper mixin for models that can be searched by its name field

classmethod search_by_name(name)[source]

Searches an object by name

Parameters:

name (string) – object.name

Returns:

db object None: if no match is found

Return type:

obj

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.

classmethod search_by_oid(oid)[source]

Searches an object by oid

Parameters:

oid (string) – object.oid

Returns:

db object None: if no match is found

Return type:

obj

classmethod search_by_oids(oids)[source]

Searches objects by oids

Parameters:

oids (list) – [object.oid, …]

Returns:

[db object, …]

Return type:

list

class portal_web.models.base.MixinSearchByUuid[source]

Bases: object

Modelwrapper mixin for models that can be searched by its UUID field

classmethod search_by_uuid(uuid)[source]

Searches an object by uuid

Parameters:

uuid (string) – object.uuid

Returns:

db object None: if no match is found

Return type:

obj

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 context()[source]

Gets the Transaction context.

Returns:

Context.

Return type:

dict

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 escape(string, wrap=False)[source]
classmethod escape_domain(domain, wrap=True)[source]
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 is_open()[source]
classmethod pool()[source]

Gets the Tryton pool object.

Returns:

Pool.

Return type:

obj

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])

classmethod search_by_email(email)[source]

Searches a party by email.

Parameters:

email (str) – Email of the party.

Returns:

Party. None: If no match is found.

Return type:

obj (party.party)

classmethod search_by_id(uid)[source]

Searches a party by id.

Parameters:

uid (string) – Id of the party.

Returns:

Party. None: If no match is found.

Return type:

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)

classmethod search_by_opt_in_uuid(opt_in_uuid)[source]

Searches a web user by opt in uuid.

Parameters:

opt_in_uuid (string) – Opt in uuid of the web user.

Returns:

Web user. None: If no match is found.

Return type:

obj (web.user)

classmethod update_opt_in_state(opt_in_uuid, state)[source]

Sets the opt in state for the web user.

Parameters:
  • opt_in_uuid (string) – Opt in uuid of the web user.

  • state (string) – New opt in state.

Returns:

If update was successful. False: Otherwise.

Return type:

True

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’.

classmethod search_all()[source]

Gets all web user roles.

Returns:

List of web user roles. None: if no match is found.

Return type:

list (obj[web.user.role])

Module contents