From c344e532e27ce078643ec3246002d2703ef85416 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Mon, 19 Nov 2012 21:03:46 -0600 Subject: Sync some SQL wiki tutorial files with the scaffold - Files that are not referred to in a literalinclude in the tutorial docs - setup.py appears in literalinclude, but no lines are added or removed so no impact. Fixed docutils order in the requires list. --- docs/tutorials/wiki2/src/authorization/README.txt | 13 +++++++++++++ .../wiki2/src/authorization/development.ini | 20 +++++++++++++++++--- docs/tutorials/wiki2/src/authorization/setup.py | 9 +++++---- docs/tutorials/wiki2/src/basiclayout/README.txt | 13 +++++++++++++ docs/tutorials/wiki2/src/basiclayout/development.ini | 20 +++++++++++++++++--- docs/tutorials/wiki2/src/basiclayout/production.ini | 12 +++++++++--- docs/tutorials/wiki2/src/basiclayout/setup.py | 6 +++--- .../src/basiclayout/tutorial/templates/mytemplate.pt | 2 +- docs/tutorials/wiki2/src/models/README.txt | 13 +++++++++++++ docs/tutorials/wiki2/src/models/development.ini | 20 +++++++++++++++++--- docs/tutorials/wiki2/src/models/setup.py | 6 +++--- docs/tutorials/wiki2/src/tests/README.txt | 13 +++++++++++++ docs/tutorials/wiki2/src/tests/development.ini | 20 +++++++++++++++++--- docs/tutorials/wiki2/src/tests/setup.py | 7 ++++--- docs/tutorials/wiki2/src/views/README.txt | 13 +++++++++++++ docs/tutorials/wiki2/src/views/development.ini | 20 +++++++++++++++++--- docs/tutorials/wiki2/src/views/setup.py | 6 +++--- 17 files changed, 178 insertions(+), 35 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/src/authorization/README.txt b/docs/tutorials/wiki2/src/authorization/README.txt index 6f851e9b7..141851285 100644 --- a/docs/tutorials/wiki2/src/authorization/README.txt +++ b/docs/tutorials/wiki2/src/authorization/README.txt @@ -1 +1,14 @@ tutorial README +================== + +Getting Started +--------------- + +- cd + +- $venv/bin/python setup.py develop + +- $venv/bin/initialize_tutorial_db development.ini + +- $venv/bin/pserve development.ini + diff --git a/docs/tutorials/wiki2/src/authorization/development.ini b/docs/tutorials/wiki2/src/authorization/development.ini index eb2f878c5..a9d53b296 100644 --- a/docs/tutorials/wiki2/src/authorization/development.ini +++ b/docs/tutorials/wiki2/src/authorization/development.ini @@ -1,3 +1,8 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + [app:main] use = egg:tutorial @@ -12,12 +17,23 @@ pyramid.includes = sqlalchemy.url = sqlite:///%(here)s/tutorial.sqlite +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + [server:main] use = egg:waitress#main host = 0.0.0.0 port = 6543 -# Begin logging configuration +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### [loggers] keys = root, tutorial, sqlalchemy @@ -53,5 +69,3 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration diff --git a/docs/tutorials/wiki2/src/authorization/setup.py b/docs/tutorials/wiki2/src/authorization/setup.py index 2fd051927..d658cae93 100644 --- a/docs/tutorials/wiki2/src/authorization/setup.py +++ b/docs/tutorials/wiki2/src/authorization/setup.py @@ -13,8 +13,8 @@ requires = [ 'pyramid_tm', 'pyramid_debugtoolbar', 'zope.sqlalchemy', - 'docutils', 'waitress', + 'docutils', ] setup(name='tutorial', @@ -23,7 +23,7 @@ setup(name='tutorial', long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", - "Framework :: Pylons", + "Framework :: Pyramid", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", ], @@ -35,11 +35,12 @@ setup(name='tutorial', include_package_data=True, zip_safe=False, test_suite='tutorial', - install_requires = requires, - entry_points = """\ + install_requires=requires, + entry_points="""\ [paste.app_factory] main = tutorial:main [console_scripts] initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) + diff --git a/docs/tutorials/wiki2/src/basiclayout/README.txt b/docs/tutorials/wiki2/src/basiclayout/README.txt index 6f851e9b7..141851285 100644 --- a/docs/tutorials/wiki2/src/basiclayout/README.txt +++ b/docs/tutorials/wiki2/src/basiclayout/README.txt @@ -1 +1,14 @@ tutorial README +================== + +Getting Started +--------------- + +- cd + +- $venv/bin/python setup.py develop + +- $venv/bin/initialize_tutorial_db development.ini + +- $venv/bin/pserve development.ini + diff --git a/docs/tutorials/wiki2/src/basiclayout/development.ini b/docs/tutorials/wiki2/src/basiclayout/development.ini index eb2f878c5..a9d53b296 100644 --- a/docs/tutorials/wiki2/src/basiclayout/development.ini +++ b/docs/tutorials/wiki2/src/basiclayout/development.ini @@ -1,3 +1,8 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + [app:main] use = egg:tutorial @@ -12,12 +17,23 @@ pyramid.includes = sqlalchemy.url = sqlite:///%(here)s/tutorial.sqlite +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + [server:main] use = egg:waitress#main host = 0.0.0.0 port = 6543 -# Begin logging configuration +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### [loggers] keys = root, tutorial, sqlalchemy @@ -53,5 +69,3 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration diff --git a/docs/tutorials/wiki2/src/basiclayout/production.ini b/docs/tutorials/wiki2/src/basiclayout/production.ini index 4684d2f7a..fa94c1b3e 100644 --- a/docs/tutorials/wiki2/src/basiclayout/production.ini +++ b/docs/tutorials/wiki2/src/basiclayout/production.ini @@ -1,3 +1,8 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + [app:main] use = egg:tutorial @@ -16,7 +21,10 @@ use = egg:waitress#main host = 0.0.0.0 port = 6543 -# Begin logging configuration +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### [loggers] keys = root, tutorial, sqlalchemy @@ -52,5 +60,3 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration diff --git a/docs/tutorials/wiki2/src/basiclayout/setup.py b/docs/tutorials/wiki2/src/basiclayout/setup.py index 050de7299..1a1ad78aa 100644 --- a/docs/tutorials/wiki2/src/basiclayout/setup.py +++ b/docs/tutorials/wiki2/src/basiclayout/setup.py @@ -22,7 +22,7 @@ setup(name='tutorial', long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", - "Framework :: Pylons", + "Framework :: Pyramid", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", ], @@ -34,8 +34,8 @@ setup(name='tutorial', include_package_data=True, zip_safe=False, test_suite='tutorial', - install_requires = requires, - entry_points = """\ + install_requires=requires, + entry_points="""\ [paste.app_factory] main = tutorial:main [console_scripts] diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/templates/mytemplate.pt b/docs/tutorials/wiki2/src/basiclayout/tutorial/templates/mytemplate.pt index fbfa9870b..15ea6614f 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/templates/mytemplate.pt +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/templates/mytemplate.pt @@ -70,7 +70,7 @@ diff --git a/docs/tutorials/wiki2/src/models/README.txt b/docs/tutorials/wiki2/src/models/README.txt index 6f851e9b7..141851285 100644 --- a/docs/tutorials/wiki2/src/models/README.txt +++ b/docs/tutorials/wiki2/src/models/README.txt @@ -1 +1,14 @@ tutorial README +================== + +Getting Started +--------------- + +- cd + +- $venv/bin/python setup.py develop + +- $venv/bin/initialize_tutorial_db development.ini + +- $venv/bin/pserve development.ini + diff --git a/docs/tutorials/wiki2/src/models/development.ini b/docs/tutorials/wiki2/src/models/development.ini index eb2f878c5..a9d53b296 100644 --- a/docs/tutorials/wiki2/src/models/development.ini +++ b/docs/tutorials/wiki2/src/models/development.ini @@ -1,3 +1,8 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + [app:main] use = egg:tutorial @@ -12,12 +17,23 @@ pyramid.includes = sqlalchemy.url = sqlite:///%(here)s/tutorial.sqlite +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + [server:main] use = egg:waitress#main host = 0.0.0.0 port = 6543 -# Begin logging configuration +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### [loggers] keys = root, tutorial, sqlalchemy @@ -53,5 +69,3 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration diff --git a/docs/tutorials/wiki2/src/models/setup.py b/docs/tutorials/wiki2/src/models/setup.py index 050de7299..1a1ad78aa 100644 --- a/docs/tutorials/wiki2/src/models/setup.py +++ b/docs/tutorials/wiki2/src/models/setup.py @@ -22,7 +22,7 @@ setup(name='tutorial', long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", - "Framework :: Pylons", + "Framework :: Pyramid", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", ], @@ -34,8 +34,8 @@ setup(name='tutorial', include_package_data=True, zip_safe=False, test_suite='tutorial', - install_requires = requires, - entry_points = """\ + install_requires=requires, + entry_points="""\ [paste.app_factory] main = tutorial:main [console_scripts] diff --git a/docs/tutorials/wiki2/src/tests/README.txt b/docs/tutorials/wiki2/src/tests/README.txt index 6f851e9b7..141851285 100644 --- a/docs/tutorials/wiki2/src/tests/README.txt +++ b/docs/tutorials/wiki2/src/tests/README.txt @@ -1 +1,14 @@ tutorial README +================== + +Getting Started +--------------- + +- cd + +- $venv/bin/python setup.py develop + +- $venv/bin/initialize_tutorial_db development.ini + +- $venv/bin/pserve development.ini + diff --git a/docs/tutorials/wiki2/src/tests/development.ini b/docs/tutorials/wiki2/src/tests/development.ini index eb2f878c5..a9d53b296 100644 --- a/docs/tutorials/wiki2/src/tests/development.ini +++ b/docs/tutorials/wiki2/src/tests/development.ini @@ -1,3 +1,8 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + [app:main] use = egg:tutorial @@ -12,12 +17,23 @@ pyramid.includes = sqlalchemy.url = sqlite:///%(here)s/tutorial.sqlite +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + [server:main] use = egg:waitress#main host = 0.0.0.0 port = 6543 -# Begin logging configuration +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### [loggers] keys = root, tutorial, sqlalchemy @@ -53,5 +69,3 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration diff --git a/docs/tutorials/wiki2/src/tests/setup.py b/docs/tutorials/wiki2/src/tests/setup.py index 0f58d8a18..8a619d27b 100644 --- a/docs/tutorials/wiki2/src/tests/setup.py +++ b/docs/tutorials/wiki2/src/tests/setup.py @@ -24,7 +24,7 @@ setup(name='tutorial', long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", - "Framework :: Pylons", + "Framework :: Pyramid", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", ], @@ -36,11 +36,12 @@ setup(name='tutorial', include_package_data=True, zip_safe=False, test_suite='tutorial', - install_requires = requires, - entry_points = """\ + install_requires=requires, + entry_points="""\ [paste.app_factory] main = tutorial:main [console_scripts] initialize_tutorial_db = tutorial.scripts.initializedb:main """, ) + diff --git a/docs/tutorials/wiki2/src/views/README.txt b/docs/tutorials/wiki2/src/views/README.txt index 6f851e9b7..141851285 100644 --- a/docs/tutorials/wiki2/src/views/README.txt +++ b/docs/tutorials/wiki2/src/views/README.txt @@ -1 +1,14 @@ tutorial README +================== + +Getting Started +--------------- + +- cd + +- $venv/bin/python setup.py develop + +- $venv/bin/initialize_tutorial_db development.ini + +- $venv/bin/pserve development.ini + diff --git a/docs/tutorials/wiki2/src/views/development.ini b/docs/tutorials/wiki2/src/views/development.ini index eb2f878c5..a9d53b296 100644 --- a/docs/tutorials/wiki2/src/views/development.ini +++ b/docs/tutorials/wiki2/src/views/development.ini @@ -1,3 +1,8 @@ +### +# app configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html +### + [app:main] use = egg:tutorial @@ -12,12 +17,23 @@ pyramid.includes = sqlalchemy.url = sqlite:///%(here)s/tutorial.sqlite +# By default, the toolbar only appears for clients from IP addresses +# '127.0.0.1' and '::1'. +# debugtoolbar.hosts = 127.0.0.1 ::1 + +### +# wsgi server configuration +### + [server:main] use = egg:waitress#main host = 0.0.0.0 port = 6543 -# Begin logging configuration +### +# logging configuration +# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html +### [loggers] keys = root, tutorial, sqlalchemy @@ -53,5 +69,3 @@ formatter = generic [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s - -# End logging configuration diff --git a/docs/tutorials/wiki2/src/views/setup.py b/docs/tutorials/wiki2/src/views/setup.py index 34b578e21..d658cae93 100644 --- a/docs/tutorials/wiki2/src/views/setup.py +++ b/docs/tutorials/wiki2/src/views/setup.py @@ -23,7 +23,7 @@ setup(name='tutorial', long_description=README + '\n\n' + CHANGES, classifiers=[ "Programming Language :: Python", - "Framework :: Pylons", + "Framework :: Pyramid", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", ], @@ -35,8 +35,8 @@ setup(name='tutorial', include_package_data=True, zip_safe=False, test_suite='tutorial', - install_requires = requires, - entry_points = """\ + install_requires=requires, + entry_points="""\ [paste.app_factory] main = tutorial:main [console_scripts] -- cgit v1.2.3 From 5fbaf7be1b82247e21fa7d3b98d76e7d92ac522c Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Tue, 20 Nov 2012 19:46:10 -0600 Subject: Sync views.py on SQL wiki tutorial with the scaffold - Explain the added lines in the Basic Layout chapter. - The user is told to remove the added lines in the Defining Views chapter, there was no need to fix any emphasized lines. - Sync the file in the other sections even if it is not shown, for consistency. --- docs/tutorials/wiki2/basiclayout.rst | 6 ++++++ .../wiki2/src/basiclayout/tutorial/views.py | 25 +++++++++++++++++++++- docs/tutorials/wiki2/src/models/tutorial/views.py | 25 +++++++++++++++++++++- docs/tutorials/wiki2/src/tests/tutorial/views.py | 13 +++++------ 4 files changed, 59 insertions(+), 10 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index dbd130c36..4f73dc914 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -171,6 +171,12 @@ application. Without being processed by ``scan``, the decorator effectively does nothing. ``@view_config`` is inert without being detected via a :term:`scan`. +The sample ``my_view()`` created by the scaffold uses a ``try:`` and ``except:`` +clause, to detect if there is a problem accessing the project database and +provide an alternate error response. That response will include the text +shown at the end of the file, which will be displayed in the browser to +inform the user about possible actions to take to solve the problem. + Content Models with ``models.py`` --------------------------------- diff --git a/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py b/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py index 3e6abf2c2..daf21bb7b 100644 --- a/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py +++ b/docs/tutorials/wiki2/src/basiclayout/tutorial/views.py @@ -1,5 +1,8 @@ +from pyramid.response import Response from pyramid.view import view_config +from sqlalchemy.exc import DBAPIError + from .models import ( DBSession, MyModel, @@ -7,5 +10,25 @@ from .models import ( @view_config(route_name='home', renderer='templates/mytemplate.pt') def my_view(request): - one = DBSession.query(MyModel).filter(MyModel.name=='one').first() + try: + 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'} + +conn_err_msg = """\ +Pyramid is having a problem using your SQL database. The problem +might be caused by one of the following things: + +1. You may need to run the "initialize_tutorial_db" script + to initialize your database tables. Check your virtual + environment's "bin" directory for this script and try to run it. + +2. Your database server may not be running. Check that the + database server referred to by the "sqlalchemy.url" setting in + your "development.ini" file is running. + +After you fix the problem, please restart the Pyramid application to +try it again. +""" + diff --git a/docs/tutorials/wiki2/src/models/tutorial/views.py b/docs/tutorials/wiki2/src/models/tutorial/views.py index 3e6abf2c2..daf21bb7b 100644 --- a/docs/tutorials/wiki2/src/models/tutorial/views.py +++ b/docs/tutorials/wiki2/src/models/tutorial/views.py @@ -1,5 +1,8 @@ +from pyramid.response import Response from pyramid.view import view_config +from sqlalchemy.exc import DBAPIError + from .models import ( DBSession, MyModel, @@ -7,5 +10,25 @@ from .models import ( @view_config(route_name='home', renderer='templates/mytemplate.pt') def my_view(request): - one = DBSession.query(MyModel).filter(MyModel.name=='one').first() + try: + 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'} + +conn_err_msg = """\ +Pyramid is having a problem using your SQL database. The problem +might be caused by one of the following things: + +1. You may need to run the "initialize_tutorial_db" script + to initialize your database tables. Check your virtual + environment's "bin" directory for this script and try to run it. + +2. Your database server may not be running. Check that the + database server referred to by the "sqlalchemy.url" setting in + your "development.ini" file is running. + +After you fix the problem, please restart the Pyramid application to +try it again. +""" + diff --git a/docs/tutorials/wiki2/src/tests/tutorial/views.py b/docs/tutorials/wiki2/src/tests/tutorial/views.py index 42ac0eb7f..0d085b0e2 100644 --- a/docs/tutorials/wiki2/src/tests/tutorial/views.py +++ b/docs/tutorials/wiki2/src/tests/tutorial/views.py @@ -37,14 +37,13 @@ def view_wiki(request): permission='view') def view_page(request): pagename = request.matchdict['pagename'] - session = DBSession() - page = session.query(Page).filter_by(name=pagename).first() + page = DBSession.query(Page).filter_by(name=pagename).first() if page is None: return HTTPNotFound('No such page') def check(match): word = match.group(1) - exists = session.query(Page).filter_by(name=word).all() + exists = DBSession.query(Page).filter_by(name=word).all() if exists: view_url = request.route_url('view_page', pagename=word) return '%s' % (view_url, word) @@ -63,10 +62,9 @@ def view_page(request): def add_page(request): pagename = request.matchdict['pagename'] if 'form.submitted' in request.params: - session = DBSession() body = request.params['body'] page = Page(pagename, body) - session.add(page) + DBSession.add(page) return HTTPFound(location = request.route_url('view_page', pagename=pagename)) save_url = request.route_url('add_page', pagename=pagename) @@ -78,11 +76,10 @@ def add_page(request): permission='edit') def edit_page(request): pagename = request.matchdict['pagename'] - session = DBSession() - page = session.query(Page).filter_by(name=pagename).one() + page = DBSession.query(Page).filter_by(name=pagename).one() if 'form.submitted' in request.params: page.data = request.params['body'] - session.add(page) + DBSession.add(page) return HTTPFound(location = request.route_url('view_page', pagename=pagename)) return dict( -- cgit v1.2.3 From b9b2ee39c251dd68a12e717e1f6d9d02a29efe9a Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 30 Nov 2012 09:27:09 -0800 Subject: A bunch of minor tweaks to the wiki2 tutorial in docs/tutorials/wiki2 --- docs/tutorials/wiki2/basiclayout.rst | 22 ++++++++++++---------- docs/tutorials/wiki2/definingmodels.rst | 8 ++++---- docs/tutorials/wiki2/definingviews.rst | 32 ++++++++++++++++---------------- docs/tutorials/wiki2/design.rst | 2 +- docs/tutorials/wiki2/installation.rst | 10 +++++----- 5 files changed, 38 insertions(+), 36 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index 4f73dc914..ed98da183 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -45,7 +45,7 @@ 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://``): @@ -62,7 +62,7 @@ engine: :lines: 13 :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 @@ -94,9 +94,9 @@ two arguments: ``static`` (the name), and ``static`` (the path): :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 @@ -114,8 +114,9 @@ used when the URL is ``/``: 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. @@ -197,7 +198,7 @@ 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 @@ -230,8 +231,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..2e6c74c99 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 @@ -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 diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index a54996e3c..c23ca947d 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 ================ 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: -- cgit v1.2.3 From 9223b3cbff80328431e3711eba2a317bb206286e Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 30 Nov 2012 09:44:25 -0800 Subject: tutorials/wiki2/definingviews.rst: Change example error page from http://localhost:6543/add_page to http://localhost:6543/foobar/edit_page For me, the former generates "404 Not Found" (probably because it doesn't match a route) while the latter gives "sqlalchemy.orm.exc.NoResultFound" and the nice traceback from Werkzeug. --- docs/tutorials/wiki2/definingviews.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index c23ca947d..538b94216 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -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`. -- cgit v1.2.3 From c47b8caa24857c1c35fd0ddf72a237c70b63f5cd Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Sat, 1 Dec 2012 19:23:34 -0600 Subject: Sync setup.py in SQL wiki tutorial --- docs/tutorials/wiki2/src/authorization/setup.py | 3 +-- docs/tutorials/wiki2/src/basiclayout/setup.py | 3 +-- docs/tutorials/wiki2/src/models/setup.py | 3 +-- docs/tutorials/wiki2/src/tests/setup.py | 3 +-- docs/tutorials/wiki2/src/views/setup.py | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) (limited to 'docs/tutorials/wiki2') 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/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/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/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/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 """, ) - -- cgit v1.2.3 From e90fa43a8051dfc8799596e17b72fd3d3def6516 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Sat, 1 Dec 2012 19:43:02 -0600 Subject: Sync __init__.py in SQL wiki tutorial - Update lines and emphasized-lines - No line numbers if only a single line --- docs/tutorials/wiki2/authorization.rst | 8 ++++---- docs/tutorials/wiki2/basiclayout.rst | 17 ++++++++--------- docs/tutorials/wiki2/definingviews.rst | 2 +- .../wiki2/src/authorization/tutorial/__init__.py | 2 +- .../wiki2/src/basiclayout/tutorial/__init__.py | 2 +- docs/tutorials/wiki2/src/models/tutorial/__init__.py | 2 +- docs/tutorials/wiki2/src/tests/tutorial/__init__.py | 2 +- docs/tutorials/wiki2/src/views/tutorial/__init__.py | 1 + 8 files changed, 18 insertions(+), 18 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index 1ddf8c82d..ffaf1e35e 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -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.) diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index 4f73dc914..7b9c44bb1 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -51,15 +51,14 @@ The main function first creates a SQLAlchemy database engine using (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, @@ -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,7 +89,7 @@ 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 @@ -108,7 +107,7 @@ 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 @@ -121,7 +120,7 @@ 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 +128,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`` diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index a54996e3c..d6a31edbb 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -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.) 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/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/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/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/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. """ -- cgit v1.2.3 From 479178179df2e3554d81d8c42d7ff46b75901c62 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Sat, 1 Dec 2012 22:30:50 -0600 Subject: Sync models.py in SQL wiki tutorial - Update lines and emphasized-lines - No line numbers if only a single line --- docs/tutorials/wiki2/authorization.rst | 4 ++-- docs/tutorials/wiki2/basiclayout.rst | 1 - docs/tutorials/wiki2/definingmodels.rst | 2 +- docs/tutorials/wiki2/src/authorization/tutorial/models.py | 1 + docs/tutorials/wiki2/src/basiclayout/tutorial/models.py | 2 +- docs/tutorials/wiki2/src/models/tutorial/models.py | 2 +- docs/tutorials/wiki2/src/tests/tutorial/models.py | 1 + docs/tutorials/wiki2/src/views/tutorial/models.py | 2 +- 8 files changed, 8 insertions(+), 7 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index ffaf1e35e..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 @@ -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 7b9c44bb1..934bfb52a 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -200,7 +200,6 @@ 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. diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 1653faf4a..936abbeb6 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -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.) 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/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/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/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/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 - -- cgit v1.2.3 From 412c4b09deb3a53f3c9ee39423b527709ea13097 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Sun, 2 Dec 2012 17:29:20 -0600 Subject: Sync initializedb.py in SQL wiki tutorial --- docs/tutorials/wiki2/definingmodels.rst | 2 +- .../wiki2/src/authorization/tutorial/scripts/initializedb.py | 4 +++- docs/tutorials/wiki2/src/basiclayout/tutorial/scripts/initializedb.py | 4 +++- docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py | 4 +++- docs/tutorials/wiki2/src/tests/tutorial/scripts/initializedb.py | 4 +++- docs/tutorials/wiki2/src/views/tutorial/scripts/initializedb.py | 4 +++- 6 files changed, 16 insertions(+), 6 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 936abbeb6..e46e9fde0 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -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/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 \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/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 \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/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 \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/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 \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/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 \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) -- cgit v1.2.3 From 95a0b80ed0eefae151d00043f85d94534a256b89 Mon Sep 17 00:00:00 2001 From: Patricio Paez Date: Sun, 2 Dec 2012 18:10:33 -0600 Subject: Sync tests.py and views.py in SQL wiki tutorial - No line references to update --- docs/tutorials/wiki2/src/authorization/tutorial/tests.py | 1 + docs/tutorials/wiki2/src/basiclayout/tutorial/tests.py | 1 + docs/tutorials/wiki2/src/basiclayout/tutorial/views.py | 5 +++-- docs/tutorials/wiki2/src/models/tutorial/tests.py | 1 + docs/tutorials/wiki2/src/models/tutorial/views.py | 5 +++-- docs/tutorials/wiki2/src/tests/tutorial/tests.py | 8 ++++++++ docs/tutorials/wiki2/src/views/tutorial/tests.py | 1 + 7 files changed, 18 insertions(+), 4 deletions(-) (limited to 'docs/tutorials/wiki2') 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/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/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/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/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(): -- cgit v1.2.3 From e91085ec75ddbeb793bec305eb693dad03c34518 Mon Sep 17 00:00:00 2001 From: Steve Johnson Date: Mon, 31 Dec 2012 10:28:16 -0800 Subject: Mention ZopeTxnExt and pyramid_tm in tutorial If this page is found via web search while trying to configure SQLAlchemy from scratch without a scaffold, it is helpful to mention pyramid_tm as a requirement somewhere. Otherwise, a hapless user such as your humble author might spend lots of time wondering why his sessions aren't getting committed after his requests despite his best efforts to properly configure SQLAlchemy and ZopeTransactionExtension. --- docs/tutorials/wiki2/installation.rst | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/installation.rst b/docs/tutorials/wiki2/installation.rst index 4ab02a13a..05b6a2a42 100644 --- a/docs/tutorials/wiki2/installation.rst +++ b/docs/tutorials/wiki2/installation.rst @@ -303,6 +303,9 @@ the following assumptions: - you are willing to use :term:`url dispatch` to map URLs to code. +- you want to use ``ZopeTransactionExtension`` and ``pyramid_tm`` to scope + sessions to requests + .. note:: :app:`Pyramid` supports any persistent storage mechanism (e.g. object -- cgit v1.2.3 From 043ccddb909327106264d10ed5d413760a51770d Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 2 Jan 2013 02:22:52 +0200 Subject: eliminate other repeated words --- docs/tutorials/wiki2/definingviews.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index 6b8689b5b..8714927c3 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -144,7 +144,7 @@ The ``check()`` function is used as the first argument to 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 @@ -358,7 +358,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. -- cgit v1.2.3 From fdc6975c2c1c2824dbbab543ddc62fc9e3d1655a Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 2 Jan 2013 22:27:50 +0200 Subject: Reduce duplicated installation instructions from the tutorials * This also removes the mention of running 'source bin/activate' (see #759). --- docs/tutorials/wiki2/installation.rst | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/installation.rst b/docs/tutorials/wiki2/installation.rst index 05b6a2a42..572bffcab 100644 --- a/docs/tutorials/wiki2/installation.rst +++ b/docs/tutorials/wiki2/installation.rst @@ -2,30 +2,22 @@ Installation ============ -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`. - Preparation =========== -Please take the following steps to prepare for the tutorial. The -steps are slightly different depending on whether you're using UNIX or -Windows. +Follow the steps in :ref:`installing_chapter`, but name the virtualenv +directory ``pyramidtut``. Preparation, UNIX ----------------- #. Install SQLite3 and its development packages if you don't already have them installed. Usually this is via your system's package - manager. For example, on a Debian Linux system, do ``sudo apt-get - install libsqlite3-dev``. - -#. Use your Python's virtualenv to make a workspace: + manager. On a Debian system, this would be: .. code-block:: text - $ path/to/my/Python-2.6/bin/virtualenv --no-site-packages pyramidtut + $ sudo apt-get install libsqlite3-dev #. Switch to the ``pyramidtut`` directory: @@ -33,35 +25,16 @@ Preparation, UNIX $ cd pyramidtut -#. Use ``easy_install`` to get :app:`Pyramid` and its direct - dependencies installed: - - .. code-block:: text - - $ bin/easy_install pyramid Preparation, Windows -------------------- -#. Use your Python's virtualenv to make a workspace: - - .. code-block:: text - - c:\> c:\Python26\Scripts\virtualenv --no-site-packages pyramidtut - #. Switch to the ``pyramidtut`` directory: .. code-block:: text c:\> cd pyramidtut -#. Use ``easy_install`` to get :app:`Pyramid` and its direct - dependencies installed: - - .. code-block:: text - - c:\pyramidtut> Scripts\easy_install pyramid - .. _sql_making_a_project: Making a Project -- cgit v1.2.3 From f65e191ed7da0ff97638879cf854c0b1cb505aaa Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 2 Jan 2013 23:09:40 +0200 Subject: typos --- docs/tutorials/wiki2/basiclayout.rst | 2 +- docs/tutorials/wiki2/installation.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index 763deaa32..e8874784c 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -97,7 +97,7 @@ 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 +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 path (e.g. the ``/foo`` in ``/static/foo``) will be used to compose a path to a static file resource, such as a CSS file. diff --git a/docs/tutorials/wiki2/installation.rst b/docs/tutorials/wiki2/installation.rst index 572bffcab..1e47e18c3 100644 --- a/docs/tutorials/wiki2/installation.rst +++ b/docs/tutorials/wiki2/installation.rst @@ -159,7 +159,7 @@ On Windows: .. code-block:: text - c:\pyramidtut\tutorial> ..\Scripts\nosetests --cover-package=tutorial ^ + c:\pyramidtut\tutorial> ..\Scripts\nosetests --cover-package=tutorial \ --cover-erase --with-coverage If successful, you will see output something like this:: -- cgit v1.2.3 From d695783b9adfe7c57c639e120c55c233c2979bc0 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 5 Jan 2013 01:02:38 +0200 Subject: typo --- docs/tutorials/wiki2/definingmodels.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 2148582f1..d42ed0814 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -31,7 +31,7 @@ following: (The highlighted lines are the ones that need to be changed.) -The first thing we've done is to do is remove the stock ``MyModel`` class +The first thing we've done is remove the stock ``MyModel`` class from the generated ``models.py`` file. The ``MyModel`` class is only a sample and we're not going to use it. -- cgit v1.2.3 From af1a96331c8de1e4ccc7eebba6f21974d21ebed6 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 5 Jan 2013 01:40:32 +0200 Subject: Reduce duplicated content in wiki2 tutorial --- docs/tutorials/wiki2/definingmodels.rst | 22 ++++++---------------- docs/tutorials/wiki2/installation.rst | 6 ++++++ 2 files changed, 12 insertions(+), 16 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index 2148582f1..cfa80aa42 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -77,25 +77,15 @@ following: (Only the highlighted lines need to be changed.) -Reinitializing the Database ---------------------------- +Installing the Project and re-initializing the Database +------------------------------------------------------- + +Redo the steps in :ref:`installing_project_in_dev_mode`. Because our model has changed, in order to reinitialize the database, we need to rerun the ``initialize_tutorial_db`` command to pick up the changes you've made -to both the models.py file and to the initializedb.py file. From the root of the -``tutorial`` project, directory execute the following commands. - -On UNIX: - -.. code-block:: text - - $ ../bin/initialize_tutorial_db development.ini - -On Windows: - -.. code-block:: text - - c:\pyramidtut\tutorial> ..\Scripts\initialize_tutorial_db development.ini +to both the models.py file and to the initializedb.py file. +See :ref:`initialize_db_wiki2` for instructions. Success will look something like this:: diff --git a/docs/tutorials/wiki2/installation.rst b/docs/tutorials/wiki2/installation.rst index 572bffcab..d4d5c0cce 100644 --- a/docs/tutorials/wiki2/installation.rst +++ b/docs/tutorials/wiki2/installation.rst @@ -66,6 +66,9 @@ On Windows: startup problems, try putting both the virtualenv and the project into directories that do not contain spaces in their paths. + +.. _installing_project_in_dev_mode: + Installing the Project in "Development Mode" ============================================ @@ -181,6 +184,9 @@ If successful, you will see output something like this:: Looks like our package doesn't quite have 100% test coverage. + +.. _initialize_db_wiki2: + Initializing the Database ========================= -- cgit v1.2.3 From fe197640038f0aa18a8d453e820df9e1b2d1bee7 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 5 Jan 2013 15:18:36 +0200 Subject: typo --- docs/tutorials/wiki2/authorization.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index d98fb87e4..cfbc8ca75 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -14,7 +14,7 @@ anyone with access to the server to view pages. We will also add a login page and a logout link on all the pages. The login page will be shown when a user is denied -access to any of the views that require a permission, instead of +access to any of the views that require permission, instead of a default "403 Forbidden" page. We will implement the access control with the following steps: -- cgit v1.2.3 From 064080f2496ef09eb79a0c370eb0db9dfd5c459c Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 5 Jan 2013 19:28:09 +0200 Subject: sentence too long; also fix grammar, and add markup --- docs/tutorials/wiki2/authorization.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index d98fb87e4..933c37f94 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -62,7 +62,7 @@ returns one of these values: - If the userid *does not* exist in the system, it will return ``None``. -For example, ``groupfinder('editor', request )`` returns ['group:editor'], +For example, ``groupfinder('editor', request )`` returns ``['group:editor']``, ``groupfinder('viewer', request)`` returns [], and ``groupfinder('admin', request)`` returns ``None``. We will use ``groupfinder()`` as an :term:`authentication policy` "callback" that will provide the :term:`principal` or principals @@ -151,10 +151,10 @@ Now add those policies to the configuration: (Only the highlighted lines need to be added.) -We are enabling an ``AuthTktAuthenticationPolicy``, it is based in an -auth ticket that may be included in the request, and an -``ACLAuthorizationPolicy`` that uses an ACL to determine the allow or deny -outcome for a view. +We are enabling an ``AuthTktAuthenticationPolicy``, which is based in an +auth ticket that may be included in the request. +We are also enabling an ``ACLAuthorizationPolicy``, which uses an ACL to +determine the *allow* or *deny* outcome for a view. Note that the :class:`pyramid.authentication.AuthTktAuthenticationPolicy` constructor accepts two arguments: ``secret`` and ``callback``. ``secret`` is -- cgit v1.2.3 From 97895f871d1e2bd168e4bfb29d61472a44d3b0e9 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 5 Jan 2013 20:14:25 +0200 Subject: no need to display the entire path --- docs/tutorials/wiki2/authorization.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index d98fb87e4..ff269ef6b 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -156,7 +156,7 @@ auth ticket that may be included in the request, and an ``ACLAuthorizationPolicy`` that uses an ACL to determine the allow or deny outcome for a view. -Note that the :class:`pyramid.authentication.AuthTktAuthenticationPolicy` +Note that the :class:`~pyramid.authentication.AuthTktAuthenticationPolicy` constructor accepts two arguments: ``secret`` and ``callback``. ``secret`` is a string representing an encryption key used by the "authentication ticket" machinery represented by this policy: it is required. The ``callback`` is the -- cgit v1.2.3 From 998b3970c98baa0c591507f94e6ec32b65969045 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sat, 5 Jan 2013 20:38:25 +0200 Subject: remove info that should be obvious to the reader --- docs/tutorials/wiki2/authorization.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index d98fb87e4..03a06e304 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -303,9 +303,8 @@ like this: (Only the highlighted line needs to be added.) -:meth:`~pyramid.security.authenticated_userid()` will return None -if the user is not authenticated, or some user id it the user -is authenticated. +The :meth:`~pyramid.security.authenticated_userid` method will return None +if the user is not authenticated. Add a "Logout" link when logged in ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3 From 168e94f0693600b122619222dd5cf2053b1d96ae Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sun, 6 Jan 2013 20:25:07 +0200 Subject: I have tested this on Python 3, and it works without modification --- docs/tutorials/wiki2/background.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/background.rst b/docs/tutorials/wiki2/background.rst index 9933adc27..1f9582903 100644 --- a/docs/tutorials/wiki2/background.rst +++ b/docs/tutorials/wiki2/background.rst @@ -11,9 +11,8 @@ To code along with this tutorial, the developer will need a UNIX machine with development tools (Mac OS X with XCode, any Linux or BSD variant, etc) *or* a Windows system of any kind. -.. warning:: +.. note:: - This tutorial has been written for Python 2. It is unlikely to work - without modification under Python 3. + This tutorial runs on both Python 2 and 3 without modification. Have fun! -- cgit v1.2.3 From 445eb8708fa48209947377f6de609799dd843ad6 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Sun, 20 Jan 2013 17:10:40 +0200 Subject: point to the sources of the wiki tutorials in just one location; fix #763 * This avoids having to update the link multiple times. * Also, mention their location, in case user has Pyramid checkout. --- docs/tutorials/wiki2/authorization.rst | 3 --- docs/tutorials/wiki2/basiclayout.rst | 3 --- docs/tutorials/wiki2/definingmodels.rst | 3 --- docs/tutorials/wiki2/definingviews.rst | 3 --- docs/tutorials/wiki2/index.rst | 6 +++--- docs/tutorials/wiki2/tests.rst | 3 --- 6 files changed, 3 insertions(+), 18 deletions(-) (limited to 'docs/tutorials/wiki2') diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index 321f1f9c4..5ede26920 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -36,9 +36,6 @@ Then we will add the login and logout feature: * Add a "Logout" link to be shown when logged in and viewing or editing a page (``view.pt``, ``edit.pt``). -The source code for this tutorial stage can be browsed at -`http://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src/authorization/ -`_. Access Control -------------- diff --git a/docs/tutorials/wiki2/basiclayout.rst b/docs/tutorials/wiki2/basiclayout.rst index e8874784c..68be4ee7c 100644 --- a/docs/tutorials/wiki2/basiclayout.rst +++ b/docs/tutorials/wiki2/basiclayout.rst @@ -6,9 +6,6 @@ The starter files generated by the ``alchemy`` scaffold are very basic, but they provide a good orientation for the high-level patterns common to most :term:`url dispatch` -based :app:`Pyramid` projects. -The source code for this tutorial stage can be browsed at -`http://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src/basiclayout/ -`_. Application Configuration with ``__init__.py`` ---------------------------------------------- diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index dca6238dd..bd1cb00d7 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -6,9 +6,6 @@ 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. -The source code for this tutorial stage can be browsed at -`http://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src/models/ -`_. Making Edits to ``models.py`` ----------------------------- diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index 8714927c3..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/ -`_. Declaring Dependencies in Our ``setup.py`` File =============================================== diff --git a/docs/tutorials/wiki2/index.rst b/docs/tutorials/wiki2/index.rst index bbc2fb96e..0a614cb23 100644 --- a/docs/tutorials/wiki2/index.rst +++ b/docs/tutorials/wiki2/index.rst @@ -9,9 +9,9 @@ tutorial is finished, the developer will have created a basic Wiki application with authentication. For cut and paste purposes, the source code for all stages of this -tutorial can be browsed at -`https://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src -`_. +tutorial can be browsed on GitHub at `docs/tutorials/wiki2/src +`_, +which corresponds to the same location if you have Pyramid sources. .. toctree:: :maxdepth: 2 diff --git a/docs/tutorials/wiki2/tests.rst b/docs/tutorials/wiki2/tests.rst index 6a7cbf62d..83df86b27 100644 --- a/docs/tutorials/wiki2/tests.rst +++ b/docs/tutorials/wiki2/tests.rst @@ -6,9 +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. -The source code for this tutorial stage can be browsed at -`http://github.com/Pylons/pyramid/tree/1.3-branch/docs/tutorials/wiki2/src/tests/ -`_. Testing the Models -- cgit v1.2.3