update zodb wiki files to synch with its cookiecutter using context manager
(cherry picked from commit 759febe)
| | |
| | | .. literalinclude:: src/authorization/tutorial/__init__.py |
| | | :lines: 18-25 |
| | | :lineno-match: |
| | | :emphasize-lines: 1-3,7-8 |
| | | :emphasize-lines: 2-4,6-7 |
| | | :language: python |
| | | |
| | | Only the highlighted lines need to be added. |
| | |
| | | |
| | | .. literalinclude:: src/authorization/tutorial/__init__.py |
| | | :linenos: |
| | | :emphasize-lines: 4-5,8,18-20,24-25 |
| | | :emphasize-lines: 4-5,8,19-21,23-24 |
| | | :language: python |
| | | |
| | | Only the highlighted lines need to be added or edited. |
| | |
| | | |
| | | #. *Line 11*. ``__init__.py`` defines a function named ``main``. |
| | | |
| | | #. *Line 14*. We construct a :term:`Configurator` with a root |
| | | factory and the settings keywords parsed by :term:`PasteDeploy`. The root |
| | | factory is named ``root_factory``. |
| | | #. *Line 14*. Use an explicit transaction manager for apps so that they do not implicitly create new transactions when touching the manager outside of the ``pyramid_tm`` lifecycle. |
| | | |
| | | #. *Lines 15 and 16*. Get the settings and use an explicit transaction transaction manager for apps so that they do not implicitly create new transactions when touching the manager outside of the ``pyramid_tm`` lifecycle. |
| | | #. *Line 15*. Construct a :term:`Configurator` as a :term:`context manager` with the settings keyword parsed by :term:`PasteDeploy`. |
| | | |
| | | #. *Line 17*. Include support for the :term:`Chameleon` template rendering |
| | | #. *Line 16*. Include support for the :term:`Chameleon` template rendering |
| | | bindings, allowing us to use the ``.pt`` templates. |
| | | |
| | | #. *Line 18*. Include support for ``pyramid_tm``, allowing Pyramid requests to join the active transaction as provided by the `transaction <https://pypi.python.org/pypi/transaction>`_ package. |
| | | #. *Line 17*. Include support for ``pyramid_tm``, allowing Pyramid requests to join the active transaction as provided by the `transaction <https://pypi.python.org/pypi/transaction>`_ package. |
| | | |
| | | #. *Line 19*. Include support for ``pyramid_retry`` to retry a request when transient exceptions occur. |
| | | #. *Line 18*. Include support for ``pyramid_retry`` to retry a request when transient exceptions occur. |
| | | |
| | | #. *Line 20*. Include support for ``pyramid_zodbconn``, providing integration between :term:`ZODB` and a Pyramid application. |
| | | #. *Line 19*. Include support for ``pyramid_zodbconn``, providing integration between :term:`ZODB` and a Pyramid application. |
| | | |
| | | #. *Line 20*. Set a root factory using our function named ``root_factory``. |
| | | |
| | | #. *Line 21*. Register a "static view", which answers requests whose URL |
| | | paths start with ``/static``, using the |
| | |
| | | package. Alternatively the cookiecutter could have used an *absolute* asset |
| | | specification as the path (``tutorial:static``). |
| | | |
| | | #. *Line 19*. Perform a :term:`scan`. A scan will find :term:`configuration |
| | | #. *Line 22*. Perform a :term:`scan`. A scan will find :term:`configuration |
| | | decoration`, such as view configuration decorators (e.g., ``@view_config``) |
| | | in the source code of the ``tutorial`` package and will take actions based |
| | | on these decorators. We don't pass any arguments to |
| | |
| | | The cookiecutter could have equivalently said ``config.scan('tutorial')``, but |
| | | it chose to omit the package name argument. |
| | | |
| | | #. *Line 20*. Use the |
| | | #. *Line 23*. Use the |
| | | :meth:`pyramid.config.Configurator.make_wsgi_app` method |
| | | to return a :term:`WSGI` application. |
| | | |
| | |
| | | By default, set these to ``None`` to indicate that this is the |
| | | :term:`root` object. |
| | | |
| | | #. *Lines 8-14*. ``appmaker`` is used to return the *application |
| | | #. *Lines 8-12*. ``appmaker`` is used to return the *application |
| | | root* object. It is called on *every request* to the |
| | | :app:`Pyramid` application. It also performs bootstrapping by |
| | | *creating* an application root (inside the ZODB root object) if one |
| | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | authn_policy = AuthTktAuthenticationPolicy( |
| | | 'sosecret', callback=groupfinder, hashalg='sha512') |
| | | authz_policy = ACLAuthorizationPolicy() |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | settings = config.get_settings() |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | config.set_authentication_policy(authn_policy) |
| | | config.set_authorization_policy(authz_policy) |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | with Configurator(settings=settings) as config: |
| | | config.set_authentication_policy(authn_policy) |
| | | config.set_authorization_policy(authz_policy) |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.set_root_factory(root_factory) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | settings = config.get_settings() |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.set_root_factory(root_factory) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | settings = config.get_settings() |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.set_root_factory(root_factory) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | settings = config.get_settings() |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.set_root_factory(root_factory) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | authn_policy = AuthTktAuthenticationPolicy( |
| | | 'sosecret', callback=groupfinder, hashalg='sha512') |
| | | authz_policy = ACLAuthorizationPolicy() |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | settings = config.get_settings() |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | config.set_authentication_policy(authn_policy) |
| | | config.set_authorization_policy(authz_policy) |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | with Configurator(settings=settings) as config: |
| | | config.set_authentication_policy(authn_policy) |
| | | config.set_authorization_policy(authz_policy) |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.set_root_factory(root_factory) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | settings = config.get_settings() |
| | | settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager' |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_chameleon') |
| | | config.include('pyramid_tm') |
| | | config.include('pyramid_retry') |
| | | config.include('pyramid_zodbconn') |
| | | config.set_root_factory(root_factory) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |