diff options
| author | Ben Bangert <ben@groovie.org> | 2010-10-29 11:14:41 -0700 |
|---|---|---|
| committer | Ben Bangert <ben@groovie.org> | 2010-10-29 11:14:41 -0700 |
| commit | 17e70c8db9140c0b4062f46ef5eb4527d678b793 (patch) | |
| tree | 38b6b8de2a57db4debec477bc4fda27db82c4c5a /docs/tutorials | |
| parent | d39e99e1f6f06a02a275a8a30f154e0f292d7dff (diff) | |
| parent | 5038994ea9e053b16fca74ea8fa022871e630883 (diff) | |
| download | pyramid-17e70c8db9140c0b4062f46ef5eb4527d678b793.tar.gz pyramid-17e70c8db9140c0b4062f46ef5eb4527d678b793.tar.bz2 pyramid-17e70c8db9140c0b4062f46ef5eb4527d678b793.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/tutorials')
| -rw-r--r-- | docs/tutorials/catalog/index.rst | 10 | ||||
| -rw-r--r-- | docs/tutorials/modwsgi/index.rst | 2 | ||||
| -rw-r--r-- | docs/tutorials/wiki/authorization.rst | 14 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/login.py | 6 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/authorization/tutorial/views.py | 14 | ||||
| -rw-r--r-- | docs/tutorials/wiki/src/viewdecorators/tutorial/views.py | 10 | ||||
| -rw-r--r-- | docs/tutorials/wiki/viewdecorators.rst | 31 |
7 files changed, 44 insertions, 43 deletions
diff --git a/docs/tutorials/catalog/index.rst b/docs/tutorials/catalog/index.rst index 9a5bbfb2f..424286bd9 100644 --- a/docs/tutorials/catalog/index.rst +++ b/docs/tutorials/catalog/index.rst @@ -1,7 +1,7 @@ .. _catalog_tutorial: -Using :mod:`repoze.catalog` Within :mod:`repoze.bfg` -==================================================== +Using :mod:`repoze.catalog` Within :mod:`pyramid` +================================================= :mod:`repoze.catalog` is a ZODB-based system that can be used to index Python objects. It also offers a query interface for retrieving @@ -83,12 +83,12 @@ want the application to be based on :term:`traversal`. .. code-block:: text - [chrism@snowpro sess]$ ../bin/paster --plugin=repoze.bfg bfgshell \ + [chrism@snowpro sess]$ ../bin/paster --plugin=pyramid bfgshell \ myapp.ini myapp Python 2.5.4 (r254:67916, Sep 4 2009, 02:12:16) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help" for more information. "root" is the BFG app root object. - >>> from repoze.bfg.traversal import model_path + >>> from pyramid.traversal import model_path >>> from myapp.models import Document >>> root['name'] = Document('title') >>> doc = root['name'] @@ -107,7 +107,7 @@ or from within a ``bfgshell`` session to update the set of indexes used by your application. In :term:`view` code, you should be able to get a hold of the root -object via the :func:`repoze.bfg.traversal.find_root` API. The +object via the :func:`pyramid.traversal.find_root` API. The ``catalog`` attribute of that root object will represent the catalog previously added. diff --git a/docs/tutorials/modwsgi/index.rst b/docs/tutorials/modwsgi/index.rst index 5572e300b..8b429a0c8 100644 --- a/docs/tutorials/modwsgi/index.rst +++ b/docs/tutorials/modwsgi/index.rst @@ -54,7 +54,7 @@ commands and files. .. code-block:: text $ cd ~/modwsgi/env - $ bin/easy_install repoze.bfg + $ bin/easy_install pyramid #. Create and install your :mod:`pyramid` application. For the purposes of this tutorial, we'll just be using the ``bfg_starter`` diff --git a/docs/tutorials/wiki/authorization.rst b/docs/tutorials/wiki/authorization.rst index 0d135f5e2..189401a45 100644 --- a/docs/tutorials/wiki/authorization.rst +++ b/docs/tutorials/wiki/authorization.rst @@ -182,12 +182,12 @@ Our resulting ``models.py`` file will now look like so: :linenos: :language: python -Adding ``permission`` Declarations to our ``bfg_view`` Decorators ------------------------------------------------------------------ +Adding ``permission`` Declarations to our ``view_config`` Decorators +-------------------------------------------------------------------- To protect each of our views with a particular permission, we need to pass a ``permission`` argument to each of our -:class:`pyramid.view.bfg_view` decorators. To do so, within +:class:`pyramid.view.view_config` decorators. To do so, within ``views.py``: - We add ``permission='view'`` to the decorator attached to the @@ -220,10 +220,10 @@ pass a ``permission`` argument to each of our consults the ``GROUPS`` data structure. This means that the ``editor`` user can add pages. -- We add ``permission='edit'`` to the ``bfg_view`` decorator attached - to the ``edit_page`` view function. This makes the assertion that - only users who possess the effective ``edit`` permission at the time - of the request may invoke this view. We've granted the +- We add ``permission='edit'`` to the decorator attached to the + ``edit_page`` view function. This makes the assertion that only + users who possess the effective ``edit`` permission at the time of + the request may invoke this view. We've granted the ``group:editors`` principal the ``edit`` permission at the root model via its ACL, so only the a user whom is a member of the group named ``group:editors`` will able to invoke the ``edit_page`` view. diff --git a/docs/tutorials/wiki/src/authorization/tutorial/login.py b/docs/tutorials/wiki/src/authorization/tutorial/login.py index ee67d9a5e..60e69fddf 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/login.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/login.py @@ -1,6 +1,6 @@ from pyramid.httpexceptions import HTTPFound -from pyramid.view import bfg_view +from pyramid.view import view_config from pyramid.url import model_url from pyramid.security import remember @@ -9,7 +9,7 @@ from pyramid.security import forget from tutorial.models import Wiki from tutorial.security import USERS -@bfg_view(context=Wiki, name='login', renderer='templates/login.pt') +@view_config(context=Wiki, name='login', renderer='templates/login.pt') def login(request): login_url = model_url(request.context, request, 'login') referrer = request.url @@ -36,7 +36,7 @@ def login(request): password = password, ) -@bfg_view(context=Wiki, name='logout') +@view_config(context=Wiki, name='logout') def logout(request): headers = forget(request) return HTTPFound(location = model_url(request.context, request), diff --git a/docs/tutorials/wiki/src/authorization/tutorial/views.py b/docs/tutorials/wiki/src/authorization/tutorial/views.py index 8c35afcd6..48e4e2b43 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/views.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/views.py @@ -6,7 +6,7 @@ from pyramid.url import model_url from pyramid.security import authenticated_userid -from pyramid.view import bfg_view +from pyramid.view import view_config from tutorial.models import Page from tutorial.models import Wiki @@ -14,11 +14,11 @@ from tutorial.models import Wiki # regular expression used to find WikiWords wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)") -@bfg_view(context=Wiki, permission='view') +@view_config(context=Wiki, permission='view') def view_wiki(context, request): return HTTPFound(location = model_url(context, request, 'FrontPage')) -@bfg_view(context=Page, renderer='templates/view.pt', permission='view') +@view_config(context=Page, renderer='templates/view.pt', permission='view') def view_page(context, request): wiki = context.__parent__ @@ -41,8 +41,8 @@ def view_page(context, request): return dict(page = context, content = content, edit_url = edit_url, logged_in = logged_in) -@bfg_view(context=Wiki, name='add_page', renderer='templates/edit.pt', - permission='edit') +@view_config(context=Wiki, name='add_page', renderer='templates/edit.pt', + permission='edit') def add_page(context, request): name = request.subpath[0] if 'form.submitted' in request.params: @@ -61,8 +61,8 @@ def add_page(context, request): return dict(page = page, save_url = save_url, logged_in = logged_in) -@bfg_view(context=Page, name='edit_page', renderer='templates/edit.pt', - permission='edit') +@view_config(context=Page, name='edit_page', renderer='templates/edit.pt', + permission='edit') def edit_page(context, request): if 'form.submitted' in request.params: context.data = request.params['body'] diff --git a/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py b/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py index 937a67344..168965db2 100644 --- a/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py +++ b/docs/tutorials/wiki/src/viewdecorators/tutorial/views.py @@ -3,7 +3,7 @@ import re from pyramid.httpexceptions import HTTPFound from pyramid.url import model_url -from pyramid.view import bfg_view +from pyramid.view import view_config from tutorial.models import Page from tutorial.models import Wiki @@ -11,11 +11,11 @@ from tutorial.models import Wiki # regular expression used to find WikiWords wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)") -@bfg_view(context=Wiki) +@view_config(context=Wiki) def view_wiki(context, request): return HTTPFound(location = model_url(context, request, 'FrontPage')) -@bfg_view(context=Page, renderer='templates/view.pt') +@view_config(context=Page, renderer='templates/view.pt') def view_page(context, request): wiki = context.__parent__ @@ -34,7 +34,7 @@ def view_page(context, request): edit_url = model_url(context, request, 'edit_page') return dict(page = context, content = content, edit_url = edit_url) -@bfg_view(context=Wiki, name='add_page', renderer='templates/edit.pt') +@view_config(context=Wiki, name='add_page', renderer='templates/edit.pt') def add_page(context, request): name = request.subpath[0] if 'form.submitted' in request.params: @@ -50,7 +50,7 @@ def add_page(context, request): page.__parent__ = context return dict(page = page, save_url = save_url) -@bfg_view(context=Page, name='edit_page', renderer='templates/edit.pt') +@view_config(context=Page, name='edit_page', renderer='templates/edit.pt') def edit_page(context, request): if 'form.submitted' in request.params: context.data = request.params['body'] diff --git a/docs/tutorials/wiki/viewdecorators.rst b/docs/tutorials/wiki/viewdecorators.rst index 7d202ee6d..2d58890e4 100644 --- a/docs/tutorials/wiki/viewdecorators.rst +++ b/docs/tutorials/wiki/viewdecorators.rst @@ -3,25 +3,26 @@ Using View Decorators Rather than ZCML ``view`` directives ========================================================== So far we've been using :term:`ZCML` to map model types to views. -It's often easier to use the ``bfg_view`` view decorator to do this -mapping. Using view decorators provides better locality of reference -for the mapping, because you can see which model types and view names -the view will serve right next to the view function itself. In this -mode, however, you lose the ability for some views to be overridden -"from the outside" (by someone using your application as a framework, -as explained in the :ref:`extending_chapter`). Since this application -is not meant to be a framework, it makes sense for us to switch over -to using view decorators. +It's often easier to use the :class:`pyramid.view.view_config` view +decorator to do this mapping. Using view decorators provides better +locality of reference for the mapping, because you can see which model +types and view names the view will serve right next to the view +function itself. In this mode, however, you lose the ability for some +views to be overridden "from the outside" (by someone using your +application as a framework, as explained in the +:ref:`extending_chapter`). Since this application is not meant to be +a framework, it makes sense for us to switch over to using view +decorators. Adding View Decorators ====================== -We're going to import the :class:`pyramid.view.bfg_view` callable. +We're going to import the :class:`pyramid.view.view_config` callable. This callable can be used as a function, class, or method decorator. We'll use it to decorate our ``view_wiki``, ``view_page``, ``add_page`` and ``edit_page`` view functions. -The :class:`pyramid.view.bfg_view` callable accepts a number of +The :class:`pyramid.view.view_config` callable accepts a number of arguments: ``context`` @@ -50,7 +51,7 @@ The decorator above the ``view_wiki`` function will be: .. code-block:: python :linenos: - @bfg_view(context=Wiki) + @view_config(context=Wiki) This indicates that the view is for the Wiki class and has the *empty* view_name (indicating the :term:`default view` for the Wiki class). @@ -76,7 +77,7 @@ The decorator above the ``view_page`` function will be: .. code-block:: python :linenos: - @bfg_view(context=Page, renderer='templates/view.pt') + @view_config(context=Page, renderer='templates/view.pt') This indicates that the view is for the Page class and has the *empty* view_name (indicating the :term:`default view` for the Page class). @@ -103,7 +104,7 @@ The decorator above the ``add_page`` function will be: .. code-block:: python :linenos: - @bfg_view(context=Wiki, name='add_page', renderer='templates/edit.pt') + @view_config(context=Wiki, name='add_page', renderer='templates/edit.pt') This indicates that the view is for the Wiki class and has the ``add_page`` view_name. After injecting this decorator, we can now @@ -130,7 +131,7 @@ The decorator above the ``edit_page`` function will be: .. code-block:: python :linenos: - @bfg_view(context=Page, name='edit_page', renderer='templates/edit.pt') + @view_config(context=Page, name='edit_page', renderer='templates/edit.pt') This indicates that the view is for the Page class and has the ``edit_page`` view_name. After injecting this decorator, we can now |
