Browse Source

cleanup of views and templates

rework
Holger Frey 7 years ago
parent
commit
bd8e3557aa
  1. 2
      ordr/templates/errors/404.jinja2
  2. 2
      ordr/templates/pages/welcome.jinja2
  3. 33
      ordr/views/default.py
  4. 7
      ordr/views/errors.py
  5. 7
      ordr/views/notfound.py
  6. 14
      ordr/views/public.py

2
ordr/templates/404.jinja2 → ordr/templates/errors/404.jinja2

@ -1,4 +1,4 @@
{% extends "layout.jinja2" %} {% extends "ordr:templates/layout.jinja2" %}
{% block content %} {% block content %}
<div class="content"> <div class="content">

2
ordr/templates/mytemplate.jinja2 → ordr/templates/pages/welcome.jinja2

@ -1,4 +1,4 @@
{% extends "layout.jinja2" %} {% extends "ordr:templates/layout.jinja2" %}
{% block content %} {% block content %}
<div class="content"> <div class="content">

33
ordr/views/default.py

@ -1,33 +0,0 @@
from pyramid.response import Response
from pyramid.view import view_config
from sqlalchemy.exc import DBAPIError
from ..models import MyModel
@view_config(context=dict, renderer='../templates/mytemplate.jinja2')
def my_view(context, request):
try:
query = request.dbsession.query(MyModel)
one = query.filter(MyModel.name == 'one').first()
except DBAPIError:
return Response(db_err_msg, content_type='text/plain', status=500)
return {'one': one, 'project': 'Ordr'}
db_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_ordr_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.
"""

7
ordr/views/errors.py

@ -0,0 +1,7 @@
from pyramid.view import notfound_view_config
@notfound_view_config(renderer='ordr:templates/errors/404.jinja2')
def notfound_view(context, request):
request.response.status = 404
return {}

7
ordr/views/notfound.py

@ -1,7 +0,0 @@
from pyramid.view import notfound_view_config
@notfound_view_config(renderer='../templates/404.jinja2')
def notfound_view(request):
request.response.status = 404
return {}

14
ordr/views/public.py

@ -0,0 +1,14 @@
from pyramid.response import Response
from pyramid.view import view_config
from sqlalchemy.exc import DBAPIError
from ..models import MyModel
@view_config(
context='ordr.resources.RootResource',
renderer='ordr:templates/pages/welcome.jinja2'
)
def home(context, request):
return {}