From 8d88c0ffa7b8e08215c7a06e130c84b2963f3279 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Mon, 25 May 2015 02:48:32 -0700 Subject: update templates, line numbers, file references --- docs/tutorials/wiki2/authorization.rst | 138 +++++++++++---------- .../src/authorization/tutorial/templates/edit.pt | 8 +- .../src/authorization/tutorial/templates/login.pt | 122 ++++++++++-------- .../src/authorization/tutorial/templates/view.pt | 8 +- docs/tutorials/wiki2/tests.rst | 4 +- 5 files changed, 150 insertions(+), 130 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index 90a89d63e..1f7af5654 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -80,15 +80,16 @@ statement at the head: :linenos: :language: python -Add the following class definition: +Add the following class definition at the end: .. literalinclude:: src/authorization/tutorial/models.py :lines: 33-37 :linenos: + :lineno-start: 33 :language: python We import :data:`~pyramid.security.Allow`, an action that -means that permission is allowed:, and +means that permission is allowed, and :data:`~pyramid.security.Everyone`, a special :term:`principal` that is associated to all requests. Both are used in the :term:`ACE` entries that make up the ACL. @@ -112,9 +113,10 @@ the class we created above: :lines: 24-25 :linenos: :emphasize-lines: 2 + :lineno-start: 16 :language: python -(Only the highlighted line needs to be added.) +Only the highlighted line needs to be added. We are now providing the ACL to the application. See :ref:`assigning_acls` for more information about what an @@ -130,12 +132,13 @@ We are now providing the ACL to the application. See Add Authentication and Authorization Policies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Open ``tutorial/__init__.py`` and -add these import statements: +Open ``tutorial/tutorial/__init__.py`` and add the highlighted import +statements: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 2-3,7 + :lines: 1-7 :linenos: + :emphasize-lines: 2-3,7 :language: python Now add those policies to the configuration: @@ -143,10 +146,11 @@ Now add those policies to the configuration: .. literalinclude:: src/authorization/tutorial/__init__.py :lines: 21-27 :linenos: + :lineno-start: 21 :emphasize-lines: 1-3,6-7 :language: python -(Only the highlighted lines need to be added.) +Only the highlighted lines need to be added. We are enabling an ``AuthTktAuthenticationPolicy``, which is based in an auth ticket that may be included in the request. @@ -161,33 +165,38 @@ machinery represented by this policy: it is required. The ``callback`` is the Add permission declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Open ``tutorial/tutorial/views.py`` and add a ``permission='edit'`` parameter +to the ``@view_config`` decorators for ``add_page()`` and ``edit_page()``: -Add a ``permission='edit'`` parameter to the ``@view_config`` -decorator for ``add_page()`` and ``edit_page()``, for example: - -.. code-block:: python - :linenos: - :emphasize-lines: 2 +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 60-61 + :emphasize-lines: 1-2 + :language: python - @view_config(route_name='add_page', renderer='templates/edit.pt', - permission='edit') +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 75-76 + :emphasize-lines: 1-2 + :language: python -(Only the highlighted line needs to be added.) +Only the highlighted lines need to be added or edited. The result is that only users who possess the ``edit`` permission at the time of the request may invoke those two views. Add a ``permission='view'`` parameter to the ``@view_config`` -decorator for ``view_wiki()`` and ``view_page()``, like this: +decorator for ``view_wiki()`` and ``view_page()`` as follows: -.. code-block:: python - :linenos: - :emphasize-lines: 2 +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 30-31 + :emphasize-lines: 1-2 + :language: python - @view_config(route_name='view_page', renderer='templates/view.pt', - permission='view') +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 36-37 + :emphasize-lines: 1-2 + :language: python -(Only the highlighted line needs to be added.) +Only the highlighted lines need to be added or edited. This allows anyone to invoke these two views. @@ -200,11 +209,11 @@ Login, Logout Add routes for /login and /logout ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Go back to ``tutorial/tutorial/__init__.py`` and add these two -routes: +routes as highlighted: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 31-32 - :linenos: + :lines: 30-33 + :emphasize-lines: 2-3 :language: python .. note:: The preceding lines must be added *before* the following @@ -212,7 +221,6 @@ routes: .. literalinclude:: src/authorization/tutorial/__init__.py :lines: 33 - :linenos: :language: python This is because ``view_page``'s route definition uses a catch-all @@ -237,11 +245,10 @@ head of ``tutorial/tutorial/views.py``: .. literalinclude:: src/authorization/tutorial/views.py :lines: 9-19 - :linenos: - :emphasize-lines: 3,6-9,11 + :emphasize-lines: 1-11 :language: python -(Only the highlighted lines need to be added.) +All the highlighted lines need to be added or edited. :meth:`~pyramid.view.forbidden_view_config` will be used to customize the default 403 Forbidden page. @@ -249,11 +256,10 @@ to customize the default 403 Forbidden page. :meth:`~pyramid.security.forget` help to create and expire an auth ticket cookie. -Now add the ``login`` and ``logout`` views: +Now add the ``login`` and ``logout`` views at the end of the file: .. literalinclude:: src/authorization/tutorial/views.py :lines: 91-123 - :linenos: :language: python ``login()`` is decorated with two decorators: @@ -286,23 +292,28 @@ content: The above template is referred to within the login view we just added to ``views.py``. -Return a logged_in flag to the renderer -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Return a ``logged_in`` flag to the renderer +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Add a ``logged_in`` parameter to the return value of -``view_page()``, ``edit_page()`` and ``add_page()``, -like this: +Add a ``logged_in`` parameter to the return value of +``view_page()``, ``edit_page()``, and ``add_page()`` as follows: -.. code-block:: python - :linenos: - :emphasize-lines: 4 +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 57-58 + :emphasize-lines: 1-2 + :language: python + +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 72-73 + :emphasize-lines: 1-2 + :language: python - return dict(page = page, - content = content, - edit_url = edit_url, - logged_in = request.authenticated_userid) +.. literalinclude:: src/authorization/tutorial/views.py + :lines: 85-89 + :emphasize-lines: 3-4 + :language: python -(Only the highlighted line needs to be added.) +Only the highlighted lines need to be added or edited. The :meth:`~pyramid.request.Request.authenticated_userid` property will be ``None`` if the user is not authenticated. @@ -311,22 +322,21 @@ Add a "Logout" link when logged in ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Open ``tutorial/tutorial/templates/edit.pt`` and -``tutorial/tutorial/templates/view.pt`` and add this within the -``
+

