Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Reorganize several sections.

Reorganize configuration, routing, testing, views, and misc sections.
  • Loading branch information...
commit d1918e117ceee2d4bee55dfd59258d8a5ece908e 1 parent fe2ef7b
Mike Orr authored
64  configuration.rst → configuration/django_settings.rst
Source Rendered
... ...
@@ -1,7 +1,5 @@
1  
-.. _configuration:
2  
-
3 1
 Django-Style "settings.py" Configuration
4  
-----------------------------------------
  2
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 3
 
6 4
 If you enjoy accessing global configuration via import statemetns ala
7 5
 Django's ``settings.py``, you can do something similar in Pyramid.
@@ -73,63 +71,3 @@ this format::
73 71
 the section name in the config file that represents your app
74 72
 (e.g. ``[app:myapp]``).  In the above example, your application will refuse
75 73
 to start without this environment variable being present.
76  
-
77  
-Chaining Decorators
78  
--------------------
79  
-
80  
-Pyramid has a ``decorator=`` argument to its view configuration.  It accepts
81  
-a single decorator that will wrap the *mapped* view callable represented by
82  
-the view configuration.  That means that, no matter what the signature and
83  
-return value of the original view callable, the decorated view callable will
84  
-receive two arguments: ``context`` and ``request`` and will return a response
85  
-object:
86  
-
87  
-.. code-block:: python
88  
-
89  
-    # the decorator
90  
-
91  
-    def decorator(view_callable):
92  
-        def inner(context, request):
93  
-            return view_callable(context, request)
94  
-        return inner
95  
-
96  
-    # the view configuration
97  
-
98  
-    @view_config(decorator=decorator, renderer='json')
99  
-    def myview(request):
100  
-        return {'a':1}
101  
-
102  
-But the ``decorator`` argument only takes a single decorator.  What happens
103  
-if you want to use more than one decorator?  You can chain them together:
104  
-
105  
-.. code-block:: python
106  
-
107  
-    def combine(*decorators):
108  
-        def floo(view_callable):
109  
-            for decorator in decorators:
110  
-                view_callable = decorator(view_callable)
111  
-            return view_callable
112  
-        return floo
113  
-
114  
-    def decorator1(view_callable):
115  
-        def inner(context, request):
116  
-            return view_callable(context, request)
117  
-        return inner
118  
-
119  
-    def decorator2(view_callable):
120  
-        def inner(context, request):
121  
-            return view_callable(context, request)
122  
-        return inner
123  
-
124  
-    def decorator3(view_callable):
125  
-        def inner(context, request):
126  
-            return view_callable(context, request)
127  
-        return inner
128  
-
129  
-    alldecs = combine(decorator1, decorator2, decorator3)
130  
-    two_and_three = combine(decorator2, decorator3)
131  
-    one_and_three = combine(decorator1, decorator3)
132  
-
133  
-    @view_config(decorator=alldecs, renderer='json')
134  
-    def myview(request):
135  
-        return {'a':1}
7  configuration/index.rst
Source Rendered
... ...
@@ -0,0 +1,7 @@
  1
+Configuration
  2
+%%%%%%%%%%%%%
  3
+
  4
+.. toctree::
  5
+  :maxdepth: 2
  6
+
  7
+  django_settings
11  index.rst
Source Rendered
@@ -7,24 +7,23 @@ The Pyramid Cookbook presents topical, practical usages of :mod:`Pyramid`.
7 7
    :maxdepth: 2
8 8
 
9 9
    auth/index
  10
+   configuration/index
10 11
    database/index
11 12
    debugging
12 13
    deployment/index
13 14
    logging/index
14 15
    porting/index
15 16
    pylons/index
  17
+   routing/index
16 18
    templates/index
  19
+   testing/index
  20
+   views/index
  21
+   misc/index
17 22
 
18 23
 .. toctree::
19 24
    :maxdepth: 2
20 25
 
21 26
    files
