diff options
| author | Chris McDonough <chrism@plope.com> | 2010-10-29 13:23:31 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2010-10-29 13:23:31 -0400 |
| commit | 197f0cb39d0a865476405dda21ad0d3e20ee0789 (patch) | |
| tree | 061f4595339022831dcd2c31275d0964eed77647 /docs/tutorials/wiki | |
| parent | 66ecc57eb00063edfa01d66f8d6f4495d21d79b5 (diff) | |
| download | pyramid-197f0cb39d0a865476405dda21ad0d3e20ee0789.tar.gz pyramid-197f0cb39d0a865476405dda21ad0d3e20ee0789.tar.bz2 pyramid-197f0cb39d0a865476405dda21ad0d3e20ee0789.zip | |
bfg_view -> view_config
Diffstat (limited to 'docs/tutorials/wiki')
| -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 |
5 files changed, 38 insertions, 37 deletions
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 |
