From b1b92284f496800a4dfd2cea72cb9be07ba8661c Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 16:52:14 -0400 Subject: First cut at import of quick tutorial. --- docs/quick_tutorial/view_classes.rst | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 docs/quick_tutorial/view_classes.rst (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst new file mode 100644 index 000000000..0c8976b7f --- /dev/null +++ b/docs/quick_tutorial/view_classes.rst @@ -0,0 +1,96 @@ +====================================== +09: Organizing Views With View Classes +====================================== + +Change our view functions to be methods on a view class, +then move some declarations to the class level. + +Background +========== + +So far our views have been simple, free-standing functions. Many times +your views are related: different ways to look at or work on the same +data or a REST API that handles multiple operations. Grouping these +together as a +:ref:`view class ` makes sense: + +- Group views + +- Centralize some repetitive defaults + +- Share some state and helpers + +In this step we just do the absolute minimum to convert the existing +views to a view class. In a later tutorial step we'll examine view +classes in depth. + +Objectives +========== + +- Group related views into a view class + +- Centralize configuration with class-level ``@view_defaults`` + +Steps +===== + + +#. First we copy the results of the previous step: + + .. code-block:: bash + + (env27)$ cd ..; cp -r templating view_classes; cd view_classes + (env27)$ python setup.py develop + +#. Our ``view_classes/tutorial/views.py`` now has a view class with + our two views: + + .. literalinclude:: view_classes/tutorial/views.py + :linenos: + +#. Our unit tests in ``view_classes/tutorial/tests.py`` don't run, + so let's modify the to import the view class and make an instance + before getting a response: + + .. literalinclude:: view_classes/tutorial/tests.py + :linenos: + +#. Now run the tests: + + .. code-block:: bash + + + (env27)$ nosetests tutorial + . + ---------------------------------------------------------------------- + Ran 4 tests in 0.141s + + OK + +#. Run your Pyramid application with: + + .. code-block:: bash + + (env27)$ pserve development.ini --reload + +#. Open ``http://localhost:6543/`` and ``http://localhost:6543/howdy`` + in your browser. + +Analysis +======== + +To ease the transition to view classes, we didn't introduce any new +functionality. We simply changed the view functions to methods on a +view class, then updated the tests. + +In our ``TutorialViews`` view class you can see that our two view +classes are logically grouped together as methods on a common class. +Since the two views shared the same template, we could move that to a +``@view_defaults`` decorator on at the class level. + +The tests needed to change. Obviously we needed to import the view +class. But you can also see the pattern in the tests of instantiating +the view class with the dummy request first, then calling the view +method being tested. + +.. seealso:: :ref:`pyramid:class_as_view` -- cgit v1.2.3 From 4042c772c8043ac96a22db439a736fec9ea2aafa Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 17:09:35 -0400 Subject: All the references re-wired. --- docs/quick_tutorial/view_classes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 0c8976b7f..e06e7f6c0 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -12,7 +12,7 @@ So far our views have been simple, free-standing functions. Many times your views are related: different ways to look at or work on the same data or a REST API that handles multiple operations. Grouping these together as a -:ref:`view class ` makes sense: +:ref:`view class ` makes sense: - Group views @@ -93,4 +93,4 @@ class. But you can also see the pattern in the tests of instantiating the view class with the dummy request first, then calling the view method being tested. -.. seealso:: :ref:`pyramid:class_as_view` +.. seealso:: :ref:`class_as_view` -- cgit v1.2.3 From 0a784868bdbc3a0eb226ed00e8d89cda9d181ec5 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 17:11:42 -0400 Subject: Fix naming of virtualenv prefix. --- docs/quick_tutorial/view_classes.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index e06e7f6c0..02d8a04fd 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -39,8 +39,8 @@ Steps .. code-block:: bash - (env27)$ cd ..; cp -r templating view_classes; cd view_classes - (env27)$ python setup.py develop + (env)$ cd ..; cp -r templating view_classes; cd view_classes + (env)$ python setup.py develop #. Our ``view_classes/tutorial/views.py`` now has a view class with our two views: @@ -60,7 +60,7 @@ Steps .. code-block:: bash - (env27)$ nosetests tutorial + (env)$ nosetests tutorial . ---------------------------------------------------------------------- Ran 4 tests in 0.141s @@ -71,7 +71,7 @@ Steps .. code-block:: bash - (env27)$ pserve development.ini --reload + (env)$ pserve development.ini --reload #. Open ``http://localhost:6543/`` and ``http://localhost:6543/howdy`` in your browser. -- cgit v1.2.3 From b0b28ede912c817a62a84b97c332e39eda02d166 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:14:53 +0200 Subject: s/env/venv just for sake of consistency --- docs/quick_tutorial/view_classes.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 02d8a04fd..01efa58a6 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -39,8 +39,8 @@ Steps .. code-block:: bash - (env)$ cd ..; cp -r templating view_classes; cd view_classes - (env)$ python setup.py develop + (venv)$ cd ..; cp -r templating view_classes; cd view_classes + (venv)$ python setup.py develop #. Our ``view_classes/tutorial/views.py`` now has a view class with our two views: @@ -60,7 +60,7 @@ Steps .. code-block:: bash - (env)$ nosetests tutorial + (venv)$ nosetests tutorial . ---------------------------------------------------------------------- Ran 4 tests in 0.141s @@ -71,7 +71,7 @@ Steps .. code-block:: bash - (env)$ pserve development.ini --reload + (venv)$ pserve development.ini --reload #. Open ``http://localhost:6543/`` and ``http://localhost:6543/howdy`` in your browser. -- cgit v1.2.3 From d749bf4c987c4ab90bd5f89326e7d4059e4f47b3 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:18:11 +0200 Subject: make example links clickable, for convenience --- docs/quick_tutorial/view_classes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 01efa58a6..22f2b2430 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -73,7 +73,7 @@ Steps (venv)$ pserve development.ini --reload -#. Open ``http://localhost:6543/`` and ``http://localhost:6543/howdy`` +#. Open http://localhost:6543/ and http://localhost:6543/howdy in your browser. Analysis -- cgit v1.2.3 From 187104fd81418beeb51592913041d9751bafe08d Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Wed, 25 Sep 2013 09:27:43 -0400 Subject: Quick Tutorial: Improve the setup instructions (adapted from Steve Piercy's work), particularly for Windows. Change all the steps to use $VENV/bin prefixes on commands (don't presume that they have done source env/bin/activate). --- docs/quick_tutorial/view_classes.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 22f2b2430..b55abf218 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -39,8 +39,8 @@ Steps .. code-block:: bash - (venv)$ cd ..; cp -r templating view_classes; cd view_classes - (venv)$ python setup.py develop + $ cd ..; cp -r templating view_classes; cd view_classes + $ $VENV/bin/python setup.py develop #. Our ``view_classes/tutorial/views.py`` now has a view class with our two views: @@ -60,7 +60,7 @@ Steps .. code-block:: bash - (venv)$ nosetests tutorial + $ $VENV/bin/nosetests tutorial . ---------------------------------------------------------------------- Ran 4 tests in 0.141s @@ -71,7 +71,7 @@ Steps .. code-block:: bash - (venv)$ pserve development.ini --reload + $ $VENV/bin/pserve development.ini --reload #. Open http://localhost:6543/ and http://localhost:6543/howdy in your browser. -- cgit v1.2.3 From b731b5fca253d9d95b3307490aa585e194676c01 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Thu, 26 Sep 2013 17:41:44 -0400 Subject: Quick Tour: shorten the setup part and point to Quick Tutorial Requirements for more explanation. Cross link each Quick Tour section with its Quick Tutorial match. --- docs/quick_tutorial/view_classes.rst | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index b55abf218..58ab43e40 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -1,3 +1,5 @@ +.. _qtut_view_classes: + ====================================== 09: Organizing Views With View Classes ====================================== -- cgit v1.2.3 From 511dc7b09996d91b8158b70607107d109b1015b6 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 21 May 2015 01:02:12 -0700 Subject: grammar fixes --- docs/quick_tutorial/view_classes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 58ab43e40..50a7ee0af 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -51,7 +51,7 @@ Steps :linenos: #. Our unit tests in ``view_classes/tutorial/tests.py`` don't run, - so let's modify the to import the view class and make an instance + so let's modify them to import the view class and make an instance before getting a response: .. literalinclude:: view_classes/tutorial/tests.py @@ -88,7 +88,7 @@ view class, then updated the tests. In our ``TutorialViews`` view class you can see that our two view classes are logically grouped together as methods on a common class. Since the two views shared the same template, we could move that to a -``@view_defaults`` decorator on at the class level. +``@view_defaults`` decorator at the class level. The tests needed to change. Obviously we needed to import the view class. But you can also see the pattern in the tests of instantiating -- cgit v1.2.3 From 51f056043f9286734e93cb61f44bb0163c5b1fa3 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 2 Mar 2016 03:47:56 -0800 Subject: give sentence a colostomy, break into two --- docs/quick_tutorial/view_classes.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 50a7ee0af..6198eed63 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -10,11 +10,10 @@ then move some declarations to the class level. Background ========== -So far our views have been simple, free-standing functions. Many times -your views are related: different ways to look at or work on the same -data or a REST API that handles multiple operations. Grouping these -together as a -:ref:`view class ` makes sense: +So far our views have been simple, free-standing functions. Many times your +views are related to one another. They may be different ways to look at or work +on the same data, or be a REST API that handles multiple operations. Grouping +these views together as a :ref:`view class ` makes sense: - Group views -- cgit v1.2.3 From fd965fe8bfb62a467521e3883237b0506296b7b4 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 7 Apr 2016 03:21:14 -0700 Subject: - update view_classes.rst --- docs/quick_tutorial/view_classes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index 6198eed63..cc5337493 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -41,7 +41,7 @@ Steps .. code-block:: bash $ cd ..; cp -r templating view_classes; cd view_classes - $ $VENV/bin/python setup.py develop + $ $VENV/bin/pip install -e . #. Our ``view_classes/tutorial/views.py`` now has a view class with our two views: -- cgit v1.2.3 From 842a4fa23a8948a31023af0983c874ef45cb1041 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Sat, 16 Apr 2016 05:09:14 -0700 Subject: quick_tutorial cleanup - replace nose with pytest - cleanup view_classes.rst --- docs/quick_tutorial/view_classes.rst | 69 +++++++++++++++++------------------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'docs/quick_tutorial/view_classes.rst') diff --git a/docs/quick_tutorial/view_classes.rst b/docs/quick_tutorial/view_classes.rst index cc5337493..05d97a9b1 100644 --- a/docs/quick_tutorial/view_classes.rst +++ b/docs/quick_tutorial/view_classes.rst @@ -4,8 +4,9 @@ 09: Organizing Views With View Classes ====================================== -Change our view functions to be methods on a view class, -then move some declarations to the class level. +Change our view functions to be methods on a view class, then move some +declarations to the class level. + Background ========== @@ -15,27 +16,27 @@ views are related to one another. They may be different ways to look at or work on the same data, or be a REST API that handles multiple operations. Grouping these views together as a :ref:`view class ` makes sense: -- Group views +- Group views. + +- Centralize some repetitive defaults. -- Centralize some repetitive defaults +- Share some state and helpers. -- Share some state and helpers +In this step we just do the absolute minimum to convert the existing views to a +view class. In a later tutorial step, we'll examine view classes in depth. -In this step we just do the absolute minimum to convert the existing -views to a view class. In a later tutorial step we'll examine view -classes in depth. Objectives ========== -- Group related views into a view class +- Group related views into a view class. + +- Centralize configuration with class-level ``@view_defaults``. -- Centralize configuration with class-level ``@view_defaults`` Steps ===== - #. First we copy the results of the previous step: .. code-block:: bash @@ -43,15 +44,15 @@ Steps $ cd ..; cp -r templating view_classes; cd view_classes $ $VENV/bin/pip install -e . -#. Our ``view_classes/tutorial/views.py`` now has a view class with - our two views: +#. Our ``view_classes/tutorial/views.py`` now has a view class with our two + views: .. literalinclude:: view_classes/tutorial/views.py :linenos: -#. Our unit tests in ``view_classes/tutorial/tests.py`` don't run, - so let's modify them to import the view class and make an instance - before getting a response: +#. Our unit tests in ``view_classes/tutorial/tests.py`` don't run, so let's + modify them to import the view class, and make an instance before getting a + response: .. literalinclude:: view_classes/tutorial/tests.py :linenos: @@ -61,12 +62,9 @@ Steps .. code-block:: bash - $ $VENV/bin/nosetests tutorial - . - ---------------------------------------------------------------------- - Ran 4 tests in 0.141s - - OK + $ $VENV/bin/py.test tutorial/tests.py -q + .... + 4 passed in 0.34 seconds #. Run your Pyramid application with: @@ -74,24 +72,23 @@ Steps $ $VENV/bin/pserve development.ini --reload -#. Open http://localhost:6543/ and http://localhost:6543/howdy - in your browser. +#. Open http://localhost:6543/ and http://localhost:6543/howdy in your browser. + Analysis ======== To ease the transition to view classes, we didn't introduce any new -functionality. We simply changed the view functions to methods on a -view class, then updated the tests. - -In our ``TutorialViews`` view class you can see that our two view -classes are logically grouped together as methods on a common class. -Since the two views shared the same template, we could move that to a -``@view_defaults`` decorator at the class level. - -The tests needed to change. Obviously we needed to import the view -class. But you can also see the pattern in the tests of instantiating -the view class with the dummy request first, then calling the view -method being tested. +functionality. We simply changed the view functions to methods on a view class, +then updated the tests. + +In our ``TutorialViews`` view class, you can see that our two view classes are +logically grouped together as methods on a common class. Since the two views +shared the same template, we could move that to a ``@view_defaults`` decorator +at the class level. + +The tests needed to change. Obviously we needed to import the view class. But +you can also see the pattern in the tests of instantiating the view class with +the dummy request first, then calling the view method being tested. .. seealso:: :ref:`class_as_view` -- cgit v1.2.3