diff options
| author | Chris McDonough <chrism@plope.com> | 2012-02-14 05:57:06 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-02-14 05:57:06 -0500 |
| commit | c6a299ad7159ffcabe201fa79f485c388d837971 (patch) | |
| tree | f4a5cec04ed8783516dadd646e2d0ccf41570fca /docs | |
| parent | c595946b859e48ea506dd3155da935eba10a1ed7 (diff) | |
| download | pyramid-c6a299ad7159ffcabe201fa79f485c388d837971.tar.gz pyramid-c6a299ad7159ffcabe201fa79f485c388d837971.tar.bz2 pyramid-c6a299ad7159ffcabe201fa79f485c388d837971.zip | |
- Don't create a ``session`` instance in SQLA Wiki tutorial, use raw
``DBSession`` instead (this is more common in real SQLA apps).
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/tutorials/wiki2/authorization.rst | 4 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/definingviews.rst | 8 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/authorization/tutorial/views.py | 13 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/views/tutorial/views.py | 13 |
4 files changed, 16 insertions, 22 deletions
diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index 56237a1b9..b1d0bf37c 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -159,14 +159,14 @@ logged in user and redirect back to the front page. The ``login`` view callable will look something like this: .. literalinclude:: src/authorization/tutorial/views.py - :lines: 90-116 + :lines: 87-113 :linenos: :language: python The ``logout`` view callable will look something like this: .. literalinclude:: src/authorization/tutorial/views.py - :lines: 118-122 + :lines: 115-119 :linenos: :language: python diff --git a/docs/tutorials/wiki2/definingviews.rst b/docs/tutorials/wiki2/definingviews.rst index bda0a2eb7..a067dbd66 100644 --- a/docs/tutorials/wiki2/definingviews.rst +++ b/docs/tutorials/wiki2/definingviews.rst @@ -126,7 +126,7 @@ HTML anchor for each *WikiWord* reference in the rendered HTML using a compiled regular expression. .. literalinclude:: src/views/tutorial/views.py - :lines: 23-44 + :lines: 23-43 :linenos: :language: python @@ -161,7 +161,7 @@ The ``matchdict`` attribute of the request passed to the ``add_page`` view will have the values we need to construct URLs and find model objects. .. literalinclude:: src/views/tutorial/views.py - :lines: 46-58 + :lines: 45-56 :linenos: :language: python @@ -184,7 +184,7 @@ If the view execution *is* a result of a form submission (if 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 -``session.add``. We then redirect back to the ``view_page`` view for the +``DBSession.add``. We then redirect back to the ``view_page`` view for the newly created page. The ``edit_page`` view function @@ -197,7 +197,7 @@ request passed to the ``edit_page`` view will have a ``'pagename'`` key matching the name of the page the user wants to edit. .. literalinclude:: src/views/tutorial/views.py - :lines: 60-73 + :lines: 58-70 :linenos: :language: python diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/views.py b/docs/tutorials/wiki2/src/authorization/tutorial/views.py index 375f1f5a5..087e6076b 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/views.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/views.py @@ -33,14 +33,13 @@ def view_wiki(request): @view_config(route_name='view_page', renderer='templates/view.pt') 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 '<a href="%s">%s</a>' % (view_url, word) @@ -59,10 +58,9 @@ def view_page(request): def add_page(request): name = request.matchdict['pagename'] if 'form.submitted' in request.params: - session = DBSession() body = request.params['body'] page = Page(name, body) - session.add(page) + DBSession.add(page) return HTTPFound(location = request.route_url('view_page', pagename=name)) save_url = request.route_url('add_page', pagename=name) @@ -74,11 +72,10 @@ def add_page(request): permission='edit') def edit_page(request): name = request.matchdict['pagename'] - session = DBSession() - page = session.query(Page).filter_by(name=name).one() + page = DBSession.query(Page).filter_by(name=name).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=name)) return dict( diff --git a/docs/tutorials/wiki2/src/views/tutorial/views.py b/docs/tutorials/wiki2/src/views/tutorial/views.py index 5c49dd2e8..c2a94a96b 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/views.py +++ b/docs/tutorials/wiki2/src/views/tutorial/views.py @@ -23,14 +23,13 @@ def view_wiki(request): @view_config(route_name='view_page', renderer='templates/view.pt') 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 '<a href="%s">%s</a>' % (view_url, word) @@ -47,10 +46,9 @@ def view_page(request): def add_page(request): name = request.matchdict['pagename'] if 'form.submitted' in request.params: - session = DBSession() body = request.params['body'] page = Page(name, body) - session.add(page) + DBSession.add(page) return HTTPFound(location = request.route_url('view_page', pagename=name)) save_url = request.route_url('add_page', pagename=name) @@ -60,11 +58,10 @@ def add_page(request): @view_config(route_name='edit_page', renderer='templates/edit.pt') def edit_page(request): name = request.matchdict['pagename'] - session = DBSession() - page = session.query(Page).filter_by(name=name).one() + page = DBSession.query(Page).filter_by(name=name).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=name)) return dict( |
