Skip to content

Commit

Permalink
- The ZODB wiki tutorial now uses the pyramid_zodbconn package ra…
Browse files Browse the repository at this point in the history
…ther

  than the ``repoze.zodbconn`` package to provide ZODB integration.

- The ZODB scaffold now uses the ``pyramid_zodbconn`` package rather than the
  ``repoze.zodbconn`` package to provide ZODB integration.
  • Loading branch information
mcdonc committed Aug 15, 2011
1 parent 2744356 commit b253355
Show file tree
Hide file tree
Showing 31 changed files with 104 additions and 143 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ Documentation
``resource_url``, ``static_url``, and ``current_route_url`` methods of the
request rather than the function variants imported from ``pyramid.url``.

- The ZODB wiki tutorial now uses the ``pyramid_zodbconn`` package rather
than the ``repoze.zodbconn`` package to provide ZODB integration.

Dependency Changes
------------------

Expand All @@ -153,6 +156,9 @@ Scaffolds
- All scaffolds now use the ``pyramid_tm`` package rather than the
``repoze.tm2`` middleware to manage transaction management.

- The ZODB scaffold now uses the ``pyramid_zodbconn`` package rather than the
``repoze.zodbconn`` package to provide ZODB integration.

- All scaffolds now use the ``pyramid_debugtoolbar`` package rather than the
``WebError`` package to provide interactive debugging features.

Expand Down
7 changes: 7 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Pyramid TODOs
Should-Have
-----------

- Name WSGI app "main" instead of pipeline in scaffold configs?

- Turn off debugtoolbar redirect catcher in scaffolding (makes tutorials
weird).

- Mention debug toolbar in tutorials.

- Make it possible to use tween aliases in explicit tween config? If not,
the tween factories of all add-ons must be APIs.

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/wiki/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declarative security checking. We need to import the new policies:
Then, we'll add those policies to the configuration:

.. literalinclude:: src/authorization/tutorial/__init__.py
:lines: 16-18,26-28
:lines: 20-25
:linenos:
:language: python

Expand Down
40 changes: 13 additions & 27 deletions docs/tutorials/wiki/basiclayout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,13 @@ point happens to be the ``main`` function within the file named

#. *Lines 1-3*. Perform some dependency imports.

#. *Line 8*. Get the ZODB configuration from the ``development.ini``
file's ``[app:main]`` section represented by the ``settings``
dictionary passed to our ``app`` function. This will be a URI
(something like ``file:///path/to/Data.fs``).
#. *Lines 5-7* Define a root factory for our Pyramid application.

#. *Line 12*. We create a "finder" object using the
``PersistentApplicationFinder`` helper class, passing it the ZODB
URI and the "appmaker" we've imported from ``models.py``.

#. *Lines 13 - 14*. We create a :term:`root factory` which uses the
finder to return a ZODB root object.

#. *Line 15*. We construct a :term:`Configurator` with a :term:`root
#. *Line 12*. We construct a :term:`Configurator` with a :term:`root
factory` and the settings keywords parsed by PasteDeploy. The root
factory is named ``get_root``.

#. *Line 16*. Register a 'static view' which answers requests which start
#. *Line 13*. Register a 'static view' which answers requests which start
with with URL path ``/static`` using the
:meth:`pyramid.config.Configurator.add_static_view method`. This
statement registers a view that will serve up static assets, such as CSS
Expand All @@ -59,14 +49,14 @@ point happens to be the ``main`` function within the file named
should serve within the ``static`` directory inside the ``tutorial``
package.

#. *Line 17*. Perform a :term:`scan`. A scan will find :term:`configuration
#. *Line 14*. 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. The argument to
:meth:`~pyramid.config.Configurator.scan` is the package name to scan,
which is ``tutorial``.

#. *Line 18*. Use the
#. *Line 15*. Use the
:meth:`pyramid.config.Configurator.make_wsgi_app` method
to return a :term:`WSGI` application.

Expand Down Expand Up @@ -100,7 +90,8 @@ Here is the source for ``models.py``:
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
does not already exist.
does not already exist. It is used by the "root_factory" we've defined
in our ``__init__.py``.

We do so by first seeing if the database has the persistent
application root. If not, we make an instance, store it, and
Expand Down Expand Up @@ -162,28 +153,23 @@ Let's try to understand the components in this module:
dictionary is used by the template named by the ``mytemplate.pt`` asset
specification to fill in certain values on the page.

The WSGI Pipeline in ``development.ini``
----------------------------------------
Configuration in ``development.ini``
------------------------------------

The ``development.ini`` (in the tutorial :term:`project` directory, as
opposed to the tutorial :term:`package` directory) looks like this:

.. literalinclude:: src/views/development.ini
:language: ini


Note the existence of a ``[pipeline:main]`` section which specifies our WSGI
pipeline. This "pipeline" will be served up as our WSGI application. As far
as the WSGI server is concerned the pipeline *is* our application. Simpler
configurations don't use a pipeline: instead they expose a single WSGI
application as "main". Our setup is more complicated, so we use a pipeline
composed of :term:`middleware`.
as the WSGI server is concerned the pipeline *is* our application.

The ``egg:repoze.zodbconn#closer`` middleware is at the top of the pipeline.
This is a piece of middleware which closes the ZODB connection opened by the
``PersistentApplicationFinder`` at the end of the request.
Our ZODB database settings are specified as the ``zodbconn.uri`` setting in
the application section.

The final line in the ``[pipeline:main]`` section is ``tutorial``, which
The only line in the ``[pipeline:main]`` section is ``tutorial``, which
refers to the ``[app:tutorial]`` section above it. The ``[app:tutorial]``
section is the section which actually defines our application settings. The
values within this section are passed as ``**settings`` to the ``main``
Expand Down
6 changes: 0 additions & 6 deletions docs/tutorials/wiki/definingmodels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ front page) into the Wiki within the ``appmaker``. This will provide
:term:`traversal` a :term:`resource tree` to work against when it attempts to
resolve URLs to resources.

