API Documentation

Anuket is an opiniated Python web framework based on Pyramid.

anuket.models – SQLAlchemy models

Models for the Anuket application.

anuket.models.auth – Auth model

SQLAlchemy model definition for authentification.

class anuket.models.auth.AuthGroup(**kwargs)[source]

AuthGroup table and model definition.

Define the database auth_group table for the users groups and a method to query the table. This table is used used for ACLs principals.

classmethod get_by_id(group_id)[source]

Query the auth_group table by group_id.

Parameters:group_id (integer) – the group id
Returns:a sqlalchemy.orm.query.Query object
class anuket.models.auth.AuthUser(**kwargs)[source]

AuthUser table and model definition.

Define the database auth_user table for the authenticated users and the methods for querring the table or check the validity of the password.

classmethod get_by_id(user_id=None)[source]

Query the auth_user table by user_id.

Parameters:user_id – the user id
Returns:a sqlalchemy.orm.query.Query object
classmethod get_by_username(username=None)[source]

Query the auth_user table by username.

Parameters:username (unicode) – the user username
Returns:a sqlalchemy.orm.query.Query object
classmethod get_by_email(email=None)[source]

Query the auth_user table by email.

Parameters:username (unicode) – the user email
Returns:a sqlalchemy.orm.query.Query object
classmethod check_password(username, password)[source]

Check the user password.

Check if the submited password for username is the same than the encrypted one recorded in the database. Return None if the username did not exist.

Parameters:
  • username (unicode) – the user username
  • username – the submited password
Returns:

True if the password is correct. false if incorect

Return type:

boolean

anuket.models.migration – Migration model

SQLAlchemy model definition for database migration with Alembic.

class anuket.models.migration.Migration[source]

Migration table and model definition.

Reflect the default version table used by Alembic. This table is used for tracking database migrations.

anuket.models.rootfactory – RootFactory model

Pyramid root factory model.

class anuket.models.rootfactory.RootFactory(request)[source]

Add ACLs to the default route factory.

anuket.views – Pyramid views

Views callables for the Anuket application.

anuket.views.root – Root views

Main views for the application.

anuket.views.root.root_view(request)[source]

Render the root pages.

Render the home page, the login page and 404 not found page.

Parameters:request – a pyramid.request object
anuket.views.root.forbiden_view(request)[source]

Redirect the 403 forbiden view.

Authenticated user with not enought permission are redirected to the home page. Non-autenthicaded users are redirected to the login page. A corresponding flash message is also added to the error message queue.

Parameters:request – a pyramid.request object
anuket.views.root.login_view(request)[source]

Render the login form.

Display an empty login form or check the submited credentials with the ones from the database. Add a success flash message, an userid in the cookies and redirect to the home page if the credentials are goods. Add an error flash message and display again the login form if the credentials are wrong.

Parameters:request – a pyramid.request object
anuket.views.root.logout_view(request)[source]

Logout authenticated user.

Clear the credentials of the connected user if any. Then, redirect to the home page and add a info flash message.

Parameters:request – a pyramid.request object

anuket.views.tools – Tools views

Admin tools views for the application.

anuket.views.tools.tools_index_view(request)[source]

Render the tools home page.

Parameters:request – a pyramid.request object

anuket.views.user – User views

Admin tools for user management.

anuket.views.user.user_add_view(request)[source]

Render the add user form page.

Display an empty user form or validate the user submited form. If the form is validated then add the user datas to the database and a success flash message. If the form is not valid, then display again the form with validation errors. Return also a list of groups to use in the group select form.

Parameters:request – a pyramid.request object
anuket.views.user.user_delete_view(request)[source]

Delete an user.

Seek the database for the user datas based on user_id used in the route. If the user did not exist then add an error flash message and redirect to the user list. If the user exist then delete the user in the database, add a warning flash message and then redirect to the user list.

Parameters:request – a pyramid.request object
anuket.views.user.user_edit_view(request)[source]

Render the edit user form page.

Seek the database for the user datas based on user_id used in the route. If the user did not exist then add an error flash message and redirect to the user list. If the user exist then render the user form filled with the user datas. If the form is validated then change the user datas to the database and add success flash message. If the form is not valid, then display again the form with validation errors. Return also a list of groups to use in the group select form.

Parameters:request – a pyramid.request object
anuket.views.user.user_list_view(request)[source]

Render the user list page.

Return a paged user list from the database. The paged list can be ordered by username, first name or last name. Add an error flash message if the list is empty. Return also basic users statistics.

Parameters:request – a pyramid.request object
anuket.views.user.user_show_view(request)[source]

Render the show user datas page.

Seek the database for the user datas based on user_id used in the route. If the user did not exist then add an error flash message and redirect to the user list. If the user exist then return his datas.

Parameters:request – a pyramid.request object
anuket.views.user.password_edit_view(request)[source]

Render the change password form page.

Seek the database for the user datas based on user_id used in the route. If the user did not exist then add an error flash message and redirect to the user list. If the user exist then render an empty password form. If the form is validated then change the user password in the database and add success flash message. If the form is not valid, then display again the form with validation errors.

