websauna.system package¶
Websauna framework initialization routine.
-
class
websauna.system.
DemoInitializer
(global_config, settings=None)[source]¶ Bases:
websauna.system.Initializer
Websauna uses internally to run tests, development server.
-
class
websauna.system.
Initializer
(global_config, settings=None)[source]¶ Bases:
object
Initializer is responsible to ramp up the frameworks and subsystems.
There exist one
Initializer
instance which you create in your WSGI application constructor.You subclass the default
Initializer
provider by WebsaunaYou override the methods for the parts where you want to customize the default Websauna behavior
You also need to include addons and other Pyramid package configurations. This is usually done by calling
self.config.include("your_pyramid_package")
.You can add your own application specific view initializations, like
self.config.scan()
for your application Python modules to register@view_config
directives in those.
See
websauna.system.Initializer.run()
for linear initialization order.Aspect-oriented approach with
websauna.utils.aspect.event_source
is used to provide hooks for addons to participate initialization process.Note
We deliberate push imports inside methods, so that it is unlikely we’d have any import time side effects caused by some less elegant solutions, like gevent.
-
celery
= None¶ Reference to Celery app instance
-
configure_authentication
()[source]¶ Set up authentication and authorization policies.
For more information see Pyramid auth documentation.
-
configure_database
()[source]¶ Configure database.
Set up base model
Set up mechanism to create database session for requests
Set up transaction machinery
Calls py:func:websauna.system.model.meta.includeme.
-
configure_federated_login
()[source]¶ Configure federated authentication (OAuth).
Set up Authomatic login services.
Read enabled federated authentication methods from the configuration file.
-
configure_forms
()[source]¶ Configure subsystems for rendering Deform forms.
Deform templates
Deform JS and CSS
CSRf view mapper
-
configure_instrumented_models
()[source]¶ Configure models from third party addons and dynamic SQLAlchemy fields which need access to the configuration.
Third party addons might need references to configurable models which are not available at the import time. One of these models is user - you can supply your own user model. However third party addon models might want to build foreign key relationships to this model. Thus,
configure_instrumented_models()
is an initialization step which is called when database setup is half way there and you want to throw in some extra models in.This exposes
Configurator
to SQLAlchemy throughwebsauna.system.model.meta.Base.metadata.pyramid_config
variable.
-
configure_logging
()[source]¶ Create and set Pyramid debug logger.
Please note that most o the logging is configured through the configuration file and that should be the primary way to do it.
-
configure_models
()[source]¶ Configure all models from your application.
Import related model modules and scan them.
Importing anything with
websauna.system.model.meta.Base
base class registers this model to an SQLAlchemy model registry for migrations.
-
configure_password
()[source]¶ Configure system password hashing solution.
By default use Argon 2
For more information see
websauna.system.user.password
-
configure_root
()[source]¶ Root object defines permissions for route URLs which have not their own traversing context.
http://pyramid-tutorials.readthedocs.org/en/latest/getting_started/10-security/
-
configure_sitemap
()[source]¶ Configure sitemap generation for your site.
By default this is not configured and nothing is done.
-
configure_static
()[source]¶ Configure static asset views.
By default we serve only core Websauna assets. Override this to add more static asset declarations to your app.
-
configure_tasks
()[source]¶ Scan all Python modules with asynchoronous and periodic tasks to be imported.
-
configure_user
()[source]¶ Configure user model, sign in and sign up subsystem.
User services
Sign in and sign up templates and views
User events
-
configure_user_models
()[source]¶ Plug in user models.
This initialization step connects chosen user model to SQLAlchemy model Base. Also set up
websauna.system.user.usermixin.SiteCreator
logic - what happens when the first user logs in.
-
include_addons
()[source]¶ Override this method to include Websauna addons for your app.
Websauna addons are created with
websauna_addon
scaffold.By default do nothing.
-
make_wsgi_app
(sanity_check=True)[source]¶ Create WSGI application from the current setup.
- Parameters
sanity_check – True if perform post-initialization sanity checks.
- Returns
WSGI application
-
run
()[source]¶ Run the initialization and prepare Pyramid subsystems.
This is the main entry for ramping up a Websauna application. We go through various subsystem inits.
-
sanity_check
()[source]¶ Perform post-initialization sanity checks.
This is run on every startup to check that the database table schema matches our model definitions. If there are un-run migrations this will bail out and do not let the problem to escalate later.
See also: websauna.sanity_check.
-
exception
websauna.system.
RequirementsFailed
[source]¶ Bases:
Exception
Websauna minimum requirements were not met.
-
exception
websauna.system.
SanityCheckFailed
[source]¶ Bases:
Exception
Looks like the application has configuration which would fail to run.
-
websauna.system.
check_python_pyramid_requirements
()[source]¶ Check for Python and Pyramid requirements.
- Return type
- Returns
Boolean indicating if Python and Pyramid requirements are met.
-
websauna.system.
expandvars_dict
(settings)[source]¶ Expand all environment variables in a settings dictionary.
ref: http://stackoverflow.com/a/16446566 :rtype:
dict
:returns: Dictionary with settings
-
websauna.system.
get_init
(global_config, settings, init_cls=None)[source]¶ Get Initializer class instance for WSGI-like app.
TODO: Deprecated. Use Pyramid’s
bootstrap()
instead.Reads reference to the initializer from settings, resolves it and creates the initializer instance.
Example 1:
config_uri = argv[1] init = get_init(dict(__file__=config_uri), settings)
- Parameters
global_config – Global config dictionary, having __file__ entry as given by Paster
settings – Settings dictionary
init_cls – Explicitly give the Initializer class to use, otherwise read
websauna.init
settings.
- Return type
-
websauna.system.
main
(global_config, **settings)[source]¶ Entry point for creating a Pyramid WSGI application.
Subpackages¶
- websauna.system.admin package
- Submodules
- websauna.system.admin.admin module
- websauna.system.admin.events module
- websauna.system.admin.filters module
- websauna.system.admin.interfaces module
- websauna.system.admin.menu module
- websauna.system.admin.modeladmin module
- websauna.system.admin.subscribers module
- websauna.system.admin.utils module
- websauna.system.admin.views module
- Submodules
- websauna.system.auth package
- websauna.system.core package
- Subpackages
- Submodules
- websauna.system.core.breadcrumbs module
- websauna.system.core.events module
- websauna.system.core.interfaces module
- websauna.system.core.loggingcapture module
- websauna.system.core.messages module
- websauna.system.core.panel module
- websauna.system.core.redis module
- websauna.system.core.render module
- websauna.system.core.root module
- websauna.system.core.route module
- websauna.system.core.session module
- websauna.system.core.simpleroute module
- websauna.system.core.sitemap module
- websauna.system.core.templatecontext module
- websauna.system.core.traversal module
- websauna.system.core.utils module
- websauna.system.core.vars module
- websauna.system.core.viewconfig module
- websauna.system.crud package
- websauna.system.devop package
- websauna.system.form package
- Submodules
- websauna.system.form.colander module
- websauna.system.form.csrf module
- websauna.system.form.deform module
- websauna.system.form.editmode module
- websauna.system.form.fieldmapper module
- websauna.system.form.fields module
- websauna.system.form.interfaces module
- websauna.system.form.interstitial module
- websauna.system.form.resourceregistry module
- websauna.system.form.resources module
- websauna.system.form.rollingwindow module
- websauna.system.form.schema module
- websauna.system.form.sqlalchemy module
- websauna.system.form.throttle module
- websauna.system.form.widgets module
- Submodules
- websauna.system.http package
- websauna.system.mail package
- websauna.system.model package
- Submodules
- websauna.system.model.columns module
- websauna.system.model.interfaces module
- websauna.system.model.json module
- websauna.system.model.meta module
- websauna.system.model.retry module
- websauna.system.model.sanitycheck module
- websauna.system.model.sqlalchemyutcdatetime module
- websauna.system.model.utils module
- Submodules
- websauna.system.notebook package
- websauna.system.task package
- websauna.system.user package
- Submodules
- websauna.system.user.admins module
- websauna.system.user.adminviews module
- websauna.system.user.credentialactivityservice module
- websauna.system.user.events module
- websauna.system.user.forms module
- websauna.system.user.googleoauth module
- websauna.system.user.interfaces module
- websauna.system.user.loginservice module
- websauna.system.user.models module
- websauna.system.user.oauthloginservice module
- websauna.system.user.password module
- websauna.system.user.registrationservice module
- websauna.system.user.schemas module
- websauna.system.user.social module
- websauna.system.user.subscribers module
- websauna.system.user.usermixin module
- websauna.system.user.userregistry module
- websauna.system.user.utils module
- websauna.system.user.views module
- Submodules