Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 3644:f35ece8f8ff7
added StringHTMLProperty wrapped() method to wrap long lines in issue display
also fixed a circular import in roundup.support
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 31 Jul 2006 01:30:05 +0000 |
| parents | 53987aa153d2 |
| children | 12633662ff63 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Thu Jul 27 22:54:05 2006 +0000 +++ b/roundup/cgi/templating.py Mon Jul 31 01:30:05 2006 +0000 @@ -20,7 +20,7 @@ from __future__ import nested_scopes import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes, csv -import calendar +import calendar, textwrap from roundup import hyperdb, date, support from roundup import i18n @@ -1248,6 +1248,34 @@ s = self.hyper_re.sub(self._hyper_repl, s) return s + def wrapped(self, escape=1, hyperlink=1): + '''Render a "wrapped" representation of the property. + + We wrap long lines at 80 columns on the nearest whitespace. Lines + with no whitespace are not broken to force wrapping. + + Note that unlike plain() we default wrapped() to have the escaping + and hyperlinking turned on since that's the most common usage. + + - "escape" turns on/off HTML quoting + - "hyperlink" turns on/off in-text hyperlinking of URLs, email + addresses and designators + ''' + if not self.is_view_ok(): + return self._('[hidden]') + + if self._value is None: + return '' + s = support.wrap(str(self._value), width=80) + if escape: + s = cgi.escape(s) + if hyperlink: + # no, we *must* escape this text + if not escape: + s = cgi.escape(s) + s = self.hyper_re.sub(self._hyper_repl, s) + return s + def stext(self, escape=0, hyperlink=1): ''' Render the value of the property as StructuredText.
