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

1
development.ini

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

8
ordr/__init__.py

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

3
ordr/routes.py

@ -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):
def test_passing_view(self): def test_passing_view(self):
from .views.default import my_view 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['one'].name, 'one')
self.assertEqual(info['project'], 'Ordr') self.assertEqual(info['project'], 'Ordr')
@ -61,5 +61,5 @@ class TestMyViewFailureCondition(BaseTest):
def test_failing_view(self): def test_failing_view(self):
from .views.default import my_view 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) self.assertEqual(info.status_int, 500)

4
ordr/views/default.py

@ -6,8 +6,8 @@ from sqlalchemy.exc import DBAPIError
from ..models import MyModel from ..models import MyModel
@view_config(route_name='home', renderer='../templates/mytemplate.jinja2') @view_config(context=dict, renderer='../templates/mytemplate.jinja2')
def my_view(request): def my_view(context, request):
try: try:
query = request.dbsession.query(MyModel) query = request.dbsession.query(MyModel)
one = query.filter(MyModel.name == 'one').first() one = query.filter(MyModel.name == 'one').first()