+ Logout +

Editing Page Name Goes Here @@ -40,11 +43,6 @@

You can return to the FrontPage.

-

- - Logout - -

diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/templates/login.pt b/docs/tutorials/wiki2/src/authorization/tutorial/templates/login.pt index 64e592ea9..331d52d2a 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/templates/login.pt +++ b/docs/tutorials/wiki2/src/authorization/tutorial/templates/login.pt @@ -1,58 +1,74 @@ - - - - Login - Pyramid tutorial wiki (based on TurboGears - 20-Minute Wiki) - - - - - - - - -
-
-
-
- pyramid + + + + + + + + + + + Login - Pyramid tutorial wiki (based on + TurboGears 20-Minute Wiki) + + + + + + + + + + + + +
+
+
+
+ +
+
+
+

+ + Login + + +

+ + +
+ + +
+
+ + +
+
+ +
+ +
+
-
-
-
-
-
- Login
- +
+
- -
-
-
-
-
- -
-
- -
-
- - + + + + + + + diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/templates/view.pt b/docs/tutorials/wiki2/src/authorization/tutorial/templates/view.pt index 4e5772de0..02cb8e73b 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/templates/view.pt +++ b/docs/tutorials/wiki2/src/authorization/tutorial/templates/view.pt @@ -33,6 +33,9 @@
+

+ Logout +

Page text goes here.
@@ -48,11 +51,6 @@

You can return to the FrontPage.

-

- - Logout - -

diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index 9aca0c5b7..c171a0e6e 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -6,8 +6,6 @@ We will now add tests for the models and the views and a few functional tests in the ``tests.py``. Tests ensure that an application works, and that it continues to work after changes are made in the future. - - Testing the Models ================== @@ -37,7 +35,7 @@ can, and so on. Viewing the results of all our edits to ``tests.py`` ==================================================== -Once we're done with the ``tests.py`` module, it will look a lot like: +Open the ``tutorial/tests.py`` module, and edit it as follows: .. literalinclude:: src/tests/tutorial/tests.py :linenos: -- cgit v1.2.3