Permalink
Browse files

Reorganize several sections.

Reorganize configuration, routing, testing, views, and misc sections.
  • Loading branch information...
mikeorr committed Feb 20, 2012
1 parent fe2ef7b commit d1918e117ceee2d4bee55dfd59258d8a5ece908e
@@ -1,7 +1,5 @@
-.. _configuration:
-
Django-Style "settings.py" Configuration
-----------------------------------------
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
If you enjoy accessing global configuration via import statemetns ala
Django's ``settings.py``, you can do something similar in Pyramid.
@@ -73,63 +71,3 @@ this format::
the section name in the config file that represents your app
(e.g. ``[app:myapp]``). In the above example, your application will refuse
to start without this environment variable being present.
-
-Chaining Decorators
--------------------
-
-Pyramid has a ``decorator=`` argument to its view configuration. It accepts
-a single decorator that will wrap the *mapped* view callable represented by
-the view configuration. That means that, no matter what the signature and
-return value of the original view callable, the decorated view callable will
-receive two arguments: ``context`` and ``request`` and will return a response
-object:
-
-.. code-block:: python
-
- # the decorator
-
- def decorator(view_callable):
- def inner(context, request):
- return view_callable(context, request)
- return inner
-
- # the view configuration
-
- @view_config(decorator=decorator, renderer='json')
- def myview(request):
- return {'a':1}
-
-But the ``decorator`` argument only takes a single decorator. What happens
-if you want to use more than one decorator? You can chain them together:
-
-.. code-block:: python
-
- def combine(*decorators):
- def floo(view_callable):
- for decorator in decorators:
- view_callable = decorator(view_callable)
- return view_callable
- return floo
-
- def decorator1(view_callable):
- def inner(context, request):
- return view_callable(context, request)
- return inner
-
- def decorator2(view_callable):
- def inner(context, request):
- return view_callable(context, request)
- return inner
-
- def decorator3(view_callable):
- def inner(context, request):
- return view_callable(context, request)
- return inner
-
- alldecs = combine(decorator1, decorator2, decorator3)
- two_and_three = combine(decorator2, decorator3)
- one_and_three = combine(decorator1, decorator3)
-
- @view_config(decorator=alldecs, renderer='json')
- def myview(request):
- return {'a':1}
View
@@ -0,0 +1,7 @@
+Configuration
+%%%%%%%%%%%%%
+
+.. toctree::
+ :maxdepth: 2
+
+ django_settings
View
@@ -7,24 +7,23 @@ The Pyramid Cookbook presents topical, practical usages of :mod:`Pyramid`.
:maxdepth: 2
auth/index
+ configuration/index
database/index
debugging
deployment/index
logging/index
porting/index
pylons/index
+ routing/index
templates/index
+ testing/index
+ views/index
+ misc/index
.. toctree::
:maxdepth: 2
files
- interfaces
- configuration
- events
- testing
- traversal
- mac_install
glossary
todo
File renamed without changes.
View
@@ -0,0 +1,9 @@
+Miscellaneous
+%%%%%%%%%%%%%
+
+.. toctree::
+ :maxdepth: 2
+
+ interfaces
+ events
+ mac_install
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,7 @@
+Traversal and URL dispatch
+%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+.. toctree::
+ :maxdepth: 2
+
+ combining
View
@@ -0,0 +1,7 @@
+Testing
+%%%%%%%
+
+.. toctree::
+ :maxdepth: 2
+
+ testing_post_curl
File renamed without changes.
@@ -0,0 +1,59 @@
+Chaining Decorators
+%%%%%%%%%%%%%%%%%%%
+
+Pyramid has a ``decorator=`` argument to its view configuration. It accepts
+a single decorator that will wrap the *mapped* view callable represented by
+the view configuration. That means that, no matter what the signature and
+return value of the original view callable, the decorated view callable will
+receive two arguments: ``context`` and ``request`` and will return a response
+object:
+
+.. code-block:: python
+
+ # the decorator
+
+ def decorator(view_callable):
+ def inner(context, request):
+ return view_callable(context, request)
+ return inner
+
+ # the view configuration
+
+ @view_config(decorator=decorator, renderer='json')
+ def myview(request):
+ return {'a':1}
+
+But the ``decorator`` argument only takes a single decorator. What happens
+if you want to use more than one decorator? You can chain them together:
+
+.. code-block:: python
+
+ def combine(*decorators):
+ def floo(view_callable):
+ for decorator in decorators:
+ view_callable = decorator(view_callable)
+ return view_callable
+ return floo
+
+ def decorator1(view_callable):
+ def inner(context, request):
+ return view_callable(context, request)
+ return inner
+
+ def decorator2(view_callable):
+ def inner(context, request):
+ return view_callable(context, request)
+ return inner
+
+ def decorator3(view_callable):
+ def inner(context, request):
+ return view_callable(context, request)
+ return inner
+
+ alldecs = combine(decorator1, decorator2, decorator3)
+ two_and_three = combine(decorator2, decorator3)
+ one_and_three = combine(decorator1, decorator3)
+
+ @view_config(decorator=alldecs, renderer='json')
+ def myview(request):
+ return {'a':1}
View
@@ -0,0 +1,7 @@
+Views
+%%%%%
+
+.. toctree::
+ :maxdepth: 2
+
+ chaining_decorators

0 comments on commit d1918e1

Please sign in to comment.