Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize configuration, routing, testing, views, and misc sections.
- Loading branch information
Showing
13 changed files
with
102 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Configuration | ||
%%%%%%%%%%%%% | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
django_settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Miscellaneous | ||
%%%%%%%%%%%%% | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
interfaces | ||
events | ||
mac_install |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Traversal and URL dispatch | ||
%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
combining |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Testing | ||
%%%%%%% | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
testing_post_curl |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Views | ||
%%%%% | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
chaining_decorators |