Parameters:request – a pyramid.request object

anuket.scripts – Console scripts

Command line scripts for the Anuket application.

anuket.scripts.initializedb – Database initialization

Script to initialize the Anuket database.

class anuket.scripts.initializedb.InitializeDBCommand(argv)[source]

Create the database using the configuration from the .ini file passed as a positional argument.

run()[source]

Run the initialize_db method or display the parser help message if the config_uri argument is missing.

Returns:initialize_db method or 2 (missing argument error)
initialize_db()[source]

Initialize the database schema and insert default values.

Returns:0 (OK) or 1 (abnormal termination error)

anuket.scripts.backupdb – Database backup

Script to backup the Anuket database.

class anuket.scripts.backupdb.BackupDBCommand(argv)[source]

Dump the database for backup purpose.

Supported database: SQLite.

run()[source]

Run the backup_db method or display the parser help message if the config_uri argument is missing.

Returns:backup_db method or 2 (missing argument error)
backup_db()[source]

Dump the database and then compress and save the file.

Returns:0 (OK) or 1 (abnormal termination error)

anuket.scripts.upgradedb – Database upgrade

Script for upgrading the Anuket database with Alembic.

class anuket.scripts.upgradedb.UpgradeDBCommand(argv)[source]

Upgrade the database using the configuration from the .ini file passed as a positional argument.

run()[source]

Run the upgrade_db method or display the parser help message if the config_uri argument is missing.

Returns:upgrade_db method or 2 (missing argument error)
upgrade_db()[source]

Upgrade the database to the head revision with Alembic.

Returns:0 (OK) or 1 (abnormal termination error)

anuket.lib – Internal libraries

Internal library for the Anuket application.

anuket.lib.alembic_utils – Alembic utilities

Alembic utilities to use with database scripts.

anuket.lib.alembic_utils.get_alembic_settings(config_uri)[source]

Get alembic settings from the config file.

Parameters:config_uri – an .ini config file
Returns:an alembic.config.Config object
anuket.lib.alembic_utils.get_alembic_revision(config_uri)[source]

Check the existence of an alembic revision in the database. If the database is versioned, then return the current revision.

Parameters:config_uri – an .ini file
Returns:the alembic revision value or None

anuket.lib.i18n – Translation library

Define a message factory and a locale negotiator.

anuket.lib.i18n.locale_negotiator(request)[source]

Return a locale name by looking at the Accept-Language HTTP header.

Parameters:request – a pyramid.request object
Returns:the language code

anuket.lib.validators – FormEncode Validators

FormEncode validators.

class anuket.lib.validators.FirstNameString(*args, **kw)[source]
Expand the validators.String class tu return a capitalised value
with excessives inner whitespaces removed.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooLong:
Enter a value not more than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more
class anuket.lib.validators.LastNameString(*args, **kw)[source]
Expand the validators.String class tu return a value with excessives
inner whitespaces removed.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
tooLong:
Enter a value not more than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more
class anuket.lib.validators.UsernamePlainText(*args, **kw)[source]
Expand the validators.PlainText class tu return a lowercased value
with all whitespaces removed.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalid:
Enter only letters, numbers, or _ (underscore)
noneType:
The input must be a string (not None)
class anuket.lib.validators.UniqueAuthUsername(*args, **kw)[source]

Unique username validator.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
not_unique_username:
This username is already used
validate_python(values, state)[source]

Check for the uniqueness of username.

class anuket.lib.validators.UniqueAuthEmail(*args, **kw)[source]

Unique email validator.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
not_unique_email:
This email is already used
validate_python(values, state)[source]

Check for the uniqueness of email.

class anuket.lib.validators.SecurePassword(*args, **kw)[source]

Secure password validator.

Messages

badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
noneType:
The input must be a string (not None)
not_secure:
This password is not secure
tooLong:
Enter a value not more than %(max)i characters long
tooShort:
Enter a value %(min)i characters long or more
validate_python(value, state)[source]

Use cracklib to check the strenght of passwords.

Others

anuket.security – Security

Authentification related utilities.

anuket.security.groupfinder(user_id, request)[source]

Groupfinder callback for authentification policy.

Return the groupname (principal) of an authenticated user form the database. Return None if the user do not exist.

Parameters:
  • user_id (integer) – the id of the authenticated user
  • request – a pyramid.request object
Returns:

the user groupname or None

anuket.subscribers – Subscribers

Pyramid event subscribers.

anuket.subscribers.add_renderer_globals(event)[source]

Renderers globals event subscriber.

Add globals to the renderer. Add _, localizer and brand_name globals.

Parameters:event – a pyramid.event.BeforeRender object
anuket.subscribers.add_localizer(event)[source]

Localization event subscriber.

Automaticaly translate strings in the templates.

Parameters:event – a pyramid.event.NewRequest object
anuket.subscribers.add_csrf_validation(event)[source]

CSRF validation event subscriber.

If the POST forms do not have a CSRF token, or an invalid one then user is logged out and the forbident view is called.

Parameters:event – a pyramid.event.NewRequest object
Raises HTTPForbidden:
 if the CSRF token is None or invalid