Merge pull request #3338 from Pylons/docs-cc-update-for-1.10
Update docs for all cookiecutters
5 files deleted
53 files added
88 files modified
2 files renamed
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | 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() |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.add_route('home', '/') |
New file |
| | |
| | | {% extends "layout.jinja2" %} |
| | | |
| | | {% block content %} |
| | | <div class="content"> |
| | | <h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Starter project</span></h1> |
| | | <p class="lead"><span class="font-semi-bold">404</span> Page Not Found</p> |
| | | </div> |
| | | {% endblock content %} |
| | |
| | | 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'], 'MyProject') |
New file |
| | |
| | | from pyramid.view import view_config |
| | | |
| | | |
| | | @view_config(route_name='home', renderer='../templates/mytemplate.jinja2') |
| | | def my_view(request): |
| | | return {'project': 'myproject'} |
New file |
| | |
| | | from pyramid.view import notfound_view_config |
| | | |
| | | |
| | | @notfound_view_config(renderer='../templates/404.jinja2') |
| | | def notfound_view(request): |
| | | request.response.status = 404 |
| | | return {} |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | |
| | | .. code-block:: text |
| | | |
| | | myproject/ |
| | | myproject |
| | | ├── .coveragerc |
| | | ├── .gitignore |
| | | ├── CHANGES.txt |
| | | ├── MANIFEST.in |
| | | ├── myproject |
| | | │  ├── __init__.py |
| | | │  ├── routes.py |
| | | │  ├── static |
| | | │  │  ├── pyramid-16x16.png |
| | | │  │  ├── pyramid.png |
| | | │  │  └── theme.css |
| | | │  ├── templates |
| | | │  │  ├── 404.jinja2 |
| | | │  │  ├── layout.jinja2 |
| | | │  │  └── mytemplate.jinja2 |
| | | │  ├── tests.py |
| | | │  └── views.py |
| | | │  └── views |
| | | │  ├── __init__.py |
| | | │  ├── default.py |
| | | │  └── notfound.py |
| | | ├── README.txt |
| | | ├── development.ini |
| | | ├── production.ini |
| | |
| | | describe, run, and test your application. |
| | | |
| | | #. ``.coveragerc`` configures coverage when running tests. |
| | | |
| | | #. ``.gitignore`` tells git which files and directories to ignore from source code version control. |
| | | |
| | | #. ``CHANGES.txt`` describes the changes you've made to the application. It is |
| | | conventionally written in :term:`reStructuredText` format. |
| | |
| | | |
| | | #. A ``tests.py`` module, which contains unit test code for the application. |
| | | |
| | | #. A ``views.py`` module, which contains view code for the application. |
| | | #. A ``views`` package, which contains view code for the application. |
| | | |
| | | #. A ``static`` directory, which contains static files, including images and CSS. |
| | | |
| | | These are purely conventions established by the cookiecutter. :app:`Pyramid` |
| | | doesn't insist that you name things in any particular way. However, it's |
| | |
| | | Line 8 adds support for Jinja2 templating bindings, allowing us to |
| | | specify renderers with the ``.jinja2`` extension. |
| | | |
| | | Line 9 registers a static view, which will serve up the files from the |
| | | ``myproject:static`` :term:`asset specification` (the ``static`` directory |
| | | of the ``myproject`` package). |
| | | Line 9 includes the ``routes.py`` module. |
| | | |
| | | Line 10 adds a :term:`route` to the configuration. This route is later used |
| | | by a view in the ``views`` module. |
| | | |
| | | Line 11 calls ``config.scan()``, which picks up view registrations declared |
| | | Line 10 calls ``config.scan()``, which picks up view registrations declared |
| | | elsewhere in the package (in this case, in the ``views.py`` module). |
| | | |
| | | Line 12 returns a :term:`WSGI` application to the caller of the function |
| | | Line 11 returns a :term:`WSGI` application to the caller of the function |
| | | (Pyramid's pserve). |
| | | |
| | | |
| | | .. index:: |
| | | single: routes.py |
| | | |
| | | .. _routes_py: |
| | | |
| | | ``routes.py`` |
| | | ~~~~~~~~~~~~~ |
| | | |
| | | The ``routes.py`` module gets included by the ``main`` function in our ``__init__.py``. |
| | | It registers a view and a route. |
| | | |
| | | .. literalinclude:: myproject/myproject/routes.py |
| | | :language: python |
| | | :linenos: |
| | | |
| | | Line 2 registers a static view, which will serve up the files from the ``myproject:static`` :term:`asset specification` (the ``static`` directory of the ``myproject`` package). |
| | | |
| | | Line 3 adds a :term:`route` to the configuration. This route is later used by a view in the ``views`` module. |
| | | |
| | | |
| | | .. index:: |
| | | single: views.py |
| | | |
| | | ``views.py`` |
| | | ~~~~~~~~~~~~ |
| | | ``views`` package |
| | | ~~~~~~~~~~~~~~~~~ |
| | | |
| | | Much of the heavy lifting in a :app:`Pyramid` application is done by *view |
| | | callables*. A :term:`view callable` is the main tool of a :app:`Pyramid` web |
| | | application developer; it is a bit of code which accepts a :term:`request` and |
| | | which returns a :term:`response`. |
| | | |
| | | .. literalinclude:: myproject/myproject/views.py |
| | | Our project has a ``views`` package by virtue of it being a directory containing an ``__init__.py`` file. |
| | | This ``__init__.py`` file happens to have no content, although it could as a project develops. |
| | | |
| | | We have two view modules in the ``views`` package. |
| | | Let's look at ``default.py``. |
| | | |
| | | .. literalinclude:: myproject/myproject/views/default.py |
| | | :language: python |
| | | :linenos: |
| | | |
| | |
| | | function named ``my_view`` is decorated with a ``view_config`` decorator (which |
| | | is processed by the ``config.scan()`` line in our ``__init__.py``). The |
| | | view_config decorator asserts that this view be found when a :term:`route` |
| | | named ``home`` is matched. In our case, because our ``__init__.py`` maps the |
| | | named ``home`` is matched. In our case, because our ``routes.py`` maps the |
| | | route named ``home`` to the URL pattern ``/``, this route will match when a |
| | | visitor visits the root URL. The view_config decorator also names a |
| | | ``renderer``, which in this case is a template that will be used to render the |
| | | result of the view callable. This particular view declaration points at |
| | | ``templates/mytemplate.pt``, which is an :term:`asset specification` that |
| | | specifies the ``mytemplate.pt`` file within the ``templates`` directory of the |
| | | ``../templates/mytemplate.jinja2``, which is an :term:`asset specification` that |
| | | specifies the ``mytemplate.jinja2`` file within the ``templates`` directory of the |
| | | ``myproject`` package. The asset specification could have also been specified |
| | | as ``myproject:templates/mytemplate.pt``; the leading package name and colon is |
| | | as ``myproject:templates/mytemplate.jinja2``; the leading package name and colon is |
| | | optional. The template file pointed to is a :term:`Jinja2` template |
| | | file (``templates/my_template.jinja2``). |
| | | file (``templates/mytemplate.jinja2``). |
| | | |
| | | This view callable function is handed a single piece of information: the |
| | | :term:`request`. The *request* is an instance of the :term:`WebOb` ``Request`` |
| | |
| | | the HTML in a :term:`response`. |
| | | |
| | | .. note:: Dictionaries provide values to :term:`template`\s. |
| | | |
| | | Now let's look at ``notfound.py``. |
| | | |
| | | .. literalinclude:: myproject/myproject/views/notfound.py |
| | | :language: python |
| | | :linenos: |
| | | |
| | | This file is similar to ``default.py``. |
| | | It merely returns a ``404`` response status and an empty dictionary to the template at ``../templates/404.jinja2``. |
| | | |
| | | .. note:: When the application is run with the cookiecutter's :ref:`default |
| | | development.ini <myproject_ini>` configuration, :ref:`logging is set up |
| | |
| | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | This is the content :term:`Jinja2` template that exists in the project. It is referenced by the call to ``@view_config`` as the ``renderer`` |
| | | of the ``my_view`` view callable in the ``views.py`` file. See |
| | | of the ``my_view`` view callable in the ``views/default.py`` file. See |
| | | :ref:`views_which_use_a_renderer` for more information about renderers. It inherits ("extends") the HTML provided by ``layout.jinja2``, replacing the content block with its own content. |
| | | |
| | | .. literalinclude:: myproject/myproject/templates/mytemplate.jinja2 |
| | |
| | | Templates are accessed and used by view configurations and sometimes by view |
| | | functions themselves. See :ref:`templates_used_directly` and |
| | | :ref:`templates_used_as_renderers`. |
| | | |
| | | |
| | | ``templates/404.jinja2`` |
| | | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | This template is similar to ``mytemplate.jinja2``, but with a few differences. |
| | | It is referenced by the call to ``@notfound_view_config`` as the ``renderer`` of the ``notfound_view`` view callable in the ``views/notfound.py`` file. |
| | | It inherits the HTML provided by ``layout.jinja2``, replacing the content block with its own content. |
| | | |
| | | .. literalinclude:: myproject/myproject/templates/404.jinja2 |
| | | :language: jinja |
| | | :linenos: |
| | | |
| | | |
| | | .. index:: |
| | |
| | | For example, the configuration method named |
| | | :meth:`~pyramid.config.Configurator.add_view` requires you to pass a |
| | | :term:`dotted Python name` or a direct object reference as the class or |
| | | function to be used as a view. By default, the ``starter`` cookiecutter would have |
| | | you add view functions to the ``views.py`` module in your package. However, you |
| | | might be more comfortable creating a ``views`` *directory*, and adding a single |
| | | file for each view. |
| | | function to be used as a view. |
| | | By default, the ``starter`` cookiecutter would have you create a ``views`` directory, and add a single file for each view or collection of related views. |
| | | However, you might be more comfortable creating a single ``views.py`` module in your package and add view functions to it. |
| | | |
| | | If your project package name was ``myproject`` and you wanted to arrange all |
| | | your views in a Python subpackage within the ``myproject`` :term:`package` |
| | | named ``views`` instead of within a single ``views.py`` file, you might do the |
| | | following. |
| | | |
| | | - Create a ``views`` directory inside your ``myproject`` package directory (the |
| | | same directory which holds ``views.py``). |
| | | |
| | | - Create a file within the new ``views`` directory named ``__init__.py``. (It |
| | | can be empty. This just tells Python that the ``views`` directory is a |
| | | *package*.) |
| | | |
| | | - *Move* the content from the existing ``views.py`` file to a file inside the |
| | | new ``views`` directory named, say, ``blog.py``. Because the ``templates`` |
| | | directory remains in the ``myproject`` package, the template :term:`asset |
| | | specification` values in ``blog.py`` must now be fully qualified with the |
| | | project's package name (``myproject:templates/blog.pt``). |
| | | |
| | | You can then continue to add view callable functions to the ``blog.py`` module, |
| | | but you can also add other ``.py`` files which contain view callable functions |
| | | to the ``views`` directory. As long as you use the ``@view_config`` directive |
| | | Whatever structure you prefer, as long as you use the ``@view_config`` directive |
| | | to register views in conjunction with ``config.scan()``, they will be picked up |
| | | automatically when the application is restarted. |
| | | |
| | |
| | | $VENV/bin/pip install -e ".[testing]" |
| | | |
| | | In your ``MyPackage`` project, your :term:`package` is named ``myproject`` |
| | | which contains a ``views`` module, which in turn contains a :term:`view` |
| | | which contains a ``views`` package containing a ``default.py`` module, which in turn contains a :term:`view` |
| | | function ``my_view`` that returns an HTML body when the root URL is invoked: |
| | | |
| | | .. literalinclude:: myproject/myproject/views.py |
| | | .. literalinclude:: myproject/myproject/views/default.py |
| | | :linenos: |
| | | :language: python |
| | | |
| | |
| | | Maybe you would like to log messages in your code? In your Python module, |
| | | import and set up the logging in your ``views.py``: |
| | | |
| | | .. literalinclude:: quick_tour/logging/hello_world/views.py |
| | | .. literalinclude:: quick_tour/logging/hello_world/views/default.py |
| | | :language: python |
| | | :lineno-match: |
| | | :lines: 3-4 |
| | | |
| | | You can now, in your code, log messages: |
| | | |
| | | .. literalinclude:: quick_tour/logging/hello_world/views.py |
| | | .. literalinclude:: quick_tour/logging/hello_world/views/default.py |
| | | :language: python |
| | | :lineno-match: |
| | | :lines: 7-8 |
| | |
| | | .. literalinclude:: quick_tour/sessions/hello_world/__init__.py |
| | | :language: python |
| | | :lineno-match: |
| | | :lines: 10-13 |
| | | :lines: 9-12 |
| | | :emphasize-lines: 2-3 |
| | | |
| | | Pyramid's :term:`request` object now has a ``session`` attribute that we can |
| | | use in our view code in ``views.py``: |
| | | |
| | | .. literalinclude:: quick_tour/sessions/hello_world/views.py |
| | | .. literalinclude:: quick_tour/sessions/hello_world/views/default.py |
| | | :language: python |
| | | :lineno-match: |
| | | :lines: 7- |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | 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() |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.add_route('home', '/') |
New file |
| | |
| | | {% extends "layout.jinja2" %} |
| | | |
| | | {% block content %} |
| | | <div class="content"> |
| | | <h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Starter project</span></h1> |
| | | <p class="lead"><span class="font-semi-bold">404</span> Page Not Found</p> |
| | | </div> |
| | | {% endblock content %} |
| | |
| | | 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'], 'hello_world') |
File was renamed from docs/quick_tour/logging/hello_world/views.py |
| | |
| | | import logging |
| | | log = logging.getLogger(__name__) |
| | | |
| | | @view_config(route_name='home', renderer='templates/mytemplate.jinja2') |
| | | @view_config(route_name='home', renderer='../templates/mytemplate.jinja2') |
| | | def my_view(request): |
| | | log.debug('Some Message') |
| | | return {'project': 'hello_world'} |
New file |
| | |
| | | from pyramid.view import notfound_view_config |
| | | |
| | | |
| | | @notfound_view_config(renderer='../templates/404.jinja2') |
| | | def notfound_view(request): |
| | | request.response.status = 404 |
| | | return {} |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | 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() |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.add_route('home', '/') |
New file |
| | |
| | | {% extends "layout.jinja2" %} |
| | | |
| | | {% block content %} |
| | | <div class="content"> |
| | | <h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Starter project</span></h1> |
| | | <p class="lead"><span class="font-semi-bold">404</span> Page Not Found</p> |
| | | </div> |
| | | {% endblock content %} |
| | |
| | | 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'], 'hello_world') |
New file |
| | |
| | | from pyramid.view import view_config |
| | | |
| | | |
| | | @view_config(route_name='home', renderer='../templates/mytemplate.jinja2') |
| | | def my_view(request): |
| | | return {'project': 'hello_world'} |
New file |
| | |
| | | from pyramid.view import notfound_view_config |
| | | |
| | | |
| | | @notfound_view_config(renderer='../templates/404.jinja2') |
| | | def notfound_view(request): |
| | | request.response.status = 404 |
| | | return {} |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | 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', '/') |
| | | my_session_factory = SignedCookieSessionFactory('itsaseekreet') |
| | | config.set_session_factory(my_session_factory) |
| | | config.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.routes') |
| | | my_session_factory = SignedCookieSessionFactory('itsaseekreet') |
| | | config.set_session_factory(my_session_factory) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.add_route('home', '/') |
New file |
| | |
| | | {% extends "layout.jinja2" %} |
| | | |
| | | {% block content %} |
| | | <div class="content"> |
| | | <h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Starter project</span></h1> |
| | | <p class="lead"><span class="font-semi-bold">404</span> Page Not Found</p> |
| | | </div> |
| | | {% endblock content %} |
| | |
| | | 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'], 'hello_world') |
File was renamed from docs/quick_tour/sessions/hello_world/views.py |
| | |
| | | import logging |
| | | log = logging.getLogger(__name__) |
| | | |
| | | @view_config(route_name='home', renderer='templates/mytemplate.jinja2') |
| | | @view_config(route_name='home', renderer='../templates/mytemplate.jinja2') |
| | | def my_view(request): |
| | | log.debug('Some Message') |
| | | session = request.session |
New file |
| | |
| | | from pyramid.view import notfound_view_config |
| | | |
| | | |
| | | @notfound_view_config(renderer='../templates/404.jinja2') |
| | | def notfound_view(request): |
| | | request.response.status = 404 |
| | | return {} |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | |
| | | env/bin/pip install -e ".[testing]" |
| | | |
| | | - Configure the database. |
| | | - Initialize and upgrade the database using Alembic. |
| | | |
| | | - Generate your first revision. |
| | | |
| | | env/bin/alembic -c development.ini revision --autogenerate -m "init" |
| | | |
| | | - Upgrade to that revision. |
| | | |
| | | env/bin/alembic -c development.ini upgrade head |
| | | |
| | | - Load default data into the database using a script. |
| | | |
| | | env/bin/initialize_sqla_demo_db development.ini |
| | | |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = sqla_demo.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | | |
| | | [alembic] |
| | | # path to migration scripts |
| | | script_location = sqla_demo/alembic |
| | | file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s |
| | | # file_template = %%(rev)s_%%(slug)s |
| | | |
| | | [server:main] |
| | | use = egg:waitress#main |
| | |
| | | qualname = sqla_demo |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = sqla_demo.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | | |
| | | [alembic] |
| | | # path to migration scripts |
| | | script_location = sqla_demo/alembic |
| | | file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s |
| | | # file_template = %%(rev)s_%%(slug)s |
| | | |
| | | [server:main] |
| | | use = egg:waitress#main |
| | | listen = *:6543 |
| | |
| | | [pytest] |
| | | testpaths = sqla_demo |
| | | python_files = *.py |
| | | python_files = test*.py |
| | |
| | | CHANGES = f.read() |
| | | |
| | | requires = [ |
| | | 'alembic', |
| | | 'plaster_pastedeploy', |
| | | 'pyramid >= 1.9a', |
| | | 'pyramid >= 1.9', |
| | | 'pyramid_debugtoolbar', |
| | | 'pyramid_jinja2', |
| | | 'pyramid_retry', |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 'main = sqla_demo:main', |
| | | ], |
| | | 'console_scripts': [ |
| | | 'initialize_sqla_demo_db = sqla_demo.scripts.initializedb:main', |
| | | 'initialize_sqla_demo_db = sqla_demo.scripts.initialize_db:main', |
| | | ], |
| | | }, |
| | | ) |
| | |
| | | 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.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | """Pyramid bootstrap environment. """ |
| | | from alembic import context |
| | | from pyramid.paster import get_appsettings, setup_logging |
| | | from sqlalchemy import engine_from_config |
| | | |
| | | from sqla_demo.models.meta import Base |
| | | |
| | | config = context.config |
| | | |
| | | setup_logging(config.config_file_name) |
| | | |
| | | settings = get_appsettings(config.config_file_name) |
| | | target_metadata = Base.metadata |
| | | |
| | | |
| | | def run_migrations_offline(): |
| | | """Run migrations in 'offline' mode. |
| | | |
| | | This configures the context with just a URL |
| | | and not an Engine, though an Engine is acceptable |
| | | here as well. By skipping the Engine creation |
| | | we don't even need a DBAPI to be available. |
| | | |
| | | Calls to context.execute() here emit the given string to the |
| | | script output. |
| | | |
| | | """ |
| | | context.configure(url=settings['sqlalchemy.url']) |
| | | with context.begin_transaction(): |
| | | context.run_migrations() |
| | | |
| | | |
| | | def run_migrations_online(): |
| | | """Run migrations in 'online' mode. |
| | | |
| | | In this scenario we need to create an Engine |
| | | and associate a connection with the context. |
| | | |
| | | """ |
| | | engine = engine_from_config(settings, prefix='sqlalchemy.') |
| | | |
| | | connection = engine.connect() |
| | | context.configure( |
| | | connection=connection, |
| | | target_metadata=target_metadata |
| | | ) |
| | | |
| | | try: |
| | | with context.begin_transaction(): |
| | | context.run_migrations() |
| | | finally: |
| | | connection.close() |
| | | |
| | | |
| | | if context.is_offline_mode(): |
| | | run_migrations_offline() |
| | | else: |
| | | run_migrations_online() |
New file |
| | |
| | | """${message} |
| | | |
| | | Revision ID: ${up_revision} |
| | | Revises: ${down_revision | comma,n} |
| | | Create Date: ${create_date} |
| | | |
| | | """ |
| | | from alembic import op |
| | | import sqlalchemy as sa |
| | | ${imports if imports else ""} |
| | | |
| | | # revision identifiers, used by Alembic. |
| | | revision = ${repr(up_revision)} |
| | | down_revision = ${repr(down_revision)} |
| | | branch_labels = ${repr(branch_labels)} |
| | | depends_on = ${repr(depends_on)} |
| | | |
| | | |
| | | def upgrade(): |
| | | ${upgrades if upgrades else "pass"} |
| | | |
| | | |
| | | def downgrade(): |
| | | ${downgrades if downgrades else "pass"} |
New file |
| | |
| | | Placeholder for alembic versions |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
New file |
| | |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | | from sqlalchemy.exc import OperationalError |
| | | |
| | | from .. import models |
| | | |
| | | |
| | | def setup_models(dbsession): |
| | | """ |
| | | Add or update models / fixtures in the database. |
| | | |
| | | """ |
| | | model = models.mymodel.MyModel(name='one', value=1) |
| | | dbsession.add(model) |
| | | |
| | | |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | | dbsession = env['request'].dbsession |
| | | setup_models(dbsession) |
| | | except OperationalError: |
| | | print(''' |
| | | 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 initialize your database tables with `alembic`. |
| | | Check your README.txt for description 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. |
| | | ''') |
| | |
| | | <h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Alchemy project</span></h1> |
| | | <p class="lead">Welcome to <span class="font-normal">{{project}}</span>, a Pyramid application generated by<br><span class="font-normal">Cookiecutter</span>.</p> |
| | | </div> |
| | | {% endblock content %} |
| | | {% endblock content %} |
| | |
| | | |
| | | from sqlalchemy.exc import DBAPIError |
| | | |
| | | from ..models import MyModel |
| | | from .. import models |
| | | |
| | | |
| | | @view_config(route_name='home', renderer='../templates/mytemplate.jinja2') |
| | | def my_view(request): |
| | | try: |
| | | query = request.dbsession.query(MyModel) |
| | | one = query.filter(MyModel.name == 'one').first() |
| | | query = request.dbsession.query(models.MyModel) |
| | | one = query.filter(models.MyModel.name == 'one').first() |
| | | except DBAPIError: |
| | | return Response(db_err_msg, content_type='text/plain', status=500) |
| | | return {'one': one, 'project': 'sqla_demo'} |
| | |
| | | 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_sqla_demo_db" script |
| | | to initialize your database tables. Check your virtual |
| | | environment's "bin" directory for this script and try to run it. |
| | | 1. You may need to initialize your database tables with `alembic`. |
| | | Check your README.txt for description 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 |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | 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() |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.add_route('home', '/') |
New file |
| | |
| | | {% extends "layout.jinja2" %} |
| | | |
| | | {% block content %} |
| | | <div class="content"> |
| | | <h1><span class="font-semi-bold">Pyramid</span> <span class="smaller">Starter project</span></h1> |
| | | <p class="lead"><span class="font-semi-bold">404</span> Page Not Found</p> |
| | | </div> |
| | | {% endblock content %} |
| | |
| | | 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') |
New file |
| | |
| | | from pyramid.view import view_config |
| | | |
| | | |
| | | @view_config(route_name='home', renderer='../templates/mytemplate.jinja2') |
| | | def my_view(request): |
| | | return {'project': 'cc_starter'} |
New file |
| | |
| | | from pyramid.view import notfound_view_config |
| | | |
| | | |
| | | @notfound_view_config(renderer='../templates/404.jinja2') |
| | | def notfound_view(request): |
| | | request.response.status = 404 |
| | | return {} |
| | |
| | | CHANGES = f.read() |
| | | |
| | | requires = [ |
| | | 'plaster_pastedeploy', |
| | | 'pyramid', |
| | | 'pyramid_debugtoolbar', |
| | | 'pyramid_jinja2', |
| | | 'pyramid_debugtoolbar', |
| | | 'waitress', |
| | | ] |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | |
| | | .. literalinclude:: src/authorization/tutorial/templates/edit.pt |
| | | :lines: 35-39 |
| | | :emphasize-lines: 3-5 |
| | | :emphasize-lines: 2-4 |
| | | :language: html |
| | | |
| | | The attribute ``tal:condition="logged_in"`` will make the element be included |
| | |
| | | |
| | | .. literalinclude:: src/authorization/tutorial/templates/edit.pt |
| | | :linenos: |
| | | :emphasize-lines: 37-39 |
| | | :emphasize-lines: 36-38 |
| | | :language: html |
| | | |
| | | Only the highlighted lines need to be added or edited. |
| | |
| | | |
| | | .. literalinclude:: src/authorization/tutorial/templates/view.pt |
| | | :linenos: |
| | | :emphasize-lines: 37-39 |
| | | :emphasize-lines: 36-38 |
| | | :language: html |
| | | |
| | | Only the highlighted lines need to be added or edited. |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | |
| | | - Upgrade packaging tools. |
| | | |
| | | env/bin/pip install --upgrade pip setuptools wheel |
| | | env/bin/pip install --upgrade pip setuptools |
| | | |
| | | - Install the project in editable mode with its testing requirements. |
| | | |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['models'] = models |
| | |
| | | <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script> |
| | | <![endif]--> |
| | | </head> |
| | | |
| | | <body> |
| | | |
| | | <div class="starter-template"> |
| | |
| | | <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script> |
| | | <![endif]--> |
| | | </head> |
| | | |
| | | <body> |
| | | |
| | | <div class="starter-template"> |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['models'] = models |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['models'] = models |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['models'] = models |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | |
| | | - Upgrade packaging tools. |
| | | |
| | | env/bin/pip install --upgrade pip setuptools wheel |
| | | env/bin/pip install --upgrade pip setuptools |
| | | |
| | | - Install the project in editable mode with its testing requirements. |
| | | |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['models'] = models |
| | |
| | | <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script> |
| | | <![endif]--> |
| | | </head> |
| | | |
| | | <body> |
| | | |
| | | <div class="starter-template"> |
| | |
| | | <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js" integrity="sha384-ZoaMbDF+4LeFxg6WdScQ9nnR1QC2MIRxA1O9KWEXQwns1G8UNyIEZIQidzb0T1fo" crossorigin="anonymous"></script> |
| | | <![endif]--> |
| | | </head> |
| | | |
| | | <body> |
| | | |
| | | <div class="starter-template"> |
New file |
| | |
| | | *.egg |
| | | *.egg-info |
| | | *.pyc |
| | | *$py.class |
| | | *~ |
| | | .coverage |
| | | coverage.xml |
| | | build/ |
| | | dist/ |
| | | .tox/ |
| | | nosetests.xml |
| | | env*/ |
| | | tmp/ |
| | | Data.fs* |
| | | *.sublime-project |
| | | *.sublime-workspace |
| | | .*.sw? |
| | | .sw? |
| | | .DS_Store |
| | | coverage |
| | | test |
| | |
| | | |
| | | - Upgrade packaging tools. |
| | | |
| | | env/bin/pip install --upgrade pip setuptools wheel |
| | | env/bin/pip install --upgrade pip setuptools |
| | | |
| | | - Install the project in editable mode with its testing requirements. |
| | | |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['models'] = models |
| | |
| | | above is executed. It accepts some settings and returns a :term:`WSGI` |
| | | application. (See :ref:`startup_chapter` for more about ``pserve``.) |
| | | |
| | | Next in ``main``, construct a :term:`Configurator` object: |
| | | Next in ``main``, construct a :term:`Configurator` object using a context manager: |
| | | |
| | | .. literalinclude:: src/basiclayout/tutorial/__init__.py |
| | | :lines: 7 |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | auth.secret = real-seekrit |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.include('.security') |
| | | config.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.include('.security') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | dbsession.add(page) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | auth.secret = real-seekrit |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.include('.security') |
| | | config.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.include('.security') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | dbsession.add(page) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | |
| | | |
| | | def setup_models(dbsession): |
| | | """ |
| | | Add or update models / fixtures in the database. |
| | | |
| | | """ |
| | | model = models.mymodel.MyModel(name='one', value=1) |
| | | dbsession.add(model) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | |
| | | |
| | | def setup_models(dbsession): |
| | | """ |
| | | Add or update models / fixtures in the database. |
| | | |
| | | """ |
| | | model = models.mymodel.MyModel(name='one', value=1) |
| | | dbsession.add(model) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | dbsession.add(page) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | auth.secret = real-seekrit |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.include('.security') |
| | | config.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.include('.security') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | dbsession.add(page) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |
| | |
| | | # '127.0.0.1' and '::1'. |
| | | # debugtoolbar.hosts = 127.0.0.1 ::1 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | qualname = tutorial |
| | | |
| | | [logger_sqlalchemy] |
| | | level = INFO |
| | | level = WARN |
| | | handlers = |
| | | qualname = sqlalchemy.engine |
| | | # "level = INFO" logs SQL queries. |
| | |
| | | |
| | | retry.attempts = 3 |
| | | |
| | | [pshell] |
| | | setup = tutorial.pshell.setup |
| | | |
| | | ### |
| | | # wsgi server configuration |
| | | ### |
| | |
| | | |
| | | tests_require = [ |
| | | 'WebTest >= 1.3.1', # py3 compat |
| | | 'pytest', |
| | | 'pytest>=3.7.4', |
| | | 'pytest-cov', |
| | | ] |
| | | |
| | |
| | | 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.scan() |
| | | with Configurator(settings=settings) as config: |
| | | config.include('pyramid_jinja2') |
| | | config.include('.models') |
| | | config.include('.routes') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
New file |
| | |
| | | from . import models |
| | | |
| | | def setup(env): |
| | | request = env['request'] |
| | | |
| | | # start a transaction |
| | | request.tm.begin() |
| | | |
| | | # inject some vars into the shell builtins |
| | | env['tm'] = request.tm |
| | | env['dbsession'] = request.dbsession |
| | | env['models'] = models |
| | |
| | | import os |
| | | import argparse |
| | | import sys |
| | | |
| | | from pyramid.paster import bootstrap, setup_logging |
| | |
| | | dbsession.add(page) |
| | | |
| | | |
| | | def usage(argv): |
| | | cmd = os.path.basename(argv[0]) |
| | | print('usage: %s <config_uri>\n' |
| | | '(example: "%s development.ini")' % (cmd, cmd)) |
| | | sys.exit(1) |
| | | def parse_args(argv): |
| | | parser = argparse.ArgumentParser() |
| | | parser.add_argument( |
| | | 'config_uri', |
| | | help='Configuration file, e.g., development.ini', |
| | | ) |
| | | return parser.parse_args(argv[1:]) |
| | | |
| | | |
| | | def main(argv=sys.argv): |
| | | if len(argv) != 2: |
| | | usage(argv) |
| | | config_uri = argv[1] |
| | | setup_logging(config_uri) |
| | | env = bootstrap(config_uri) |
| | | args = parse_args(argv) |
| | | setup_logging(args.config_uri) |
| | | env = bootstrap(args.config_uri) |
| | | |
| | | try: |
| | | with env['request'].tm: |