diff options
| author | Chris McDonough <chrism@plope.com> | 2013-02-09 19:15:07 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-02-09 19:15:07 -0500 |
| commit | acf115391088770ae434d222179fd22a693bfe46 (patch) | |
| tree | 442d33920cd6d20ccb7ce3cff3344fd851448d0d /docs/tutorials/wiki2/definingviews.rst | |
| parent | 6313e0dd97e22b8c897293cd8d5f2f145637f49f (diff) | |
| parent | 7fe736bf57696aa62c8b0d84e62ad486d0f88f40 (diff) | |
| download | pyramid-acf115391088770ae434d222179fd22a693bfe46.tar.gz pyramid-acf115391088770ae434d222179fd22a693bfe46.tar.bz2 pyramid-acf115391088770ae434d222179fd22a693bfe46.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/tutorials/wiki2/definingviews.rst')
| -rw-r--r-- | docs/tutorials/wiki2/definingviews.rst | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index a54996e3c..e83a88198 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -16,9 +16,6 @@ instance, if a call to :meth:`pyramid.config.Configurator.add_route` in have a ``'one'`` key with the value ``'foo'`` and a ``'two'`` key with the value ``'bar'``. -The source code for this tutorial stage can be browsed at -`http://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src/views/ -<http://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src/views/>`_. Declaring Dependencies in Our ``setup.py`` File =============================================== @@ -26,7 +23,7 @@ Declaring Dependencies in Our ``setup.py`` File The view code in our application will depend on a package which is not a dependency of the original "tutorial" application. The original "tutorial" application was generated by the ``pcreate`` command; it doesn't know -about our custom application requirements. +about our custom application requirements. We need to add a dependency on the ``docutils`` package to our ``tutorial`` package's ``setup.py`` file by assigning this dependency to the ``requires`` parameter in ``setup()``. @@ -123,14 +120,14 @@ the :class:`pyramid.interfaces.IResponse` interface like It uses the :meth:`pyramid.request.Request.route_url` API to construct a URL to the ``FrontPage`` page (e.g. ``http://localhost:6543/FrontPage``), which -is used as the "location" of the HTTPFound response, forming an HTTP redirect. +is used as the "location" of the ``HTTPFound`` response, forming an HTTP redirect. The ``view_page`` view function ------------------------------- ``view_page()`` is used to display a single page of our wiki. It renders the :term:`ReStructuredText` body of a page (stored as -the ``data`` attribute of a Page object) as HTML. Then it substitutes an +the ``data`` attribute of a ``Page`` model object) as HTML. Then it substitutes an HTML anchor for each *WikiWord* reference in the rendered HTML using a compiled regular expression. @@ -139,12 +136,12 @@ compiled regular expression. :linenos: :language: python -The curried ``check()`` function is used as the first argument to +The ``check()`` function is used as the first argument to ``wikiwords.sub``, indicating that it should be called to provide a value for each WikiWord match found in the content. If the wiki already contains a page with the matched WikiWord name, ``check()`` generates a view link to be used as the substitution value and returns it. If the wiki does -not already contain a page with with the matched WikiWord name, ``check()`` +not already contain a page with the matched WikiWord name, ``check()`` generates an "add" link as the substitution value and returns it. As a result, the ``content`` variable is now a fully formed bit of HTML @@ -181,6 +178,13 @@ the page we'd like to add. If our add view is invoked via, e.g. ``http://localhost:6543/add_page/SomeName``, the value for ``'pagename'`` in the ``matchdict`` will be ``'SomeName'``. +If the view execution *is* a result of a form submission (i.e. the expression +``'form.submitted' in request.params`` is ``True``), we scrape the page body +from the form data, create a Page object with this page body and the name +taken from ``matchdict['pagename']``, and save it into the database using +``DBSession.add``. We then redirect back to the ``view_page`` view for the +newly created page. + If the view execution is *not* a result of a form submission (i.e. the expression ``'form.submitted' in request.params`` is ``False``), the view callable renders a template. To do so, it generates a "save url" which the @@ -191,13 +195,6 @@ in order to satisfy the edit form's desire to have *some* page object exposed as ``page``. :app:`Pyramid` will render the template associated with this view to a response. -If the view execution *is* a result of a form submission (i.e. the expression -``'form.submitted' in request.params`` is ``True``), we scrape the page body -from the form data, create a Page object with this page body and the name -taken from ``matchdict['pagename']``, and save it into the database using -``DBSession.add``. We then redirect back to the ``view_page`` view for the -newly created page. - The ``edit_page`` view function ------------------------------- @@ -212,17 +209,17 @@ matching the name of the page the user wants to edit. :linenos: :language: python -If the view execution is *not* a result of a form submission (i.e. the -expression ``'form.submitted' in request.params`` is ``False``), the view -simply renders the edit form, passing the page object and a ``save_url`` -which will be used as the action of the generated form. - If the view execution *is* a result of a form submission (i.e. the expression ``'form.submitted' in request.params`` is ``True``), the view grabs the ``body`` element of the request parameters and sets it as the ``data`` attribute of the page object. It then redirects to the ``view_page`` view of the wiki page. +If the view execution is *not* a result of a form submission (i.e. the +expression ``'form.submitted' in request.params`` is ``False``), the view +simply renders the edit form, passing the page object and a ``save_url`` +which will be used as the action of the generated form. + Adding Templates ================ @@ -342,7 +339,7 @@ something like: .. literalinclude:: src/views/tutorial/__init__.py :linenos: :language: python - :emphasize-lines: 17-20 + :emphasize-lines: 18-21 (The highlighted lines are the ones that need to be added or edited.) @@ -358,7 +355,7 @@ each of the following URLs, check that the result is as expected: of the FrontPage page object. - ``http://localhost:6543/FrontPage`` in a browser invokes - the ``view_page`` view of the front page page object. + the ``view_page`` view of the front page object. - ``http://localhost:6543/FrontPage/edit_page`` in a browser invokes the edit view for the front page object. @@ -366,7 +363,7 @@ each of the following URLs, check that the result is as expected: - ``http://localhost:6543/add_page/SomePageName`` in a browser invokes the add view for a page. -- To generate an error, visit ``http://localhost:6543/add_page`` which +- To generate an error, visit ``http://localhost:6543/foobars/edit_page`` which will generate a ``NoResultFound: No row was found for one()`` error. You'll see an interactive traceback facility provided by :term:`pyramid_debugtoolbar`. |
