diff options
Diffstat (limited to 'docs/tutorials')
55 files changed, 190 insertions, 159 deletions
diff --git a/docs/tutorials/wiki/authorization.rst b/docs/tutorials/wiki/authorization.rst index 24249945a..e90dfe12d 100644 --- a/docs/tutorials/wiki/authorization.rst +++ b/docs/tutorials/wiki/authorization.rst @@ -127,7 +127,7 @@ add these import statements: Now add those policies to the configuration: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 17-22 + :lines: 18-23 :linenos: :emphasize-lines: 1-3,5-6 :language: python @@ -213,7 +213,7 @@ expire an auth ticket cookie. Now add the ``login`` and ``logout`` views: .. literalinclude:: src/authorization/tutorial/views.py - :lines: 87-120 + :lines: 82-120 :linenos: :language: python @@ -306,7 +306,7 @@ when we're done: .. literalinclude:: src/authorization/tutorial/__init__.py :linenos: - :emphasize-lines: 4-5,8,17-19,21-22 + :emphasize-lines: 4-5,8,18-20,22-23 :language: python (Only the highlighted lines need to be added.) diff --git a/docs/tutorials/wiki/basiclayout.rst b/docs/tutorials/wiki/basiclayout.rst index 033dcb28c..12cf86a91 100644 --- a/docs/tutorials/wiki/basiclayout.rst +++ b/docs/tutorials/wiki/basiclayout.rst @@ -31,13 +31,13 @@ point happens to be the ``main`` function within the file named #. *Lines 1-3*. Perform some dependency imports. -#. *Lines 5-7* Define a root factory for our Pyramid application. +#. *Lines 6-8* Define a root factory for our Pyramid application. -#. *Line 12*. We construct a :term:`Configurator` with a :term:`root +#. *Line 14*. We construct a :term:`Configurator` with a :term:`root factory` and the settings keywords parsed by :term:`PasteDeploy`. The root factory is named ``root_factory``. -#. *Line 13*. Register a 'static view' which answers requests which start +#. *Line 15*. Register a 'static view' which answers requests which start with with URL path ``/static`` using the :meth:`pyramid.config.Configurator.add_static_view method`. This statement registers a view that will serve up static assets, such as CSS @@ -50,7 +50,7 @@ point happens to be the ``main`` function within the file named package. The scaffold could have alternately used an *absolute* asset specification as the path (``tutorial:static``) but it does not. -#. *Line 14*. Perform a :term:`scan`. A scan will find :term:`configuration +#. *Line 16*. Perform a :term:`scan`. A scan will find :term:`configuration decoration`, such as view configuration decorators (e.g. ``@view_config``) in the source code of the ``tutorial`` package and will take actions based on these decorators. We don't pass any arguments to @@ -59,7 +59,7 @@ point happens to be the ``main`` function within the file named The scaffold could have equivalently said ``config.scan('tutorial')`` but it chose to omit the package name argument. -#. *Line 15*. Use the +#. *Line 17*. Use the :meth:`pyramid.config.Configurator.make_wsgi_app` method to return a :term:`WSGI` application. @@ -81,7 +81,7 @@ Here is the source for ``models.py``: :linenos: :language: py -#. *Lines 3-4*. The ``MyModel`` :term:`resource` class is implemented here. +#. *Lines 4-5*. The ``MyModel`` :term:`resource` class is implemented here. Instances of this class will be capable of being persisted in :term:`ZODB` because the class inherits from the :class:`persistent.mapping.PersistentMapping` class. The ``__parent__`` @@ -89,7 +89,7 @@ Here is the source for ``models.py``: By default, have these as ``None`` indicating that this is the :term:`root` object. -#. *Lines 6-12*. ``appmaker`` is used to return the *application +#. *Lines 8-14*. ``appmaker`` is used to return the *application root* object. It is called on *every request* to the :app:`Pyramid` application. It also performs bootstrapping by *creating* an application root (inside the ZODB root object) if one @@ -118,7 +118,7 @@ Let's try to understand the components in this module: #. *Lines 1-2*. Perform some dependency imports. -#. *Line 4*. Use the :func:`pyramid.view.view_config` :term:`configuration +#. *Line 5*. Use the :func:`pyramid.view.view_config` :term:`configuration decoration` to perform a :term:`view configuration` registration. This view configuration registration will be activated when the application is started. It will be activated by virtue of it being found as the result @@ -148,7 +148,7 @@ Let's try to understand the components in this module: ``my_view`` function which it decorates represents the "default" view callable used when the context is of the type ``MyModel``. -#. *Lines 5-6*. We define a :term:`view callable` named ``my_view``, which +#. *Lines 6-7*. We define a :term:`view callable` named ``my_view``, which we decorated in the step above. This view callable is a *function* we write generated by the ``zodb`` scaffold that is given a ``request`` and which returns a dictionary. The ``mytemplate.pt`` diff --git a/docs/tutorials/wiki/src/authorization/setup.py b/docs/tutorials/wiki/src/authorization/setup.py index 1d2d690fc..3164fd724 100644 --- a/docs/tutorials/wiki/src/authorization/setup.py +++ b/docs/tutorials/wiki/src/authorization/setup.py @@ -20,7 +20,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -34,12 +34,11 @@ setup(name='tutorial', packages=find_packages(), include_package_data=True, zip_safe=False, - install_requires = requires, - tests_require= requires, + install_requires=requires, + tests_require=requires, test_suite="tutorial", - entry_points = """\ + entry_points="""\ [paste.app_factory] main = tutorial:main """, ) - diff --git a/docs/tutorials/wiki/src/authorization/tutorial/__init__.py b/docs/tutorials/wiki/src/authorization/tutorial/__init__.py index b42e01d03..8ea8f8fa3 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/__init__.py @@ -11,8 +11,9 @@ def root_factory(request): conn = get_connection(request) return appmaker(conn.root()) + def main(global_config, **settings): - """ This function returns a WSGI application. + """ This function returns a Pyramid WSGI application. """ authn_policy = AuthTktAuthenticationPolicy( 'sosecret', callback=groupfinder, hashalg='sha512') diff --git a/docs/tutorials/wiki/src/authorization/tutorial/tests.py b/docs/tutorials/wiki/src/authorization/tutorial/tests.py index 77e7cce29..0b9046d47 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/tests.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/tests.py @@ -30,6 +30,7 @@ class WikiModelTests(unittest.TestCase): self.assertEqual(wiki.__name__, None) class AppmakerTests(unittest.TestCase): + def _callFUT(self, zodb_root): from .models import appmaker return appmaker(zodb_root) @@ -63,7 +64,7 @@ class ViewPageTests(unittest.TestCase): info = self._callFUT(context, request) self.assertEqual(info['page'], context) self.assertEqual( - info['content'], + info['content'], '<div class="document">\n' '<p>Hello <a href="http://example.com/add_page/CruelWorld">' 'CruelWorld</a> ' @@ -85,9 +86,9 @@ class AddPageTests(unittest.TestCase): request.subpath = ['AnotherPage'] info = self._callFUT(context, request) self.assertEqual(info['page'].data,'') - self.assertEqual(info['save_url'], - request.resource_url( - context, 'add_page', 'AnotherPage')) + self.assertEqual( + info['save_url'], + request.resource_url(context, 'add_page', 'AnotherPage')) def test_it_submitted(self): context = testing.DummyResource() diff --git a/docs/tutorials/wiki/src/authorization/tutorial/views.py b/docs/tutorials/wiki/src/authorization/tutorial/views.py index 50485d279..77956b1e3 100644 --- a/docs/tutorials/wiki/src/authorization/tutorial/views.py +++ b/docs/tutorials/wiki/src/authorization/tutorial/views.py @@ -64,8 +64,8 @@ def add_page(context, request): page.__name__ = pagename page.__parent__ = context - return dict(page = page, save_url = save_url, - logged_in = authenticated_userid(request)) + return dict(page=page, save_url=save_url, + logged_in=authenticated_userid(request)) @view_config(name='edit_page', context='.models.Page', renderer='templates/edit.pt', @@ -75,9 +75,9 @@ def edit_page(context, request): context.data = request.params['body'] return HTTPFound(location = request.resource_url(context)) - return dict(page = context, - save_url = request.resource_url(context, 'edit_page'), - logged_in = authenticated_userid(request)) + return dict(page=context, + save_url=request.resource_url(context, 'edit_page'), + logged_in=authenticated_userid(request)) @view_config(context='.models.Wiki', name='login', renderer='templates/login.pt') diff --git a/docs/tutorials/wiki/src/basiclayout/setup.py b/docs/tutorials/wiki/src/basiclayout/setup.py index 647c3a638..4998be902 100644 --- a/docs/tutorials/wiki/src/basiclayout/setup.py +++ b/docs/tutorials/wiki/src/basiclayout/setup.py @@ -19,7 +19,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -33,12 +33,11 @@ setup(name='tutorial', packages=find_packages(), include_package_data=True, zip_safe=False, - install_requires = requires, - tests_require= requires, + install_requires=requires, + tests_require=requires, test_suite="tutorial", - entry_points = """\ + entry_points="""\ [paste.app_factory] main = tutorial:main """, ) - diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py b/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py index b63933fc5..c3bb87a62 100644 --- a/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/basiclayout/tutorial/__init__.py @@ -2,10 +2,12 @@ from pyramid.config import Configurator from pyramid_zodbconn import get_connection from .models import appmaker + def root_factory(request): conn = get_connection(request) return appmaker(conn.root()) + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/models.py b/docs/tutorials/wiki/src/basiclayout/tutorial/models.py index 8dd0f5a49..a94b36ef4 100644 --- a/docs/tutorials/wiki/src/basiclayout/tutorial/models.py +++ b/docs/tutorials/wiki/src/basiclayout/tutorial/models.py @@ -1,8 +1,10 @@ from persistent.mapping import PersistentMapping + class MyModel(PersistentMapping): __parent__ = __name__ = None + def appmaker(zodb_root): if not 'app_root' in zodb_root: app_root = MyModel() diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py b/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py index 8d2374be1..7f6523c66 100644 --- a/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py +++ b/docs/tutorials/wiki/src/basiclayout/tutorial/tests.py @@ -14,4 +14,3 @@ class ViewTests(unittest.TestCase): request = testing.DummyRequest() info = my_view(request) self.assertEqual(info['project'], 'tutorial') - diff --git a/docs/tutorials/wiki/src/basiclayout/tutorial/views.py b/docs/tutorials/wiki/src/basiclayout/tutorial/views.py index 4265b6bf7..628ce15ed 100644 --- a/docs/tutorials/wiki/src/basiclayout/tutorial/views.py +++ b/docs/tutorials/wiki/src/basiclayout/tutorial/views.py @@ -1,6 +1,7 @@ from pyramid.view import view_config from .models import MyModel + @view_config(context=MyModel, renderer='templates/mytemplate.pt') def my_view(request): - return {'project':'tutorial'} + return {'project': 'tutorial'} diff --git a/docs/tutorials/wiki/src/models/setup.py b/docs/tutorials/wiki/src/models/setup.py index 647c3a638..4998be902 100644 --- a/docs/tutorials/wiki/src/models/setup.py +++ b/docs/tutorials/wiki/src/models/setup.py @@ -19,7 +19,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -33,12 +33,11 @@ setup(name='tutorial', packages=find_packages(), include_package_data=True, zip_safe=False, - install_requires = requires, - tests_require= requires, + install_requires=requires, + tests_require=requires, test_suite="tutorial", - entry_points = """\ + entry_points="""\ [paste.app_factory] main = tutorial:main """, ) - diff --git a/docs/tutorials/wiki/src/models/tutorial/__init__.py b/docs/tutorials/wiki/src/models/tutorial/__init__.py index c59f36e7b..c3bb87a62 100644 --- a/docs/tutorials/wiki/src/models/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/models/tutorial/__init__.py @@ -2,15 +2,16 @@ from pyramid.config import Configurator from pyramid_zodbconn import get_connection from .models import appmaker + def root_factory(request): conn = get_connection(request) return appmaker(conn.root()) + def main(global_config, **settings): - """ This function returns a WSGI application. + """ This function returns a Pyramid WSGI application. """ config = Configurator(root_factory=root_factory, settings=settings) config.add_static_view('static', 'static', cache_max_age=3600) config.scan() return config.make_wsgi_app() - diff --git a/docs/tutorials/wiki/src/models/tutorial/views.py b/docs/tutorials/wiki/src/models/tutorial/views.py index 7c1f1d228..628ce15ed 100644 --- a/docs/tutorials/wiki/src/models/tutorial/views.py +++ b/docs/tutorials/wiki/src/models/tutorial/views.py @@ -1,5 +1,7 @@ from pyramid.view import view_config +from .models import MyModel -@view_config(renderer='templates/mytemplate.pt') + +@view_config(context=MyModel, renderer='templates/mytemplate.pt') def my_view(request): - return {'project':'tutorial'} + return {'project': 'tutorial'} diff --git a/docs/tutorials/wiki/src/tests/setup.py b/docs/tutorials/wiki/src/tests/setup.py index a665611bd..702d34c4c 100644 --- a/docs/tutorials/wiki/src/tests/setup.py +++ b/docs/tutorials/wiki/src/tests/setup.py @@ -21,7 +21,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -35,12 +35,11 @@ setup(name='tutorial', packages=find_packages(), include_package_data=True, zip_safe=False, - install_requires = requires, - tests_require= requires, + install_requires=requires, + tests_require=requires, test_suite="tutorial", - entry_points = """\ + entry_points="""\ [paste.app_factory] main = tutorial:main """, ) - diff --git a/docs/tutorials/wiki/src/tests/tutorial/__init__.py b/docs/tutorials/wiki/src/tests/tutorial/__init__.py index b42e01d03..8ea8f8fa3 100644 --- a/docs/tutorials/wiki/src/tests/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/tests/tutorial/__init__.py @@ -11,8 +11,9 @@ def root_factory(request): conn = get_connection(request) return appmaker(conn.root()) + def main(global_config, **settings): - """ This function returns a WSGI application. + """ This function returns a Pyramid WSGI application. """ authn_policy = AuthTktAuthenticationPolicy( 'sosecret', callback=groupfinder, hashalg='sha512') diff --git a/docs/tutorials/wiki/src/tests/tutorial/tests.py b/docs/tutorials/wiki/src/tests/tutorial/tests.py index 81f7a1882..ff7ca4f33 100644 --- a/docs/tutorials/wiki/src/tests/tutorial/tests.py +++ b/docs/tutorials/wiki/src/tests/tutorial/tests.py @@ -30,6 +30,7 @@ class WikiModelTests(unittest.TestCase): self.assertEqual(wiki.__name__, None) class AppmakerTests(unittest.TestCase): + def _callFUT(self, zodb_root): from .models import appmaker return appmaker(zodb_root) diff --git a/docs/tutorials/wiki/src/tests/tutorial/views.py b/docs/tutorials/wiki/src/tests/tutorial/views.py index 50485d279..77956b1e3 100644 --- a/docs/tutorials/wiki/src/tests/tutorial/views.py +++ b/docs/tutorials/wiki/src/tests/tutorial/views.py @@ -64,8 +64,8 @@ def add_page(context, request): page.__name__ = pagename page.__parent__ = context - return dict(page = page, save_url = save_url, - logged_in = authenticated_userid(request)) + return dict(page=page, save_url=save_url, + logged_in=authenticated_userid(request)) @view_config(name='edit_page', context='.models.Page', renderer='templates/edit.pt', @@ -75,9 +75,9 @@ def edit_page(context, request): context.data = request.params['body'] return HTTPFound(location = request.resource_url(context)) - return dict(page = context, - save_url = request.resource_url(context, 'edit_page'), - logged_in = authenticated_userid(request)) + return dict(page=context, + save_url=request.resource_url(context, 'edit_page'), + logged_in=authenticated_userid(request)) @view_config(context='.models.Wiki', name='login', renderer='templates/login.pt') diff --git a/docs/tutorials/wiki/src/views/setup.py b/docs/tutorials/wiki/src/views/setup.py index 1d2d690fc..3164fd724 100644 --- a/docs/tutorials/wiki/src/views/setup.py +++ b/docs/tutorials/wiki/src/views/setup.py @@ -20,7 +20,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -34,12 +34,11 @@ setup(name='tutorial', packages=find_packages(), include_package_data=True, zip_safe=False, - install_requires = requires, - tests_require= requires, + install_requires=requires, + tests_require=requires, test_suite="tutorial", - entry_points = """\ + entry_points="""\ [paste.app_factory] main = tutorial:main """, ) - diff --git a/docs/tutorials/wiki/src/views/tutorial/__init__.py b/docs/tutorials/wiki/src/views/tutorial/__init__.py index 957a0b705..c3bb87a62 100644 --- a/docs/tutorials/wiki/src/views/tutorial/__init__.py +++ b/docs/tutorials/wiki/src/views/tutorial/__init__.py @@ -1,15 +1,17 @@ from pyramid.config import Configurator from pyramid_zodbconn import get_connection -from tutorial.models import appmaker +from .models import appmaker + def root_factory(request): conn = get_connection(request) return appmaker(conn.root()) + def main(global_config, **settings): - """ This function returns a WSGI application. + """ This function returns a Pyramid WSGI application. """ config = Configurator(root_factory=root_factory, settings=settings) config.add_static_view('static', 'static', cache_max_age=3600) - config.scan('tutorial') + config.scan() return config.make_wsgi_app() diff --git a/docs/tutorials/wiki/src/views/tutorial/tests.py b/docs/tutorials/wiki/src/views/tutorial/tests.py index 9eac2a432..663c9f405 100644 --- a/docs/tutorials/wiki/src/views/tutorial/tests.py +++ b/docs/tutorials/wiki/src/views/tutorial/tests.py @@ -5,7 +5,7 @@ from pyramid import testing class PageModelTests(unittest.TestCase): def _getTargetClass(self): - from tutorial.models import Page + from .models import Page return Page def _makeOne(self, data=u'some data'): @@ -14,11 +14,11 @@ class PageModelTests(unittest.TestCase): def test_constructor(self): instance = self._makeOne() self.assertEqual(instance.data, u'some data') - + class WikiModelTests(unittest.TestCase): def _getTargetClass(self): - from tutorial.models import Wiki + from .models import Wiki return Wiki def _makeOne(self): @@ -30,8 +30,9 @@ class WikiModelTests(unittest.TestCase): self.assertEqual(wiki.__name__, None) class AppmakerTests(unittest.TestCase): + def _callFUT(self, zodb_root): - from tutorial.models import appmaker + from .models import appmaker return appmaker(zodb_root) def test_it(self): @@ -42,7 +43,7 @@ class AppmakerTests(unittest.TestCase): class ViewWikiTests(unittest.TestCase): def test_it(self): - from tutorial.views import view_wiki + from .views import view_wiki context = testing.DummyResource() request = testing.DummyRequest() response = view_wiki(context, request) @@ -50,7 +51,7 @@ class ViewWikiTests(unittest.TestCase): class ViewPageTests(unittest.TestCase): def _callFUT(self, context, request): - from tutorial.views import view_page + from .views import view_page return view_page(context, request) def test_it(self): @@ -63,7 +64,7 @@ class ViewPageTests(unittest.TestCase): info = self._callFUT(context, request) self.assertEqual(info['page'], context) self.assertEqual( - info['content'], + info['content'], '<div class="document">\n' '<p>Hello <a href="http://example.com/add_page/CruelWorld">' 'CruelWorld</a> ' @@ -72,11 +73,11 @@ class ViewPageTests(unittest.TestCase): '</p>\n</div>\n') self.assertEqual(info['edit_url'], 'http://example.com/thepage/edit_page') - - + + class AddPageTests(unittest.TestCase): def _callFUT(self, context, request): - from tutorial.views import add_page + from .views import add_page return add_page(context, request) def test_it_notsubmitted(self): @@ -88,7 +89,7 @@ class AddPageTests(unittest.TestCase): self.assertEqual( info['save_url'], request.resource_url(context, 'add_page', 'AnotherPage')) - + def test_it_submitted(self): context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, @@ -102,7 +103,7 @@ class AddPageTests(unittest.TestCase): class EditPageTests(unittest.TestCase): def _callFUT(self, context, request): - from tutorial.views import edit_page + from .views import edit_page return edit_page(context, request) def test_it_notsubmitted(self): @@ -112,7 +113,7 @@ class EditPageTests(unittest.TestCase): self.assertEqual(info['page'], context) self.assertEqual(info['save_url'], request.resource_url(context, 'edit_page')) - + def test_it_submitted(self): context = testing.DummyResource() request = testing.DummyRequest({'form.submitted':True, diff --git a/docs/tutorials/wiki/src/views/tutorial/views.py b/docs/tutorials/wiki/src/views/tutorial/views.py index b0c15297f..61517c31d 100644 --- a/docs/tutorials/wiki/src/views/tutorial/views.py +++ b/docs/tutorials/wiki/src/views/tutorial/views.py @@ -56,5 +56,5 @@ def edit_page(context, request): context.data = request.params['body'] return HTTPFound(location = request.resource_url(context)) - return dict(page = context, - save_url = request.resource_url(context, 'edit_page')) + return dict(page=context, + save_url=request.resource_url(context, 'edit_page')) diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index 1ddf8c82d..d98fb87e4 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -86,7 +86,7 @@ statement at the head: Add the following class definition: .. literalinclude:: src/authorization/tutorial/models.py - :lines: 35-39 + :lines: 36-40 :linenos: :language: python @@ -112,7 +112,7 @@ parameter to our :term:`Configurator` constructor, that points to the class we created above: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 23-24 + :lines: 24-25 :linenos: :emphasize-lines: 2 :language: python @@ -144,7 +144,7 @@ add these import statements: Now add those policies to the configuration: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 20-26 + :lines: 21-27 :linenos: :emphasize-lines: 1-3,6-7 :language: python @@ -206,7 +206,7 @@ Go back to ``tutorial/tutorial/__init__.py`` and add these two routes: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 29-30 + :lines: 30-31 :linenos: :language: python @@ -333,7 +333,7 @@ when we're done: .. literalinclude:: src/authorization/tutorial/__init__.py :linenos: - :emphasize-lines: 2-3,7,23-24,20-26,29-30 + :emphasize-lines: 2-3,7,21-23,25-27,30-31 :language: python (Only the highlighted lines need to be added.) @@ -343,7 +343,7 @@ when we're done: .. literalinclude:: src/authorization/tutorial/models.py :linenos: - :emphasize-lines: 1-4,35-39 + :emphasize-lines: 1-4,36-40 :language: python (Only the highlighted lines need to be added.) diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index 4f73dc914..763deaa32 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -45,24 +45,23 @@ When you invoke the ``pserve development.ini`` command, the ``main`` function above is executed. It accepts some settings and returns a :term:`WSGI` application. (See :ref:`startup_chapter` for more about ``pserve``.) -The main function first creates a SQLAlchemy database engine using +The main function first creates a :term:`SQLAlchemy` database engine using ``engine_from_config`` from the ``sqlalchemy.`` prefixed settings in the ``development.ini`` file's ``[app:main]`` section. This will be a URI (something like ``sqlite://``): .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 12 - :linenos: + :lines: 13 :language: py ``main`` then initializes our SQLAlchemy session object, passing it the engine: .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 13 + :lines: 14 :language: py -``main`` subsequently initializes our SQLAlchemy declarative Base object, +``main`` subsequently initializes our SQLAlchemy declarative ``Base`` object, assigning the engine we created to the ``bind`` attribute of it's ``metadata`` object. This allows table definitions done imperatively (instead of declaratively, via a class statement) to work. We won't use any @@ -71,13 +70,13 @@ forgotten about this tutorial, you won't be left scratching your head when it doesn't work. .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 14 + :lines: 15 :language: py The next step of ``main`` is to construct a :term:`Configurator` object: .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 15 + :lines: 16 :language: py ``settings`` is passed to the Configurator as a keyword argument with the @@ -90,13 +89,13 @@ deployment-related values such as ``pyramid.reload_templates``, two arguments: ``static`` (the name), and ``static`` (the path): .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 16 + :lines: 17 :language: py This registers a static resource view which will match any URL that starts -with the prefix ``/static`` (by virtue of the first argument to add_static -view). This will serve up static resources for us from within the ``static`` -directory of our ``tutorial`` package, in this case, via +with the prefix ``/static`` (by virtue of the first argument to +``add_static_view``). This will serve up static resources for us from within +the ``static`` directory of our ``tutorial`` package, in this case, via ``http://localhost:6543/static/`` and below (by virtue of the second argument to add_static_view). With this declaration, we're saying that any URL that starts with ``/static`` should go to the static view; any remainder of its @@ -108,20 +107,21 @@ via the :meth:`pyramid.config.Configurator.add_route` method that will be used when the URL is ``/``: .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 17 + :lines: 18 :language: py Since this route has a ``pattern`` equalling ``/`` it is the route that will be matched when the URL ``/`` is visited, e.g. ``http://localhost:6543/``. -``main`` next calls the ``scan`` method of the configurator, which will -recursively scan our ``tutorial`` package, looking for ``@view_config`` (and +``main`` next calls the ``scan`` method of the configurator +(:meth:`pyramid.config.Configurator.scan`), which will recursively scan our +``tutorial`` package, looking for ``@view_config`` (and other special) decorators. When it finds a ``@view_config`` decorator, a view configuration will be registered, which will allow one of our application URLs to be mapped to some code. .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 18 + :lines: 19 :language: py Finally, ``main`` is finished configuring things, so it uses the @@ -129,7 +129,7 @@ Finally, ``main`` is finished configuring things, so it uses the :term:`WSGI` application: .. literalinclude:: src/basiclayout/tutorial/__init__.py - :lines: 19 + :lines: 20 :language: py View Declarations via ``views.py`` @@ -197,11 +197,10 @@ Let's examine this in detail. First, we need some imports to support later code: :linenos: :language: py -Next we set up a SQLAlchemy "DBSession" object: +Next we set up a SQLAlchemy ``DBSession`` object: .. literalinclude:: src/basiclayout/tutorial/models.py :lines: 16 - :linenos: :language: py ``scoped_session`` and ``sessionmaker`` are standard SQLAlchemy helpers. @@ -230,8 +229,9 @@ To give a simple example of a model class, we define one named ``MyModel``: :linenos: :language: py -Our example model has an ``__init__`` that takes a two arguments (``name``, -and ``value``). It stores these values as ``self.name`` and ``self.value`` +Our example model has an ``__init__`` method that takes a two arguments +(``name``, and ``value``). It stores these values as ``self.name`` and +``self.value`` within the ``__init__`` function itself. The ``MyModel`` class also has a ``__tablename__`` attribute. This informs SQLAlchemy which table to use to store the data representing instances of this class. diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 1653faf4a..2148582f1 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -2,7 +2,7 @@ Defining the Domain Model ========================= -The first change we'll make to our stock pcreate-generated application will +The first change we'll make to our stock ``pcreate``-generated application will be to define a :term:`domain model` constructor representing a wiki page. We'll do this inside our ``models.py`` file. @@ -15,7 +15,7 @@ Making Edits to ``models.py`` .. note:: - There is nothing automagically special about the filename ``models.py``. A + There is nothing special about the filename ``models.py``. A project may have many models throughout its codebase in arbitrarily-named files. Files implementing models often have ``model`` in their filenames (or they may live in a Python subpackage of your application package named @@ -27,7 +27,7 @@ following: .. literalinclude:: src/models/tutorial/models.py :linenos: :language: py - :emphasize-lines: 19-21,24,26,28 + :emphasize-lines: 20-22,25,27,29 (The highlighted lines are the ones that need to be changed.) @@ -46,8 +46,8 @@ this class inherits from an instance of As you can see, our ``Page`` class has a class level attribute ``__tablename__`` which equals the string ``'pages'``. This means that -SQLAlchemy will store our wiki data in a SQL table named ``pages``. Our Page -class will also have class-level attributes named ``id``, ``name`` and +SQLAlchemy will store our wiki data in a SQL table named ``pages``. Our +``Page`` class will also have class-level attributes named ``id``, ``name`` and ``data`` (all instances of :class:`sqlalchemy.Column`). These will map to columns in the ``pages`` table. The ``id`` attribute will be the primary key in the table. The ``name`` attribute will be a text attribute, each value of @@ -73,7 +73,7 @@ following: .. literalinclude:: src/models/tutorial/scripts/initializedb.py :linenos: :language: python - :emphasize-lines: 14,34 + :emphasize-lines: 14,36 (Only the highlighted lines need to be changed.) diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index a54996e3c..6b8689b5b 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -26,7 +26,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 +123,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,7 +139,7 @@ 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 @@ -181,6 +181,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 +198,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 +212,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 +342,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.) @@ -366,7 +366,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`. diff --git a/docs/tutorials/wiki2/design.rst b/docs/tutorials/wiki2/design.rst index 6e41e00aa..c56d7fecf 100644 --- a/docs/tutorials/wiki2/design.rst +++ b/docs/tutorials/wiki2/design.rst @@ -9,7 +9,7 @@ tutorial. Overall ------- -We choose to use ``reStructuredText`` markup in the wiki text. Translation +We choose to use :term:`reStructuredText` markup in the wiki text. Translation from reStructuredText to HTML is provided by the widely used ``docutils`` Python module. We will add this module in the dependency list on the project ``setup.py`` file. diff --git a/docs/tutorials/wiki2/installation.rst b/docs/tutorials/wiki2/installation.rst index 6589a1557..4ab02a13a 100644 --- a/docs/tutorials/wiki2/installation.rst +++ b/docs/tutorials/wiki2/installation.rst @@ -2,7 +2,7 @@ Installation ============ -This tutorial assumes that Python and virtualenv are already installed +This tutorial assumes that Python and :term:`virtualenv` are already installed and working in your system. If you need help setting this up, you should refer to the chapters on :ref:`installing_chapter`. @@ -98,9 +98,9 @@ Installing the Project in "Development Mode" In order to do development on the project easily, you must "register" the project as a development egg in your workspace using the -``setup.py develop`` command. In order to do so, cd to the "tutorial" +``setup.py develop`` command. In order to do so, cd to the `tutorial` directory you created in :ref:`sql_making_a_project`, and run the -"setup.py develop" command using virtualenv Python interpreter. +``setup.py develop`` command using the virtualenv Python interpreter. On UNIX: @@ -158,8 +158,8 @@ test`` does but provides additional "coverage" information, exposing which lines of your project are "covered" (or not covered) by the tests. -To get this functionality working, we'll need to install a couple of -other packages into our ``virtualenv``: ``nose`` and ``coverage``: +To get this functionality working, we'll need to install the ``nose`` and +``coverage`` packages into our ``virtualenv``: On UNIX: diff --git a/docs/tutorials/wiki2/src/authorization/setup.py b/docs/tutorials/wiki2/src/authorization/setup.py index d658cae93..36668dd33 100644 --- a/docs/tutorials/wiki2/src/authorization/setup.py +++ b/docs/tutorials/wiki2/src/authorization/setup.py @@ -20,7 +20,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -43,4 +43,3 @@ setup(name='tutorial', initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) - diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py b/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py index 76071173a..d08e55bf9 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/__init__.py @@ -11,6 +11,7 @@ from .models import ( Base, ) + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ @@ -33,4 +34,3 @@ def main(global_config, **settings): config.add_route('edit_page', '/{pagename}/edit_page') config.scan() return config.make_wsgi_app() - diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/models.py b/docs/tutorials/wiki2/src/authorization/tutorial/models.py index c3bdcbea5..91e5a0019 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/models.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/models.py @@ -21,6 +21,7 @@ from zope.sqlalchemy import ZopeTransactionExtension DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base() + class Page(Base): """ The SQLAlchemy declarative model class for a Page object. """ __tablename__ = 'pages' diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/scripts/initializedb.py b/docs/tutorials/wiki2/src/authorization/tutorial/scripts/initializedb.py index 03188e8ad..092e359ce 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/scripts/initializedb.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/scripts/initializedb.py @@ -15,12 +15,14 @@ from ..models import ( Base, ) + def usage(argv): cmd = os.path.basename(argv[0]) print('usage: %s <config_uri>\n' - '(example: "%s development.ini")' % (cmd, cmd)) + '(example: "%s development.ini")' % (cmd, cmd)) sys.exit(1) + def main(argv=sys.argv): if len(argv) != 2: usage(argv) diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/tests.py b/docs/tutorials/wiki2/src/authorization/tutorial/tests.py index 31d2dc6d5..5dcee127b 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/tests.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/tests.py @@ -1,5 +1,6 @@ import unittest import transaction + from pyramid import testing def _initTestingDB(): diff --git a/docs/tutorials/wiki2/src/basiclayout/setup.py b/docs/tutorials/wiki2/src/basiclayout/setup.py index 1a1ad78aa..a09bf756a 100644 --- a/docs/tutorials/wiki2/src/basiclayout/setup.py +++ b/docs/tutorials/wiki2/src/basiclayout/setup.py @@ -19,7 +19,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -42,4 +42,3 @@ setup(name='tutorial', initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) - diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py index e39f619ed..aac7c5e69 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/__init__.py @@ -6,6 +6,7 @@ from .models import ( Base, ) + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ @@ -17,4 +18,3 @@ def main(global_config, **settings): config.add_route('home', '/') config.scan() return config.make_wsgi_app() - diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py index b6ac15429..aeeb9df64 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/models.py @@ -16,6 +16,7 @@ from zope.sqlalchemy import ZopeTransactionExtension DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base() + class MyModel(Base): __tablename__ = 'models' id = Column(Integer, primary_key=True) @@ -25,4 +26,3 @@ class MyModel(Base): def __init__(self, name, value): self.name = name self.value = value - diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/scripts/initializedb.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/scripts/initializedb.py index 0e828465f..66feb3008 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/scripts/initializedb.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/scripts/initializedb.py @@ -15,12 +15,14 @@ from ..models import ( Base, ) + def usage(argv): cmd = os.path.basename(argv[0]) print('usage: %s <config_uri>\n' - '(example: "%s development.ini")' % (cmd, cmd)) + '(example: "%s development.ini")' % (cmd, cmd)) sys.exit(1) + def main(argv=sys.argv): if len(argv) != 2: usage(argv) diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py index 653d061e4..57a775e0a 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py @@ -5,6 +5,7 @@ from pyramid import testing from .models import DBSession + class TestMyView(unittest.TestCase): def setUp(self): self.config = testing.setUp() diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py index daf21bb7b..4cfcae4af 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py @@ -8,13 +8,14 @@ from .models import ( MyModel, ) + @view_config(route_name='home', renderer='templates/mytemplate.pt') def my_view(request): try: - one = DBSession.query(MyModel).filter(MyModel.name=='one').first() + one = DBSession.query(MyModel).filter(MyModel.name == 'one').first() except DBAPIError: return Response(conn_err_msg, content_type='text/plain', status_int=500) - return {'one':one, 'project':'tutorial'} + return {'one': one, 'project': 'tutorial'} conn_err_msg = """\ Pyramid is having a problem using your SQL database. The problem diff --git a/docs/tutorials/wiki2/src/models/setup.py b/docs/tutorials/wiki2/src/models/setup.py index 1a1ad78aa..a09bf756a 100644 --- a/docs/tutorials/wiki2/src/models/setup.py +++ b/docs/tutorials/wiki2/src/models/setup.py @@ -19,7 +19,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -42,4 +42,3 @@ setup(name='tutorial', initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) - diff --git a/docs/tutorials/wiki2/src/models/tutorial/__init__.py b/docs/tutorials/wiki2/src/models/tutorial/__init__.py index e39f619ed..aac7c5e69 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/models/tutorial/__init__.py @@ -6,6 +6,7 @@ from .models import ( Base, ) + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ @@ -17,4 +18,3 @@ def main(global_config, **settings): config.add_route('home', '/') config.scan() return config.make_wsgi_app() - diff --git a/docs/tutorials/wiki2/src/models/tutorial/models.py b/docs/tutorials/wiki2/src/models/tutorial/models.py index 499396c5b..9a078d757 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/models.py +++ b/docs/tutorials/wiki2/src/models/tutorial/models.py @@ -16,6 +16,7 @@ from zope.sqlalchemy import ZopeTransactionExtension DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base() + class Page(Base): """ The SQLAlchemy declarative model class for a Page object. """ __tablename__ = 'pages' @@ -26,4 +27,3 @@ class Page(Base): def __init__(self, name, data): self.name = name self.data = data - diff --git a/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py b/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py index 03188e8ad..092e359ce 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py +++ b/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py @@ -15,12 +15,14 @@ from ..models import ( Base, ) + def usage(argv): cmd = os.path.basename(argv[0]) print('usage: %s <config_uri>\n' - '(example: "%s development.ini")' % (cmd, cmd)) + '(example: "%s development.ini")' % (cmd, cmd)) sys.exit(1) + def main(argv=sys.argv): if len(argv) != 2: usage(argv) diff --git a/docs/tutorials/wiki2/src/models/tutorial/tests.py b/docs/tutorials/wiki2/src/models/tutorial/tests.py index 653d061e4..57a775e0a 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/tests.py +++ b/docs/tutorials/wiki2/src/models/tutorial/tests.py @@ -5,6 +5,7 @@ from pyramid import testing from .models import DBSession + class TestMyView(unittest.TestCase): def setUp(self): self.config = testing.setUp() diff --git a/docs/tutorials/wiki2/src/models/tutorial/views.py b/docs/tutorials/wiki2/src/models/tutorial/views.py index daf21bb7b..4cfcae4af 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/views.py +++ b/docs/tutorials/wiki2/src/models/tutorial/views.py @@ -8,13 +8,14 @@ from .models import ( MyModel, ) + @view_config(route_name='home', renderer='templates/mytemplate.pt') def my_view(request): try: - one = DBSession.query(MyModel).filter(MyModel.name=='one').first() + one = DBSession.query(MyModel).filter(MyModel.name == 'one').first() except DBAPIError: return Response(conn_err_msg, content_type='text/plain', status_int=500) - return {'one':one, 'project':'tutorial'} + return {'one': one, 'project': 'tutorial'} conn_err_msg = """\ Pyramid is having a problem using your SQL database. The problem diff --git a/docs/tutorials/wiki2/src/tests/setup.py b/docs/tutorials/wiki2/src/tests/setup.py index 8a619d27b..3c2961fcc 100644 --- a/docs/tutorials/wiki2/src/tests/setup.py +++ b/docs/tutorials/wiki2/src/tests/setup.py @@ -21,7 +21,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -44,4 +44,3 @@ setup(name='tutorial', initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) - diff --git a/docs/tutorials/wiki2/src/tests/tutorial/__init__.py b/docs/tutorials/wiki2/src/tests/tutorial/__init__.py index 76071173a..d08e55bf9 100644 --- a/docs/tutorials/wiki2/src/tests/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/tests/tutorial/__init__.py @@ -11,6 +11,7 @@ from .models import ( Base, ) + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ @@ -33,4 +34,3 @@ def main(global_config, **settings): config.add_route('edit_page', '/{pagename}/edit_page') config.scan() return config.make_wsgi_app() - diff --git a/docs/tutorials/wiki2/src/tests/tutorial/models.py b/docs/tutorials/wiki2/src/tests/tutorial/models.py index c3bdcbea5..91e5a0019 100644 --- a/docs/tutorials/wiki2/src/tests/tutorial/models.py +++ b/docs/tutorials/wiki2/src/tests/tutorial/models.py @@ -21,6 +21,7 @@ from zope.sqlalchemy import ZopeTransactionExtension DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base() + class Page(Base): """ The SQLAlchemy declarative model class for a Page object. """ __tablename__ = 'pages' diff --git a/docs/tutorials/wiki2/src/tests/tutorial/scripts/initializedb.py b/docs/tutorials/wiki2/src/tests/tutorial/scripts/initializedb.py index 03188e8ad..092e359ce 100644 --- a/docs/tutorials/wiki2/src/tests/tutorial/scripts/initializedb.py +++ b/docs/tutorials/wiki2/src/tests/tutorial/scripts/initializedb.py @@ -15,12 +15,14 @@ from ..models import ( Base, ) + def usage(argv): cmd = os.path.basename(argv[0]) print('usage: %s <config_uri>\n' - '(example: "%s development.ini")' % (cmd, cmd)) + '(example: "%s development.ini")' % (cmd, cmd)) sys.exit(1) + def main(argv=sys.argv): if len(argv) != 2: usage(argv) diff --git a/docs/tutorials/wiki2/src/tests/tutorial/tests.py b/docs/tutorials/wiki2/src/tests/tutorial/tests.py index 659862a09..3e96d0a82 100644 --- a/docs/tutorials/wiki2/src/tests/tutorial/tests.py +++ b/docs/tutorials/wiki2/src/tests/tutorial/tests.py @@ -1,7 +1,9 @@ import unittest import transaction + from pyramid import testing + def _initTestingDB(): from sqlalchemy import create_engine from tutorial.models import ( @@ -17,6 +19,7 @@ def _initTestingDB(): DBSession.add(model) return DBSession + def _registerRoutes(config): config.add_route('view_page', '{pagename}') config.add_route('edit_page', '{pagename}/edit_page') @@ -43,6 +46,7 @@ class PageModelTests(unittest.TestCase): self.assertEqual(instance.name, 'SomeName') self.assertEqual(instance.data, 'some data') + class ViewWikiTests(unittest.TestCase): def setUp(self): self.config = testing.setUp() @@ -60,6 +64,7 @@ class ViewWikiTests(unittest.TestCase): response = self._callFUT(request) self.assertEqual(response.location, 'http://example.com/FrontPage') + class ViewPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() @@ -93,6 +98,7 @@ class ViewPageTests(unittest.TestCase): self.assertEqual(info['edit_url'], 'http://example.com/IDoExist/edit_page') + class AddPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() @@ -125,6 +131,7 @@ class AddPageTests(unittest.TestCase): page = self.session.query(Page).filter_by(name='AnotherPage').one() self.assertEqual(page.data, 'Hello yo!') + class EditPageTests(unittest.TestCase): def setUp(self): self.session = _initTestingDB() @@ -162,6 +169,7 @@ class EditPageTests(unittest.TestCase): self.assertEqual(response.location, 'http://example.com/abc') self.assertEqual(page.data, 'Hello yo!') + class FunctionalTests(unittest.TestCase): viewer_login = '/login?login=viewer&password=viewer' \ diff --git a/docs/tutorials/wiki2/src/views/setup.py b/docs/tutorials/wiki2/src/views/setup.py index d658cae93..36668dd33 100644 --- a/docs/tutorials/wiki2/src/views/setup.py +++ b/docs/tutorials/wiki2/src/views/setup.py @@ -20,7 +20,7 @@ requires = [ setup(name='tutorial', version='0.0', description='tutorial', - long_description=README + '\n\n' + CHANGES, + long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", "Framework :: Pyramid", @@ -43,4 +43,3 @@ setup(name='tutorial', initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) - diff --git a/docs/tutorials/wiki2/src/views/tutorial/__init__.py b/docs/tutorials/wiki2/src/views/tutorial/__init__.py index 810e92f75..c95bfdbf8 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/__init__.py +++ b/docs/tutorials/wiki2/src/views/tutorial/__init__.py @@ -6,6 +6,7 @@ from .models import ( Base, ) + def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ diff --git a/docs/tutorials/wiki2/src/views/tutorial/models.py b/docs/tutorials/wiki2/src/views/tutorial/models.py index 499396c5b..9a078d757 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/models.py +++ b/docs/tutorials/wiki2/src/views/tutorial/models.py @@ -16,6 +16,7 @@ from zope.sqlalchemy import ZopeTransactionExtension DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base() + class Page(Base): """ The SQLAlchemy declarative model class for a Page object. """ __tablename__ = 'pages' @@ -26,4 +27,3 @@ class Page(Base): def __init__(self, name, data): self.name = name self.data = data - diff --git a/docs/tutorials/wiki2/src/views/tutorial/scripts/initializedb.py b/docs/tutorials/wiki2/src/views/tutorial/scripts/initializedb.py index 03188e8ad..092e359ce 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/scripts/initializedb.py +++ b/docs/tutorials/wiki2/src/views/tutorial/scripts/initializedb.py @@ -15,12 +15,14 @@ from ..models import ( Base, ) + def usage(argv): cmd = os.path.basename(argv[0]) print('usage: %s <config_uri>\n' - '(example: "%s development.ini")' % (cmd, cmd)) + '(example: "%s development.ini")' % (cmd, cmd)) sys.exit(1) + def main(argv=sys.argv): if len(argv) != 2: usage(argv) diff --git a/docs/tutorials/wiki2/src/views/tutorial/tests.py b/docs/tutorials/wiki2/src/views/tutorial/tests.py index 31d2dc6d5..5dcee127b 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/tests.py +++ b/docs/tutorials/wiki2/src/views/tutorial/tests.py @@ -1,5 +1,6 @@ import unittest import transaction + from pyramid import testing def _initTestingDB(): |
