Skip to content
Browse files

added support for includeme register function

  • Loading branch information...
1 parent b9b3430 commit 6524a0a18e78e2100cbe3c247a523c69f4dc64da @blaflamme blaflamme committed Oct 22, 2011
Showing with 59 additions and 11 deletions.
  1. +3 −0 .gitmodules
  2. +1 −0 CHANGES.txt
  3. +3 −1 CONTRIBUTORS.txt
  4. +0 −1 docs/.gitignore
  5. +1 −1 docs/Makefile
  6. +1 −0 docs/_themes
  7. +34 −8 docs/index.rst
  8. +5 −0 pyramid_beaker/__init__.py
  9. +11 −0 pyramid_beaker/tests.py
View
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "docs/_themes"]
+ path = docs/_themes
+ url = git://github.com/Pylons/pylons_sphinx_theme.git
View
1 CHANGES.txt
@@ -2,6 +2,7 @@ Next release
------------
- Add a tox.ini for Jenkins testing.
+- Add includeme function to ease application setup.
0.5 (2011-03-30)
----------------
View
4 CONTRIBUTORS.txt
@@ -114,4 +114,6 @@ Contributors
- Joachim Krebs 2011/01/03
-- Wichert Akkerman, 29-04-2011
+- Wichert Akkerman, 2011/04/29
+
+- Blaise Laflamme, 2011/10/22
View
1 docs/.gitignore
@@ -1,2 +1 @@
-_themes/
.build/
View
2 docs/Makefile
@@ -70,4 +70,4 @@ linkcheck:
"or in _build/linkcheck/output.txt."
_themes:
- git clone git://github.com/Pylons/pylons_sphinx_theme.git _themes
+ cd ..; git submodule update --init; cd docs
1 docs/_themes
@@ -0,0 +1 @@
+Subproject commit 03e5e5aaaeddc4c9aea887478c7e7b379a127b6f
View
42 docs/index.rst
@@ -1,16 +1,47 @@
pyramid_beaker
==============
+Overview
+--------
+
A :term:`Beaker` session factory backend for :term:`Pyramid`, also cache
configurator.
+Installation
+------------
+
+Install using setuptools, e.g. (within a virtualenv)::
+
+ $ easy_install pyramid_beaker
+
+Setup
+-----
+
+Once :mod:`pyramid_beaker` is installed, you must use the ``config.include``
+mechanism to include it into your Pyramid project's configuration. In your
+Pyramid project's ``__init__.py``:
+
+.. code-block:: python
+
+ config = Configurator(.....)
+ config.include('pyramid_beaker')
+
+Alternately, instead of using the Configurator's ``include`` method, you can
+activate Pyramid by changing your application's ``.ini`` file, use the
+following line:
+
+.. code-block:: ini
+
+ pyramid.includes = pyramid_beaker
+
Usage
-----
Session management
``````````````````
-In the configuration portion of your :term:`Pyramid` app, use the
+In the configuration portion of your :term:`Pyramid` app, if you are not using
+the default activation setup, use the
:func:`pyramid_beaker.BeakerSessionFactoryConfig` function or the
:func:`pyramid_beaker.session_factory_from_settings` function to
create a Pyramid :term:`session factory`. Subsequently register that
@@ -53,13 +84,10 @@ in the ``__init__.py`` of your Pyramid application that uses an
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
- zcml_file = settings.get('configure_zcml', 'configure.zcml')
session_factory = session_factory_from_settings(settings)
config = Configurator(root_factory=get_root, settings=settings)
- config.begin()
config.set_session_factory(session_factory)
# ... other configuration stuff...
- config.end()
return config.make_wsgi_app()
The ``cookie_on_exception`` option is specific to ``pyramid_beaker`` (as
@@ -71,7 +99,8 @@ cookies will be sent back in responses generated by exception views.
Beaker cache region support
```````````````````````````
-In the configuration portion of your :term:`Pyramid` app, use the
+In the configuration portion of your :term:`Pyramid` app, if you are not using
+the default activation setup, use the
:func:`pyramid_beaker.set_cache_regions_from_settings` function to
set Beaker's cache regions. At that point, you can use Beaker's `cache_region`
functionality to enable caching for Your application.
@@ -111,12 +140,9 @@ in the ``__init__.py`` of your Pyramid application that uses an
It is usually called by the PasteDeploy framework during
``paster serve``.
"""
- zcml_file = settings.get('configure_zcml', 'configure.zcml')
set_cache_regions_from_settings(settings)
config = Configurator(root_factory=get_root, settings=settings)
- config.begin()
# ... other configuration stuff...
- config.end()
return config.make_wsgi_app()
Inherited region settings
View
5 pyramid_beaker/__init__.py
@@ -151,3 +151,8 @@ def set_cache_regions_from_settings(settings):
if 'url' not in region_settings:
region_settings['url'] = cache_settings.get('url')
cache.cache_regions[region] = region_settings
+
+def includeme(config):
+ session_factory = session_factory_from_settings(config.registry.settings)
+ config.set_session_factory(session_factory)
+ set_cache_regions_from_settings(config.registry.settings)
View
11 pyramid_beaker/tests.py
@@ -304,3 +304,14 @@ def test_region_inherit_url(self):
short_term = beaker.cache.cache_regions.get('short_term')
self.assertEqual(short_term.get('url'), settings['cache.url'])
self.assertEqual(default_term.get('url'), settings['cache.url'])
+
+class TestIncludeMe(unittest.TestCase):
+ def test_includeme(self):
+ from pyramid.interfaces import ISessionFactory
+ from pyramid import testing
+ from pyramid_beaker import includeme
+ config = testing.setUp(settings={})
+ includeme(config)
+ session_factory = config.registry.queryUtility(ISessionFactory)
+ self.assertEqual(str(session_factory),
+ "<class 'pyramid_beaker.PyramidBeakerSessionObject'>")

0 comments on commit 6524a0a

Please sign in to comment.
Something went wrong with that request. Please try again.