summaryrefslogtreecommitdiff
path: root/docs/tutorials/wiki/definingviews.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/tutorials/wiki/definingviews.rst')
-rw-r--r--docs/tutorials/wiki/definingviews.rst51
1 files changed, 24 insertions, 27 deletions
diff --git a/docs/tutorials/wiki/definingviews.rst b/docs/tutorials/wiki/definingviews.rst
index ac94d8059..442d5ed18 100644
--- a/docs/tutorials/wiki/definingviews.rst
+++ b/docs/tutorials/wiki/definingviews.rst
@@ -4,7 +4,7 @@
Defining Views
==============
-A :term:`view callable` in a :term:`traversal` -based :app:`Pyramid`
+A :term:`view callable` in a :term:`traversal`-based :app:`Pyramid`
application is typically a simple Python function that accepts two
parameters: :term:`context` and :term:`request`. A view callable is
assumed to return a :term:`response` object.
@@ -16,7 +16,7 @@ assumed to return a :term:`response` object.
this one-argument pattern used in other :app:`Pyramid` tutorials
and applications. Either calling convention will work in any
:app:`Pyramid` application; the calling conventions can be used
- interchangeably as necessary. In :term:`traversal` based applications,
+ interchangeably as necessary. In :term:`traversal`-based applications,
URLs are mapped to a context :term:`resource`, and since our
:term:`resource tree` also represents our application's
"domain model", we're often interested in the context because
@@ -36,7 +36,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
+application was generated by the cookiecutter; it doesn't know
about our custom application requirements.
We need to add a dependency on the ``docutils`` package to our ``tutorial``
@@ -52,6 +52,7 @@ Open ``setup.py`` and edit it to look like the following:
Only the highlighted line needs to be added.
+.. _wiki-running-pip-install:
Running ``pip install -e .``
============================
@@ -74,15 +75,15 @@ On Windows:
.. code-block:: doscon
- c:\pyramidtut> cd tutorial
- c:\pyramidtut\tutorial> %VENV%\Scripts\pip install -e .
+ c:\> cd tutorial
+ c:\tutorial> %VENV%\Scripts\pip install -e .
Success executing this command will end with a line to the console something
like:
.. code-block:: text
- Successfully installed docutils-0.12 tutorial-0.0
+ Successfully installed docutils-0.13.1 tutorial
Adding view functions in ``views.py``
@@ -98,11 +99,11 @@ like the following:
We added some imports and created a regular expression to find "WikiWords".
We got rid of the ``my_view`` view function and its decorator that was added
-when we originally rendered the ``zodb`` scaffold. It was only an example and
+when we originally rendered the ``zodb`` cookiecutter. It was only an example and
isn't relevant to our application.
Then we added four :term:`view callable` functions to our ``views.py``
-module:
+module:
* ``view_wiki()`` - Displays the wiki itself. It will answer on the root URL.
* ``view_page()`` - Displays an individual page.
@@ -126,8 +127,7 @@ Following is the code for the ``view_wiki`` view function and its decorator:
.. literalinclude:: src/views/tutorial/views.py
:lines: 12-14
- :lineno-start: 12
- :linenos:
+ :lineno-match:
:language: python
.. note:: In our code, we use an *import* that is *relative* to our package
@@ -165,8 +165,7 @@ Here is the code for the ``view_page`` view function and its decorator:
.. literalinclude:: src/views/tutorial/views.py
:lines: 16-33
- :lineno-start: 16
- :linenos:
+ :lineno-match:
:language: python
The ``view_page`` function is configured to respond as the default view
@@ -219,8 +218,7 @@ Here is the code for the ``add_page`` view function and its decorator:
.. literalinclude:: src/views/tutorial/views.py
:lines: 35-50
- :lineno-start: 35
- :linenos:
+ :lineno-match:
:language: python
The ``add_page`` function is configured to respond when the context resource
@@ -247,7 +245,7 @@ are found *after* the :term:`view name` in the URL segments given in the
add view is invoked via, e.g., ``http://localhost:6543/add_page/SomeName``,
the :term:`subpath` will be a tuple: ``('SomeName',)``.
-The add view takes the zeroth element of the subpath (the wiki page name),
+The add view takes the zero\ :sup:`th` element of the subpath (the wiki page name),
and aliases it to the name attribute in order to know the name of the page
we're trying to add.
@@ -274,8 +272,7 @@ Here is the code for the ``edit_page`` view function and its decorator:
.. literalinclude:: src/views/tutorial/views.py
:lines: 52-60
- :lineno-start: 52
- :linenos:
+ :lineno-match:
:language: python
The ``edit_page`` function is configured to respond when the context is
@@ -316,26 +313,26 @@ extension to be recognized as such.
The ``view.pt`` template
------------------------
-Create ``tutorial/templates/view.pt`` and add the following
-content:
+Rename ``tutorial/templates/mytemplate.pt`` to ``tutorial/templates/view.pt`` and edit the emphasized lines to look like the following:
.. literalinclude:: src/views/tutorial/templates/view.pt
:linenos:
:language: html
+ :emphasize-lines: 11-12,37-52
This template is used by ``view_page()`` for displaying a single
wiki page. It includes:
- A ``div`` element that is replaced with the ``content`` value provided by
- the view (lines 36-38). ``content`` contains HTML, so the ``structure``
+ the view (lines 37-39). ``content`` contains HTML, so the ``structure``
keyword is used to prevent escaping it (i.e., changing ">" to ">", etc.)
- A link that points at the "edit" URL which invokes the ``edit_page`` view
- for the page being viewed (lines 40-42).
+ for the page being viewed (lines 41-43).
The ``edit.pt`` template
------------------------
-Create ``tutorial/templates/edit.pt`` and add the following content:
+Copy ``tutorial/templates/view.pt`` to ``tutorial/templates/edit.pt`` and edit the emphasized lines to look like the following:
.. literalinclude:: src/views/tutorial/templates/edit.pt
:linenos:
@@ -344,12 +341,12 @@ Create ``tutorial/templates/edit.pt`` and add the following content:
This template is used by ``add_page()`` and ``edit_page()`` for adding and
editing a wiki page. It displays a page containing a form that includes:
-- A 10 row by 60 column ``textarea`` field named ``body`` that is filled
- with any existing page data when it is rendered (line 45).
-- A submit button that has the name ``form.submitted`` (line 48).
+- A 10-row by 60-column ``textarea`` field named ``body`` that is filled
+ with any existing page data when it is rendered (line 46).
+- A submit button that has the name ``form.submitted`` (line 49).
The form POSTs back to the ``save_url`` argument supplied by the view (line
-43). The view will use the ``body`` and ``form.submitted`` values.
+44). The view will use the ``body`` and ``form.submitted`` values.
.. note:: Our templates use a ``request`` object that none of our tutorial
views return in their dictionary. ``request`` is one of several names that
@@ -394,5 +391,5 @@ each of the following URLs, checking that the result is as expected:
- http://localhost:6543/add_page/SomePageName invokes the add view for a Page.
- To generate an error, visit http://localhost:6543/add_page which will
- generate an ``IndexErrorr: tuple index out of range`` error. You'll see an
+ generate an ``IndexError: tuple index out of range`` error. You'll see an
interactive traceback facility provided by :term:`pyramid_debugtoolbar`.