""" Convert linebreaks to
s and escape each line. Return value is marked 'safe' """
def linebreaksbr_escape(value):
escaped_lines = []
for line in value.split('\n'):
escaped_lines.append(escape(line))
escaped = "
".join(escaped_lines)
# mark as safe
return Markup(escaped)
# reverse url pattern matching, and automatically urlencode parameters
# "|urlencode" filter is also available
def url(view_name, *args, **kwargs):
escaped_args = tuple(_url_quote(arg) for arg in args)
escaped_kwargs = dict((k, _url_quote(arg)) for k,v in kwargs)
return url_noencode(view_name, *escaped_args, **kwargs)
def _url_quote(arg):
if isinstance(arg,basestring):
return urlquote(arg)
else:
return arg
# reverse url pattern matching
def url_noencode(view_name, *args, **kwargs):
return reverse(view_name, args=args, kwargs=kwargs)