websauna.system.crud.urlmapper module¶
Map URL traversing ids to database ids and vice versa.
-
class
websauna.system.crud.urlmapper.
Base64UUIDMapper
(mapping_attribute=None, transform_to_path=None, transform_to_id=None, is_id=None)[source]¶ Bases:
websauna.system.crud.urlmapper.IdMapper
Map objects to URLs using their UUID property.
-
static
is_id
(val)[source]¶ Try guess if the value is valid base64 UUID slug or not.
Note that some view names can be valid UUID slugs, thus we might hit database in any case for the view lookup.
-
mapping_attribute
= 'uuid'¶ Override this if you want to change the column name containing uuid
-
static
-
exception
websauna.system.crud.urlmapper.
CannotMapException
[source]¶ Bases:
Exception
We could not extract id from an object.
-
class
websauna.system.crud.urlmapper.
IdMapper
(mapping_attribute=None, transform_to_path=None, transform_to_id=None, is_id=None)[source]¶ Bases:
websauna.system.crud.urlmapper.Mapper
Use object/column attribute id to map functions.
By default this is set to use integer ids, but you can override properties.
-
static
is_id
(value)¶ is_id(path) function checks whether the given URL path should be mapped to object and is a valid object id. Alternatively, if the path doesn’t look like an object id, it could be a view name. Because Pyramid traversing checks objects prior views, we need to let bad object ids to fall through through KeyError, so that view matching mechanism kicks in. By default we check for number integer id. Some object paths cannot be reliable disquished from view names, like UUID strings. In this case
is_id
is None, the lookup always first goes to the database. The database item is not with view name a KeyError is triggerred and thus Pyramid continues to view name resolution. This behavior is suboptimal and may change in the future versions
-
mapping_attribute
= 'id'¶ What is the object attibute name defining the its id
-
transform_to_id
¶ alias of
builtins.int
-
transform_to_path
¶ alias of
builtins.str
-
static