1
2 r"""
3 :Copyright:
4
5 Copyright 2007 - 2015
6 Andr\xe9 Malo or his licensors, as applicable
7
8 :License:
9
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
13
14 http://www.apache.org/licenses/LICENSE-2.0
15
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
21
22 =====================
23 HTML forms reloaded
24 =====================
25
26 Form helper classes.
27 """
28 if __doc__:
29
30 __doc__ = __doc__.encode('ascii').decode('unicode_escape')
31 __author__ = r"Andr\xe9 Malo".encode('ascii').decode('unicode_escape')
32 __docformat__ = "restructuredtext en"
33 __all__ = [
34 'ParameterAdapterInterface', 'PreProcInterface', 'PostProcInterface',
35 ]
36
37
39 """
40 Interface for a request parameter adapter suitable for `HTMLForm`
41 """
42
44 """
45 Determine all parameters submitted under a name
46
47 :Parameters:
48 `name` : ``str``
49 The name to look up
50
51 :Return: The List of values (maybe empty) (``[u'value', ...]``)
52 :Rtype: ``list``
53 """
54
56 """
57 Determine one parameter of all submitted under a name
58
59 It doesn't have to be the first parameter, but it should work
60 deterministically, i.e. the method should always return the same
61 value for the same name.
62
63 :Parameters:
64 `name` : ``str``
65 The name to look up
66
67 `default` : ``basestring``
68 The returned value if name could not be found
69
70 :Return: The found value. If it was not found, `default` is returned
71 :Rtype: ``basestring``
72 """
73
74
76 """ Interface for node processors """
77
78 - def __call__(self, method, node, kwargs):
79 """
80 Pre process the node
81
82 :Parameters:
83 `method` : ``str``
84 The name of the method (like ``'text'`` or ``'checkbox'``)
85
86 `node` : `tdi.nodetree.Node`
87 The node to process
88
89 `kwargs` : ``dict``
90 The arguments of the HTMLForm method
91
92 :Return: node and kwargs again (they do not need to be the same as
93 input). Keys appearing in kwargs override the original
94 parameters then. (``(node, kwargs)``)
95 :Rtype: ``tuple``
96 """
97
98
99 -class PostProcInterface(object):
100 """ Interface for node processors """
101
102 - def __call__(self, method, node, kwargs):
103 """
104 Post process the node
105
106 :Parameters:
107 `method` : ``str``
108 The name of the method (like ``'text'`` or ``'checkbox'``)
109
110 `node` : `tdi.nodetree.Node`
111 The node to process
112
113 `kwargs` : ``dict``
114 The arguments of the HTMLForm method
115 """
116