22  
-   interfaces
23  
-   configuration
24  
-   events
25  
-   testing
26  
-   traversal
27  
-   mac_install
28 27
    glossary
29 28
    todo
30 29
 
0  events.rst → misc/events.rst
Source Rendered
File renamed without changes
9  misc/index.rst
Source Rendered
... ...
@@ -0,0 +1,9 @@
  1
+Miscellaneous
  2
+%%%%%%%%%%%%%
  3
+
  4
+.. toctree::
  5
+   :maxdepth: 2
  6
+
  7
+   interfaces
  8
+   events
  9
+   mac_install
0  interfaces.rst → misc/interfaces.rst
Source Rendered
File renamed without changes
0  mac_install.rst → misc/mac_install.rst
Source Rendered
File renamed without changes
0  traversal.rst → routing/combining.rst
Source Rendered
File renamed without changes
7  routing/index.rst
Source Rendered
... ...
@@ -0,0 +1,7 @@
  1
+Traversal and URL dispatch
  2
+%%%%%%%%%%%%%%%%%%%%%%%%%%
  3
+
  4
+.. toctree::
  5
+   :maxdepth: 2
  6
+
  7
+   combining
7  testing/index.rst
Source Rendered
... ...
@@ -0,0 +1,7 @@
  1
+Testing
  2
+%%%%%%%
  3
+
  4
+.. toctree::
  5
+   :maxdepth: 2
  6
+
  7
+   testing_post_curl
0  testing.rst → testing/testing_post_curl.rst
Source Rendered
File renamed without changes
59  views/chaining_decorators.rst
Source Rendered
... ...
@@ -0,0 +1,59 @@
  1
+Chaining Decorators
  2
+%%%%%%%%%%%%%%%%%%%
  3
+
  4
+Pyramid has a ``decorator=`` argument to its view configuration.  It accepts
  5
+a single decorator that will wrap the *mapped* view callable represented by
  6
+the view configuration.  That means that, no matter what the signature and
  7
+return value of the original view callable, the decorated view callable will
  8
+receive two arguments: ``context`` and ``request`` and will return a response
  9
+object:
  10
+
  11
+.. code-block:: python
  12
+
  13
+    # the decorator
  14
+
  15
+    def decorator(view_callable):
  16
+        def inner(context, request):
  17
+            return view_callable(context, request)
  18
+        return inner
  19
+
  20
+    # the view configuration
  21
+
  22
+    @view_config(decorator=decorator, renderer='json')
  23
+    def myview(request):
  24
+        return {'a':1}
  25
+
  26
+But the ``decorator`` argument only takes a single decorator.  What happens
  27
+if you want to use more than one decorator?  You can chain them together:
  28
+
  29
+.. code-block:: python
  30
+
  31
+    def combine(*decorators):
  32
+        def floo(view_callable):
  33
+            for decorator in decorators:
  34
+                view_callable = decorator(view_callable)
  35
+            return view_callable
  36
+        return floo
  37
+
  38
+    def decorator1(view_callable):
  39
+        def inner(context, request):
  40
+            return view_callable(context, request)
  41
+        return inner
  42
+
  43
+    def decorator2(view_callable):
  44
+        def inner(context, request):
  45
+            return view_callable(context, request)
  46
+        return inner
  47
+
  48
+    def decorator3(view_callable):
  49
+        def inner(context, request):
  50
+            return view_callable(context, request)
  51
+        return inner
  52
+
  53
+    alldecs = combine(decorator1, decorator2, decorator3)
  54
+    two_and_three = combine(decorator2, decorator3)
  55
+    one_and_three = combine(decorator1, decorator3)
  56
+
  57
+    @view_config(decorator=alldecs, renderer='json')
  58
+    def myview(request):
  59
+        return {'a':1}
7  views/index.rst
Source Rendered
... ...
@@ -0,0 +1,7 @@
  1
+Views
  2
+%%%%%
  3
+
  4
+.. toctree::
  5
+   :maxdepth: 2
  6
+
  7
+   chaining_decorators

0 notes on commit d1918e1

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