dazzler.contrib package

Submodules

dazzler.contrib.postgresql module

class dazzler.contrib.postgresql.PostgresAuthenticator(app, pool=None)[source]

Bases: dazzler.system.auth.Authenticator

Authenticator for PostgreSQL.

Encryption of user passwords with scrypt.

Tables
  • users

  • role

  • user_roles

Configuration
[authentication]
authenticator = 'dazzler.contrib.postgresql:PostgresAuthenticator'

[postgres]
dsn = 'host=localhost port=5432 dbname=mydb'

[postgres.auth]
schema_name = 'public'
user_table_name = 'users'
__init__(app, pool=None)[source]
async authenticate(username, password)[source]

For login purpose.

Parameters
  • username (str) –

  • password (str) –

Returns

async get_user(username)[source]

Retrieve a user by it’s username.

Parameters

username (str) –

Returns

async register_user(username, password, email=None, fields=None)[source]

Register an user on form submit.

Return a string as an error, otherwise the operation is successful.

async setup(_)[source]
class dazzler.contrib.postgresql.PostgresConfig(config_format=ConfigFormat.TOML, root_name='config')[source]

Bases: precept._configs.Config

class Postgres(parent=None, parent_len=0)[source]

Bases: precept._configs.Nestable

class Auth(parent=None, parent_len=0)[source]

Bases: precept._configs.Nestable

class Encryption(parent=None, parent_len=0)[source]

Bases: precept._configs.Nestable

blocksize
cost_factor
dklen
maxmem
parallelism
default_user_roles
encryption: dazzler.contrib.postgresql.PostgresConfig.Postgres.Auth.Encryption
role_table_name
roles
schema_name
user_roles_table_name
user_table_name
class Middleware(parent=None, parent_len=0)[source]

Bases: precept._configs.Nestable

app_key
request_key
class Pool(parent=None, parent_len=0)[source]

Bases: precept._configs.Nestable

maxsize
minsize
class Session(parent=None, parent_len=0)[source]

Bases: precept._configs.Nestable

schema_name
table_name
auth: dazzler.contrib.postgresql.PostgresConfig.Postgres.Auth
dsn
middleware: dazzler.contrib.postgresql.PostgresConfig.Postgres.Middleware
pool: dazzler.contrib.postgresql.PostgresConfig.Postgres.Pool
session: dazzler.contrib.postgresql.PostgresConfig.Postgres.Session
postgres: dazzler.contrib.postgresql.PostgresConfig.Postgres
class dazzler.contrib.postgresql.PostgresMiddleware(app, config, pool=None)[source]

Bases: dazzler.system._middleware.Middleware

__init__(app, config, pool=None)[source]
class dazzler.contrib.postgresql.PostgresSessionBackend(app, config=None, pool=None)[source]

Bases: dazzler.system.session.SessionBackEnd

Session backend for PostgreSQL.

Tables
  • session

Configuration
[session]
backend = 'PostgreSQL'
__init__(app, config=None, pool=None)[source]
Parameters

app (dazzler.Dazzler) – Running dazzler app.

async delete(session_id, key)[source]

Delete a session key value.

Parameters
  • session_id (str) – Session to delete the key for.

  • key (str) – The key to delete.

Returns

async get(session_id, key)[source]

Get a key for the session id.

Parameters
  • session_id (str) – Session to fetch the data for.

  • key (str) – Key to get.

Returns

async on_new_session(session_id)[source]

Called when a new session is created. Override to handle.

async set(session_id, key, value)[source]

Set a key for the session id.

Parameters
  • session_id (str) – Session to set data with a key.

  • key (str) – Key to set

  • value (Any) – Value to keep.

Returns

class dazzler.contrib.postgresql.PostgresUserAdminPage(app, config=None, **kwargs)[source]

Bases: dazzler.pages.user_admin.UserAdminPage

Implementation of UserAdminPage for PostgreSQL.

Configuration
[authentication.admin]
enable = true
page_ref = 'dazzler.contrib.postgresql:PostgresUserAdminPage'
__init__(app, config=None, **kwargs)[source]
Parameters
  • name – Unique name for the page, usually give __name__.

  • layout – Root component or function returning a Component. In the case of a function, the request will be None on setup.

  • url – Url, default to /name.

  • bindings – Bindings of component aspects for this page.

  • routes – Additional routes to register with this page.

  • requirements – List of requirements to

  • title – Title of the page.

  • lang – lang attribute of the html tag.

  • header – Static header to include as first child on the page.

  • footer – Static footer to include as last child on the page.

  • favicon – Url to favicon for the page.

  • meta_tags – Meta tags of the page.

  • packages – Packages list to use on the page instead of the whole registry.

  • require_login – Page requires that user is logged in.

  • electron_window – Settings for the electron window like size.

  • authorizations – Rules for authorization.

async change_user_roles(username, roles)[source]
async create_role(role, description)[source]
async delete_role(role)[source]
async delete_user(username)[source]
async get_roles()[source]
async get_user_count(filters=None)[source]
async get_users(offset, limit, filters=None)[source]
async setup(_)[source]
async toggle_active_user(username, active)[source]
async update_role_description(role, description)[source]
async dazzler.contrib.postgresql.get_postgres_pool(config)[source]

dazzler.contrib.redis module

class dazzler.contrib.redis.RedisMiddleware(app, redis=None)[source]

Bases: dazzler.system._middleware.Middleware

Insert the aioredis pool instance into the aiohttp app and requests.

__init__(app, redis=None)[source]
class dazzler.contrib.redis.RedisSessionBackend(app, redis=None)[source]

Bases: dazzler.system.session.SessionBackEnd

Backed by aioredis.

Values are serialized to json first to keep the types.

Install with pip install dazzler[redis]

Seealso

https://aioredis.readthedocs.io/

__init__(app, redis=None)[source]
Parameters

app (dazzler.Dazzler) – Running dazzler app.

async delete(session_id, key)[source]

Delete a session key value.

Parameters
  • session_id (str) – Session to delete the key for.

  • key (str) – The key to delete.

Returns

async get(session_id, key)[source]

Get a key for the session id.

Parameters
  • session_id (str) – Session to fetch the data for.

  • key (str) – Key to get.

Returns

async set(session_id, key, value)[source]

Set a key for the session id.

Parameters
  • session_id (str) – Session to set data with a key.

  • key (str) – Key to set

  • value (Any) – Value to keep.

Returns

async dazzler.contrib.redis.get_redis_pool()[source]