Browse Source

changed routing to traversal

rework
Holger Frey 7 years ago
parent
commit
fb0dab46a4
  1. 4
      .gitignore
  2. 1
      development.ini
  3. 8
      ordr/__init__.py
  4. 3
      ordr/routes.py
  5. 4
      ordr/tests.py
  6. 4
      ordr/views/default.py

4
.gitignore vendored

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
# database
ordr.sqlite
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
@ -35,6 +38,7 @@ pip-log.txt @@ -35,6 +38,7 @@ pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
.pytest_cache
htmlcov/
.tox/
.coverage

1
development.ini

@ -13,6 +13,7 @@ pyramid.debug_routematch = false @@ -13,6 +13,7 @@ pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
pyramid_listing
sqlalchemy.url = sqlite:///%(here)s/ordr.sqlite

8
ordr/__init__.py

@ -1,12 +1,18 @@ @@ -1,12 +1,18 @@
from pyramid.config import Configurator
def root_factory(request):
''' dummy root factory '''
return dict()
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings)
config.include('pyramid_jinja2')
config.include('.models')
config.include('.routes')
config.add_static_view('static', 'static', cache_max_age=3600)
config.set_root_factory(root_factory)
config.scan()
return config.make_wsgi_app()

3
ordr/routes.py

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
def includeme(config):
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')

4
ordr/tests.py

@ -52,7 +52,7 @@ class TestMyViewSuccessCondition(BaseTest): @@ -52,7 +52,7 @@ class TestMyViewSuccessCondition(BaseTest):
def test_passing_view(self):
from .views.default import my_view
info = my_view(dummy_request(self.session))
info = my_view(None, dummy_request(self.session))
self.assertEqual(info['one'].name, 'one')
self.assertEqual(info['project'], 'Ordr')
@ -61,5 +61,5 @@ class TestMyViewFailureCondition(BaseTest): @@ -61,5 +61,5 @@ class TestMyViewFailureCondition(BaseTest):
def test_failing_view(self):
from .views.default import my_view
info = my_view(dummy_request(self.session))
info = my_view(None, dummy_request(self.session))
self.assertEqual(info.status_int, 500)

4
ordr/views/default.py

@ -6,8 +6,8 @@ from sqlalchemy.exc import DBAPIError @@ -6,8 +6,8 @@ from sqlalchemy.exc import DBAPIError
from ..models import MyModel
@view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
def my_view(request):
@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()