From 33768fb147c26d93b2894a3504bcb117319a3629 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Thu, 30 Aug 2018 03:49:21 -0700 Subject: Update quick_tutorial with starter cookiecutter source files --- docs/quick_tutorial/cookiecutters/cc_starter/__init__.py | 9 ++++----- docs/quick_tutorial/cookiecutters/cc_starter/routes.py | 3 +++ .../quick_tutorial/cookiecutters/cc_starter/templates/404.jinja2 | 8 ++++++++ docs/quick_tutorial/cookiecutters/cc_starter/tests.py | 2 +- docs/quick_tutorial/cookiecutters/cc_starter/views.py | 6 ------ docs/quick_tutorial/cookiecutters/cc_starter/views/__init__.py | 0 docs/quick_tutorial/cookiecutters/cc_starter/views/default.py | 6 ++++++ docs/quick_tutorial/cookiecutters/cc_starter/views/notfound.py | 7 +++++++ 8 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 docs/quick_tutorial/cookiecutters/cc_starter/routes.py create mode 100644 docs/quick_tutorial/cookiecutters/cc_starter/templates/404.jinja2 delete mode 100644 docs/quick_tutorial/cookiecutters/cc_starter/views.py create mode 100644 docs/quick_tutorial/cookiecutters/cc_starter/views/__init__.py create mode 100644 docs/quick_tutorial/cookiecutters/cc_starter/views/default.py create mode 100644 docs/quick_tutorial/cookiecutters/cc_starter/views/notfound.py (limited to 'docs/quick_tutorial/cookiecutters/cc_starter') diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/__init__.py b/docs/quick_tutorial/cookiecutters/cc_starter/__init__.py index 49dde36d4..a3d5a6469 100644 --- a/docs/quick_tutorial/cookiecutters/cc_starter/__init__.py +++ b/docs/quick_tutorial/cookiecutters/cc_starter/__init__.py @@ -4,9 +4,8 @@ from pyramid.config import Configurator def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ - config = Configurator(settings=settings) - config.include('pyramid_jinja2') - config.add_static_view('static', 'static', cache_max_age=3600) - config.add_route('home', '/') - config.scan() + with Configurator(settings=settings) as config: + config.include('pyramid_jinja2') + config.include('.routes') + config.scan() return config.make_wsgi_app() diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/routes.py b/docs/quick_tutorial/cookiecutters/cc_starter/routes.py new file mode 100644 index 000000000..25504ad4d --- /dev/null +++ b/docs/quick_tutorial/cookiecutters/cc_starter/routes.py @@ -0,0 +1,3 @@ +def includeme(config): + config.add_static_view('static', 'static', cache_max_age=3600) + config.add_route('home', '/') diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/templates/404.jinja2 b/docs/quick_tutorial/cookiecutters/cc_starter/templates/404.jinja2 new file mode 100644 index 000000000..aaf12413f --- /dev/null +++ b/docs/quick_tutorial/cookiecutters/cc_starter/templates/404.jinja2 @@ -0,0 +1,8 @@ +{% extends "layout.jinja2" %} + +{% block content %} +
+

Pyramid Starter project

+

404 Page Not Found

+
+{% endblock content %} diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/tests.py b/docs/quick_tutorial/cookiecutters/cc_starter/tests.py index 2f553bbb4..f3886be84 100644 --- a/docs/quick_tutorial/cookiecutters/cc_starter/tests.py +++ b/docs/quick_tutorial/cookiecutters/cc_starter/tests.py @@ -11,7 +11,7 @@ class ViewTests(unittest.TestCase): testing.tearDown() def test_my_view(self): - from .views import my_view + from .views.default import my_view request = testing.DummyRequest() info = my_view(request) self.assertEqual(info['project'], 'cc_starter') diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/views.py b/docs/quick_tutorial/cookiecutters/cc_starter/views.py deleted file mode 100644 index deedd53b8..000000000 --- a/docs/quick_tutorial/cookiecutters/cc_starter/views.py +++ /dev/null @@ -1,6 +0,0 @@ -from pyramid.view import view_config - - -@view_config(route_name='home', renderer='templates/mytemplate.jinja2') -def my_view(request): - return {'project': 'cc_starter'} diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/views/__init__.py b/docs/quick_tutorial/cookiecutters/cc_starter/views/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/views/default.py b/docs/quick_tutorial/cookiecutters/cc_starter/views/default.py new file mode 100644 index 000000000..47af359b5 --- /dev/null +++ b/docs/quick_tutorial/cookiecutters/cc_starter/views/default.py @@ -0,0 +1,6 @@ +from pyramid.view import view_config + + +@view_config(route_name='home', renderer='../templates/mytemplate.jinja2') +def my_view(request): + return {'project': 'cc_starter'} diff --git a/docs/quick_tutorial/cookiecutters/cc_starter/views/notfound.py b/docs/quick_tutorial/cookiecutters/cc_starter/views/notfound.py new file mode 100644 index 000000000..69d6e2804 --- /dev/null +++ b/docs/quick_tutorial/cookiecutters/cc_starter/views/notfound.py @@ -0,0 +1,7 @@ +from pyramid.view import notfound_view_config + + +@notfound_view_config(renderer='../templates/404.jinja2') +def notfound_view(request): + request.response.status = 404 + return {} -- cgit v1.2.3