summaryrefslogtreecommitdiff
path: root/docs/tutorials
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-18 22:33:34 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-18 22:33:34 +0000
commitfba349892ccdf2b2e82f51fc42b4e556fa3db726 (patch)
tree928f5bd3eee8cbbb336d809fc802408bc7031773 /docs/tutorials
parent70d0a179ce80c8ce0992157d3e7e5afa99fddcb1 (diff)
downloadpyramid-fba349892ccdf2b2e82f51fc42b4e556fa3db726.tar.gz
pyramid-fba349892ccdf2b2e82f51fc42b4e556fa3db726.tar.bz2
pyramid-fba349892ccdf2b2e82f51fc42b4e556fa3db726.zip
Rejigger tutorial in the face of request-only default views.
Diffstat (limited to 'docs/tutorials')
-rw-r--r--docs/tutorials/bfgwiki2/authorization.rst21
-rw-r--r--docs/tutorials/bfgwiki2/basiclayout.rst14
-rw-r--r--docs/tutorials/bfgwiki2/definingviews.rst17
-rw-r--r--docs/tutorials/bfgwiki2/src/authorization/tutorial/login.py4
-rw-r--r--docs/tutorials/bfgwiki2/src/authorization/tutorial/views.py8
-rw-r--r--docs/tutorials/bfgwiki2/src/basiclayout/tutorial/views.py2
-rw-r--r--docs/tutorials/bfgwiki2/src/models/tutorial/views.py2
7 files changed, 31 insertions, 37 deletions
diff --git a/docs/tutorials/bfgwiki2/authorization.rst b/docs/tutorials/bfgwiki2/authorization.rst
index 1e1fce92c..a8100999e 100644
--- a/docs/tutorials/bfgwiki2/authorization.rst
+++ b/docs/tutorials/bfgwiki2/authorization.rst
@@ -18,7 +18,7 @@ Adding A Root Factory
We're going to start to use a custom *root factory* within our
``run.py`` file in order to be able to attach security declarations to
-our :term:`context` object. When we do this, we can begin to make use
+a :term:`context` object. When we do this, we can begin to make use
of the declarative security features of :mod:`repoze.bfg`.
Let's modify our ``run.py``, passing in a :term:`root factory` as the
@@ -38,14 +38,15 @@ statements to your ``models.py`` file:
Defining a root factory allows us to use declarative security features
of :mod:`repoze.bfg`. The ``RootFactory`` class we added will be used
-to construct each of the ``context`` objects passed to our views. All
-of our ``context`` objects will possess an ``__acl__`` attribute that
-allows "Everyone" (a special principal) to view all request, while
-allowing only a user named ``editor`` to edit and add pages. The
-``__acl__`` attribute attached to a context is interpreted specially
-by :mod:`repoze.bfg` as an access control list during view execution.
-See :ref:`assigning_acls` for more information about what an
-:term:`ACL` represents.
+to construct each of the ``context`` objects. The context is attached
+to our request as the ``context`` attribute. All of our ``context``
+objects will possess an ``__acl__`` attribute that allows "Everyone"
+(a special principal) to view all pages, while allowing only a user
+named ``editor`` to edit and add pages. The ``__acl__`` attribute
+attached to a context is interpreted specially by :mod:`repoze.bfg` as
+an access control list during view execution. See
+:ref:`assigning_acls` for more information about what an :term:`ACL`
+represents.
.. note: Although we don't use the functionality here, the ``factory``
used to create route contexts may differ per-route instead of
@@ -125,7 +126,7 @@ to pass the `resulting `logged_in`` value to the template, e.g.:
return render_template_to_response('templates/view.pt',
request = request,
- page = context,
+ page = page,
content = content,
logged_in = logged_in,
edit_url = edit_url)
diff --git a/docs/tutorials/bfgwiki2/basiclayout.rst b/docs/tutorials/bfgwiki2/basiclayout.rst
index 303622c7e..8809bc503 100644
--- a/docs/tutorials/bfgwiki2/basiclayout.rst
+++ b/docs/tutorials/bfgwiki2/basiclayout.rst
@@ -36,8 +36,8 @@ XML namespace. Our sample ZCML file looks like the following:
attribute, it is the "default" route. The attribute named ``view``
with the value ``.views.my_view`` is the dotted name to a
*function* we write (generated by the ``bfg_routesalchemy``
- template) that is given a ``context`` and a ``request`` and returns
- a response. You will use mostly ``<route>`` statements in a
+ template) that is given a ``request`` object and which returns a
+ response. You will use mostly ``<route>`` statements in a
:term:`URL dispatch` based application to map URLs to code.
#. *Lines 14-17*. Register a ``<view>`` with a path that starts with
@@ -54,11 +54,11 @@ XML namespace. Our sample ZCML file looks like the following:
Content Models with ``models.py``
---------------------------------
-In the context of a SQLAlchemy-based application, a *model* object is
-an object composed by quering the SQL database which backs an
-application. SQLAlchemy is an "object relational mapper" (an ORM).
-The ``models.py`` file is where the ``bfg_zodb`` Paster template put
-the classes that implement our models.
+In a SQLAlchemy-based application, a *model* object is an object
+composed by quering the SQL database which backs an application.
+SQLAlchemy is an "object relational mapper" (an ORM). The
+``models.py`` file is where the ``bfg_routesalchemy`` Paster template
+put the classes that implement our models.
Here is the source for ``models.py``:
diff --git a/docs/tutorials/bfgwiki2/definingviews.rst b/docs/tutorials/bfgwiki2/definingviews.rst
index 25f52291c..df19a21c2 100644
--- a/docs/tutorials/bfgwiki2/definingviews.rst
+++ b/docs/tutorials/bfgwiki2/definingviews.rst
@@ -2,16 +2,10 @@
Defining Views
==============
-Views in BFG are typically simple Python functions that accept two
-parameters: :term:`context`, and :term:`request`. A view is assumed
-to return a :term:`response` object.
-
-A invocation of a view that matches a URL via :term:`url dispatch`
-passes as the context object an object generated by a ``root
-factory``. In this application, the context will always be generated
-by the *default* root factory. Since we're not using traversal in
-this application, this means the context will appear useless, at least
-until we get to :ref:`wiki2_adding_authorization`.
+Views in a :term:`url dispatch` -based BFG application are typically
+simple Python functions that accept a single parameter:
+::term:`request`. A view is assumed to return a :term:`response`
+object.
The request passed to every view that is called as the result of a
route match has an attribute named ``matchdict`` that contains the
@@ -164,8 +158,7 @@ If the view rendering *is* a result of a form submission (if the
expression ``'form.submitted' in request.params`` is True), the view
grabs the ``body`` element of the request parameter and sets it as the
``data`` key in the matchdict. It then redirects to the default view
-of the context (the page), which will always be the ``view_page``
-view.
+of the wiki page, which will always be the ``view_page`` view.
Viewing the Result of Our Edits to ``views.py``
===============================================
diff --git a/docs/tutorials/bfgwiki2/src/authorization/tutorial/login.py b/docs/tutorials/bfgwiki2/src/authorization/tutorial/login.py
index 28c3e05b4..b5a2a836c 100644
--- a/docs/tutorials/bfgwiki2/src/authorization/tutorial/login.py
+++ b/docs/tutorials/bfgwiki2/src/authorization/tutorial/login.py
@@ -9,7 +9,7 @@ from repoze.bfg.security import forget
from tutorial.run import USERS
-def login(context, request):
+def login(request):
login_url = url_for('login')
referrer = request.environ.get('HTTP_REFERER', '/')
if referrer == login_url:
@@ -37,7 +37,7 @@ def login(context, request):
request =request,
)
-def logout(context, request):
+def logout(request):
headers = forget(request)
return HTTPFound(location = url_for('view_wiki'),
headers = headers)
diff --git a/docs/tutorials/bfgwiki2/src/authorization/tutorial/views.py b/docs/tutorials/bfgwiki2/src/authorization/tutorial/views.py
index 4bcaae185..fd6c410e2 100644
--- a/docs/tutorials/bfgwiki2/src/authorization/tutorial/views.py
+++ b/docs/tutorials/bfgwiki2/src/authorization/tutorial/views.py
@@ -18,10 +18,10 @@ wikiwords = re.compile(r"\b([A-Z]\w+[A-Z]+\w+)")
static_view = static('templates/static')
-def view_wiki(context, request):
+def view_wiki(request):
return HTTPFound(location = url_for('view_page', pagename='FrontPage'))
-def view_page(context, request):
+def view_page(request):
pagename = request.matchdict['pagename']
session = DBSession()
page = session.query(Page).filter_by(name=pagename).one()
@@ -47,7 +47,7 @@ def view_page(context, request):
logged_in = logged_in,
edit_url = edit_url)
-def add_page(context, request):
+def add_page(request):
name = request.matchdict['pagename']
if 'form.submitted' in request.params:
session = DBSession()
@@ -64,7 +64,7 @@ def add_page(context, request):
logged_in = logged_in,
save_url = save_url)
-def edit_page(context, request):
+def edit_page(request):
name = request.matchdict['pagename']
session = DBSession()
page = session.query(Page).filter_by(name=name).one()
diff --git a/docs/tutorials/bfgwiki2/src/basiclayout/tutorial/views.py b/docs/tutorials/bfgwiki2/src/basiclayout/tutorial/views.py
index 375293b02..f101b2742 100644
--- a/docs/tutorials/bfgwiki2/src/basiclayout/tutorial/views.py
+++ b/docs/tutorials/bfgwiki2/src/basiclayout/tutorial/views.py
@@ -6,7 +6,7 @@ from tutorial.models import Model
static_view = static('templates/static')
-def my_view(context, request):
+def my_view(request):
dbsession = DBSession()
root = dbsession.query(Model).filter(Model.name==u'root').first()
return render_template_to_response('templates/mytemplate.pt',
diff --git a/docs/tutorials/bfgwiki2/src/models/tutorial/views.py b/docs/tutorials/bfgwiki2/src/models/tutorial/views.py
index 375293b02..f101b2742 100644
--- a/docs/tutorials/bfgwiki2/src/models/tutorial/views.py
+++ b/docs/tutorials/bfgwiki2/src/models/tutorial/views.py
@@ -6,7 +6,7 @@ from tutorial.models import Model
static_view = static('templates/static')
-def my_view(context, request):
+def my_view(request):
dbsession = DBSession()
root = dbsession.query(Model).filter(Model.name==u'root').first()
return render_template_to_response('templates/mytemplate.pt',