We're using a mini-framework callable named ``PersistentApplicationFinder``
in our application (see ``__init__.py``). A ``PersistentApplicationFinder``
accepts a ZODB URL as well as an "appmaker" callback. This callback
typically lives in the ``models.py`` file. We'll just change this function,
making the necessary edits.

Looking at the Result of Our Edits to ``models.py``
---------------------------------------------------

Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/wiki/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ Preparation, UNIX
$ bin/easy_install pyramid
#. Use ``easy_install`` to install ``docutils``, ``pyramid_tm``,
``repoze.zodbconn``, ``nose`` and ``coverage``:
``pyramid_zodbconn``, ``pyramid_debugtoolbar``, ``nose`` and ``coverage``:

.. code-block:: text
$ bin/easy_install docutils pyramid_tm repoze.zodbconn \
nose coverage
$ bin/easy_install docutils pyramid_tm pyramid_zodbconn \
pyramid_debugtoolbar nose coverage
Preparation, Windows
--------------------
Expand Down Expand Up @@ -118,12 +118,12 @@ Preparation, Windows
c:\pyramidtut> Scripts\easy_install pyramid
#. Use ``easy_install`` to install ``docutils``, ``pyramid_tm``,
``repoze.zodbconn``, ``nose`` and ``coverage``:
``pyramid_zodbconn``, ``pyramid_debugtoolbar``, ``nose`` and ``coverage``:

.. code-block:: text
c:\pyramidtut> Scripts\easy_install docutils pyramid_tm \
repoze.zodbconn nose coverage
pyramid_zodbconn pyramid_debugtoolbar nose coverage
.. _making_a_project:

Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/wiki/src/authorization/development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.default_locale_name = en
pyramid.includes = pyramid_debugtoolbar
pyramid_zodbconn
pyramid_tm
tm.attempts = 3

zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
zodbconn.uri = file://%(here)s/Data.fs?connection_cache_size=20000

[pipeline:main]
pipeline =
egg:repoze.zodbconn#closer
tutorial

[server:main]
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/wiki/src/authorization/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.default_locale_name = en
pyramid.includes = pyramid_tm
pyramid_zodbconn
tm.attempts = 3

zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
zodbconn.uri = file://%(here)s/Data.fs?connection_cache_size=20000

[pipeline:main]
pipeline =
egg:repoze.zodbconn#closer
tutorial

[server:main]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/wiki/src/authorization/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

