summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7873cc2)
raw | patch | inline | side by side (parent: 7873cc2)
author | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 9 Oct 2009 13:58:43 +0000 (13:58 +0000) | ||
committer | stefan <stefan@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 9 Oct 2009 13:58:43 +0000 (13:58 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4371 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/cgi/templating.py | patch | blob | history |
index 2087508e53e49aa5e47c388bf1463584faa3fad7..797cd1370622ee3c900d8cf6d87c80cc1b429e11 100644 (file)
except KeyError:
pass
+def cgi_escape_attrs(**attrs):
+ return ' '.join(['%s="%s"'%(k,cgi.escape(str(v), True))
+ for k,v in attrs.items()])
+
def input_html4(**attrs):
"""Generate an 'input' (html4) element with given attributes"""
_set_input_default_args(attrs)
- return '<input %s>'%' '.join(['%s="%s"'%(k,cgi.escape(str(v), True))
- for k,v in attrs.items()])
+ return '<input %s>'%cgi_escape_attrs(**attrs)
def input_xhtml(**attrs):
"""Generate an 'input' (xhtml) element with given attributes"""
_set_input_default_args(attrs)
- return '<input %s/>'%' '.join(['%s="%s"'%(k,cgi.escape(str(v), True))
- for k,v in attrs.items()])
+ return '<input %s/>'%cgi_escape_attrs(**attrs)
class HTMLInputMixin:
""" requires a _client property """
value = '"'.join(value.split('"'))
name = self._formname
- passthrough_args = ' '.join(['%s="%s"' % (k, cgi.escape(str(v), True))
- for k,v in kwargs.items()])
+ passthrough_args = cgi_escape_attrs(**kwargs)
return ('<textarea %(passthrough_args)s name="%(name)s" id="%(name)s"'
' rows="%(rows)s" cols="%(cols)s">'
'%(value)s</textarea>') % locals()
return ''
return self._('*encrypted*')
- def field(self, size=30):
+ def field(self, size=30, **kwargs):
""" Render a form edit field for the property.
If not editable, just display the value via plain().
if not self.is_edit_ok():
return self.plain(escape=1)
- return self.input(type="password", name=self._formname, size=size)
+ return self.input(type="password", name=self._formname, size=size,
+ **kwargs)
def confirm(self, size=30):
""" Render a second form edit field for the property, used for
return str(self._value)
- def field(self, size=30):
+ def field(self, size=30, **kwargs):
""" Render a form edit field for the property.
If not editable, just display the value via plain().
if value is None:
value = ''
- return self.input(name=self._formname, value=value, size=size)
+ return self.input(name=self._formname, value=value, size=size,
+ **kwargs)
def __int__(self):
""" Return an int of me
return ''
return self._value and self._("Yes") or self._("No")
- def field(self):
+ def field(self, **kwargs):
""" Render a form edit field for the property
If not editable, just display the value via plain().
checked = value and "checked" or ""
if value:
s = self.input(type="radio", name=self._formname, value="yes",
- checked="checked")
+ checked="checked", **kwargs)
s += self._('Yes')
- s +=self.input(type="radio", name=self._formname, value="no")
+ s +=self.input(type="radio", name=self._formname, value="no",
+ **kwargs)
s += self._('No')
else:
- s = self.input(type="radio", name=self._formname, value="yes")
+ s = self.input(type="radio", name=self._formname, value="yes",
+ **kwargs)
s += self._('Yes')
s +=self.input(type="radio", name=self._formname, value="no",
- checked="checked")
+ checked="checked", **kwargs)
s += self._('No')
return s
return DateHTMLProperty(self._client, self._classname, self._nodeid,
self._prop, self._formname, ret)
- def field(self, size=30, default=None, format=_marker, popcal=True):
+ def field(self, size=30, default=None, format=_marker, popcal=True,
+ **kwargs):
"""Render a form edit field for the property
If not editable, just display the value via plain().
elif isinstance(value, str) or isinstance(value, unicode):
# most likely erroneous input to be passed back to user
if isinstance(value, unicode): value = value.encode('utf8')
- return self.input(name=self._formname, value=value, size=size)
+ return self.input(name=self._formname, value=value, size=size,
+ **kwargs)
else:
raw_value = value
if format is not self._marker:
value = value.pretty(format)
- s = self.input(name=self._formname, value=value, size=size)
+ s = self.input(name=self._formname, value=value, size=size,
+ **kwargs)
if popcal:
s += self.popcal()
return s
return self._value.pretty()
- def field(self, size=30):
+ def field(self, size=30, **kwargs):
""" Render a form edit field for the property
If not editable, just display the value via plain().
if value is None:
value = ''
- return self.input(name=self._formname, value=value, size=size)
+ return self.input(name=self._formname, value=value, size=size,
+ **kwargs)
class LinkHTMLProperty(HTMLProperty):
""" Link HTMLProperty
value = cgi.escape(value)
return value
- def field(self, showid=0, size=None):
+ def field(self, showid=0, size=None, **kwargs):
""" Render a form edit field for the property
If not editable, just display the value via plain().
value = linkcl.get(self._value, k)
else:
value = self._value
- return self.input(name=self._formname, value=value, size=size)
+ return self.input(name=self._formname, value=value, size=size,
+ **kwargs)
def menu(self, size=None, height=None, showid=0, additional=[], value=None,
- sort_on=None, **conditions):
+ sort_on=None, html_kwargs = {}, **conditions):
""" Render a form select list for this property
"size" is used to limit the length of the list labels
value = None
linkcl = self._db.getclass(self._prop.classname)
- l = ['<select name="%s">'%self._formname]
+ l = ['<select %s>'%cgi_escape_attrs(name = self._formname,
+ **html_kwargs)]
k = linkcl.labelprop(1)
s = ''
if value is None:
value = cgi.escape(value)
return value
- def field(self, size=30, showid=0):
+ def field(self, size=30, showid=0, **kwargs):
""" Render a form edit field for the property
If not editable, just display the value via plain().
k = linkcl.labelprop(1)
value = lookupKeys(linkcl, k, value)
value = ','.join(value)
- return self.input(name=self._formname, size=size, value=value)
+ return self.input(name=self._formname, size=size, value=value,
+ **kwargs)
def menu(self, size=None, height=None, showid=0, additional=[],
- value=None, sort_on=None, **conditions):
+ value=None, sort_on=None, html_kwargs = {}, **conditions):
""" Render a form <select> list for this property.
"size" is used to limit the length of the list labels
# The "no selection" option.
height += 1
height = min(height, 7)
- l = ['<select multiple name="%s" size="%s">'%(self._formname, height)]
+ l = ['<select multiple %s>'%cgi_escape_attrs(name = self._formname,
+ size = height,
+ **html_kwargs)]
k = linkcl.labelprop(1)
if value: