Commit 68e0caba authored by Grégory Wisniewski's avatar Grégory Wisniewski

Make make_hidden_input produce valid X-HTML <input /> tag.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43909 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 74b1dcaa
...@@ -14,41 +14,40 @@ ...@@ -14,41 +14,40 @@
""" """
Backport fix from https://bugs.launchpad.net/zope2/+bug/143768 for Zope2.8 Backport fix from https://bugs.launchpad.net/zope2/+bug/143768 for Zope2.8
Also, close properly the <input /> tag
""" """
from App import version_txt import ZTUtils.Zope
if version_txt.getZopeVersion() < (2, 9): from ZTUtils.Zope import complex_marshal
import ZTUtils.Zope import cgi
from ZTUtils.Zope import complex_marshal
import cgi def make_hidden_input(*args, **kwargs):
'''Construct a set of hidden input elements, with marshalling markup.
def make_hidden_input(*args, **kwargs):
'''Construct a set of hidden input elements, with marshalling markup. If there are positional arguments, they must be dictionaries.
They are combined with the dictionary of keyword arguments to form
If there are positional arguments, they must be dictionaries. a dictionary of query names and values.
They are combined with the dictionary of keyword arguments to form
a dictionary of query names and values. Query names (the keys) must be strings. Values may be strings,
integers, floats, or DateTimes, and they may also be lists or
Query names (the keys) must be strings. Values may be strings, namespaces containing these types. All arguments are marshalled with
integers, floats, or DateTimes, and they may also be lists or complex_marshal().
namespaces containing these types. All arguments are marshalled with '''
complex_marshal().
''' d = {}
for arg in args:
d = {} d.update(arg)
for arg in args: d.update(kwargs)
d.update(arg)
d.update(kwargs) hq = lambda x:cgi.escape(x, quote=True)
qlist = complex_marshal(d.items())
hq = lambda x:cgi.escape(x, quote=True) for i in range(len(qlist)):
qlist = complex_marshal(d.items()) k, m, v = qlist[i]
for i in range(len(qlist)): qlist[i] = ('<input type="hidden" name="%s%s" value="%s" />'
k, m, v = qlist[i] % (hq(k), m, hq(str(v))))
qlist[i] = ('<input type="hidden" name="%s%s" value="%s">'
% (hq(k), m, hq(str(v)))) return '\n'.join(qlist)
return '\n'.join(qlist) ZTUtils.Zope.make_hidden_input = make_hidden_input
ZTUtils.make_hidden_input = make_hidden_input
ZTUtils.Zope.make_hidden_input = make_hidden_input
ZTUtils.make_hidden_input = make_hidden_input
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment