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. --- .../wiki2/src/basiclayout/tutorial/views.py | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'docs/tutorials/wiki2/src/basiclayout') 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. +""" + -- cgit v1.2.3