diff options
| author | Chris McDonough <chrism@plope.com> | 2011-06-11 05:43:16 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-06-11 05:43:16 -0400 |
| commit | a4d5525cdbb6b7e614939b20a340b989258779ca (patch) | |
| tree | 666586b1a0293a04fe3ed4bc27eeddbd680e4311 /docs/tutorials/wiki2/src/views | |
| parent | aee35e30083acd3d3c84e7f50db1f17bf6dc2d12 (diff) | |
| parent | b1b9f99e9a2e249cff61f4ccc0ecf10ac734fa08 (diff) | |
| download | pyramid-a4d5525cdbb6b7e614939b20a340b989258779ca.tar.gz pyramid-a4d5525cdbb6b7e614939b20a340b989258779ca.tar.bz2 pyramid-a4d5525cdbb6b7e614939b20a340b989258779ca.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
Diffstat (limited to 'docs/tutorials/wiki2/src/views')
| -rw-r--r-- | docs/tutorials/wiki2/src/views/tutorial/models.py | 5 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/views/tutorial/views.py | 13 |
2 files changed, 10 insertions, 8 deletions
diff --git a/docs/tutorials/wiki2/src/views/tutorial/models.py b/docs/tutorials/wiki2/src/views/tutorial/models.py index 23b8afab8..960c14941 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/models.py +++ b/docs/tutorials/wiki2/src/views/tutorial/models.py @@ -23,14 +23,15 @@ class Page(Base): data = Column(Text) def __init__(self, name, data): - self.name = name - self.data = data + self.name = name + self.data = data def initialize_sql(engine): DBSession.configure(bind=engine) Base.metadata.bind = engine Base.metadata.create_all(engine) try: + transaction.begin() session = DBSession() page = Page('FrontPage', 'initial data') session.add(page) diff --git a/docs/tutorials/wiki2/src/views/tutorial/views.py b/docs/tutorials/wiki2/src/views/tutorial/views.py index b8896abe7..f3d7f4a99 100644 --- a/docs/tutorials/wiki2/src/views/tutorial/views.py +++ b/docs/tutorials/wiki2/src/views/tutorial/views.py @@ -2,7 +2,7 @@ import re from docutils.core import publish_parts -from pyramid.httpexceptions import HTTPFound +from pyramid.httpexceptions import HTTPFound, HTTPNotFound from pyramid.url import route_url from tutorial.models import DBSession @@ -16,9 +16,11 @@ def view_wiki(request): pagename='FrontPage')) def view_page(request): - matchdict = request.matchdict + pagename = request.matchdict['pagename'] session = DBSession() - page = session.query(Page).filter_by(name=matchdict['pagename']).one() + page = session.query(Page).filter_by(name=pagename).first() + if page is None: + return HTTPNotFound('No such page') def check(match): word = match.group(1) @@ -32,8 +34,7 @@ def view_page(request): content = publish_parts(page.data, writer_name='html')['html_body'] content = wikiwords.sub(check, content) - edit_url = route_url('edit_page', request, - pagename=matchdict['pagename']) + edit_url = route_url('edit_page', request, pagename=pagename) return dict(page=page, content=content, edit_url=edit_url) def add_page(request): @@ -48,7 +49,7 @@ def add_page(request): save_url = route_url('add_page', request, pagename=name) page = Page('', '') return dict(page=page, save_url=save_url) - + def edit_page(request): name = request.matchdict['pagename'] session = DBSession() |