requires = [
'pyramid',
'repoze.zodbconn',
'pyramid_zodbconn',
'pyramid_tm',
'pyramid_debugtoolbar',
'ZODB3',
Expand Down
17 changes: 7 additions & 10 deletions docs/tutorials/wiki/src/authorization/tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from repoze.zodbconn.finder import PersistentApplicationFinder

from pyramid.config import Configurator
from pyramid_zodbconn import get_connection

from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy

from tutorial.models import appmaker
from tutorial.security import groupfinder

def root_factory(request):
conn = get_connection(request)
return appmaker(conn.root())

def main(global_config, **settings):
""" This function returns a WSGI application.
Expand All @@ -16,14 +20,7 @@ def main(global_config, **settings):
authn_policy = AuthTktAuthenticationPolicy(secret='sosecret',
callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
zodb_uri = settings.get('zodb_uri', False)
if zodb_uri is False:
raise ValueError("No 'zodb_uri' in application configuration.")

finder = PersistentApplicationFinder(zodb_uri, appmaker)
def get_root(request):
return finder(request.environ)
config = Configurator(root_factory=get_root, settings=settings,
config = Configurator(root_factory=root_factory, settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy)
config.add_static_view('static', 'tutorial:static')
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/wiki/src/basiclayout/development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.default_locale_name = en
pyramid.includes = pyramid_debugtoolbar
pyramid_zodbconn
pyramid_tm
tm.attempts = 3

zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
zodbconn.uri = file://%(here)s/Data.fs?connection_cache_size=20000

[pipeline:main]
pipeline =
egg:repoze.zodbconn#closer
tutorial

[server:main]
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/wiki/src/basiclayout/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.default_locale_name = en
pyramid.includes = pyramid_tm
pyramid_zodbconn
tm.attempts = 3

zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
zodbconn.uri = file://%(here)s/Data.fs?connection_cache_size=20000

[pipeline:main]
pipeline =
egg:repoze.zodbconn#closer
tutorial

[server:main]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/wiki/src/basiclayout/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

requires = [
'pyramid',
'repoze.zodbconn',
'pyramid_zodbconn',
'pyramid_tm',
'pyramid_debugtoolbar',
'ZODB3',
Expand Down
15 changes: 6 additions & 9 deletions docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
from pyramid.config import Configurator
from repoze.zodbconn.finder import PersistentApplicationFinder
from pyramid_zodbconn import get_connection
from tutorial.models import appmaker

def root_factory(request):
conn = get_connection(request)
return appmaker(conn.root())

def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
zodb_uri = settings.get('zodb_uri', False)
if zodb_uri is False:
raise ValueError("No 'zodb_uri' in application configuration.")

finder = PersistentApplicationFinder(zodb_uri, appmaker)
def get_root(request):
return finder(request.environ)
config = Configurator(root_factory=get_root, settings=settings)
config = Configurator(root_factory=root_factory, settings=settings)
config.add_static_view('static', 'tutorial:static')
config.scan('tutorial')
return config.make_wsgi_app()
5 changes: 2 additions & 3 deletions docs/tutorials/wiki/src/models/development.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.default_locale_name = en
pyramid.includes = pyramid_debugtoolbar
pyramid_zodbconn
pyramid_tm
tm.attempts = 3

zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
zodbconn.uri = file://%(here)s/Data.fs?connection_cache_size=20000

[pipeline:main]
pipeline =
egg:repoze.zodbconn#closer
tutorial

[server:main]
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/wiki/src/models/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.default_locale_name = en
pyramid.includes = pyramid_tm
pyramid_zodbconn
tm.attempts = 3

zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
zodbconn.uri = file://%(here)s/Data.fs?connection_cache_size=20000

[pipeline:main]
pipeline =
egg:repoze.zodbconn#closer
tutorial

[server:main]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/wiki/src/models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

requires = [
'pyramid',
'repoze.zodbconn',
'pyramid_zodbconn',
'pyramid_tm',
'pyramid_debugtoolbar',
'ZODB3',
Expand Down
15 changes: 6 additions & 9 deletions docs/tutorials/wiki/src/models/tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
from pyramid.config import Configurator
from repoze.zodbconn.finder import PersistentApplicationFinder
from pyramid_zodbconn import get_connection
from tutorial.models import appmaker

def root_factory(request):
conn = get_connection(request)
return appmaker(conn.root())

def main(global_config, **settings):
""" This function returns a WSGI application.
"""
zodb_uri = settings.get('zodb_uri', False)
if zodb_uri is False:
raise ValueError("No 'zodb_uri' in application configuration.")

finder = PersistentApplicationFinder(zodb_uri, appmaker)
def get_root(request):
return finder(request.environ)
config = Configurator(root_factory=get_root, settings=settings)
config = Configurator(root_factory=root_factory, settings=settings)
config.add_static_view('static', 'tutorial:static')
config.scan('tutorial')
return config.make_wsgi_app()
Expand Down
Loading

0 comments on commit b253355

Please sign in to comment.