Skip to content

Commit 381c5fc

Browse files
committed
fix: document/fix wrapped HtmlProperty method.
The wrapped method was not documented in reference.txt. It is now documented in reference.txt. The docstring documented that it would not break up long words. Fixed by adding break_long_words=False to prevent breaking string longer than the wrap length. Wrapping was breaking the hyperlinking of long urls. Added columns argument to set the wrap length (default 80 columns).
1 parent e8f13f8 commit 381c5fc

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

doc/reference.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,6 +3316,12 @@ There are several methods available on these wrapper objects:
33163316

33173317
"structure msg/content/hyperlinked"
33183318

3319+
wrapped Wraps long lines on the nearest whitespace. Like
3320+
plain(), it takes ``escape`` and ``hyperlink``
3321+
arguments. However, the defaults are to enable both
3322+
escape and hyperlinks. It also takes a ``columns``
3323+
argument set by default to 80.
3324+
33193325
field render an appropriate form edit field for the property - for
33203326
most types this is a text entry box, but for
33213327
Booleans it is a
@@ -3337,6 +3343,7 @@ There are several methods available on these wrapper objects:
33373343
rst only on String properties - render the value of the property
33383344
as ReStructuredText (requires the :ref:`Docutils
33393345
module to be installed separately<install/docutils>`).
3346+
33403347
stext only on String properties - render the value of the property
33413348
as StructuredText (requires the StructureText module to be
33423349
installed separately) (depricated, to be removed
@@ -3347,25 +3354,32 @@ There are several methods available on these wrapper objects:
33473354

33483355
multiline only on String properties - render a multiline form edit
33493356
field for the property
3357+
33503358
email only on String properties - render the value of the property
33513359
as an obscured email address
3360+
33523361
url_quote only on String properties. It quotes any characters in the
33533362
string so it is safe to use in a url. E.G. a space is
33543363
replaced with %20.
3364+
33553365
confirm only on Password properties - render a second form edit field
33563366
for the property, used for confirmation that the user typed
33573367
the password correctly. Generates a field with name
33583368
"name:confirm".
3369+
33593370
now only on Date properties - return the current date as a new
33603371
property
3372+
33613373
reldate only on Date properties - render the interval between the date
33623374
and now
3375+
33633376
local only on Date properties - return this date as a new property
33643377
with some timezone offset, for example::
33653378

33663379
python:context.creation.local(10)
33673380

33683381
will render the date with a +10 hour offset.
3382+
33693383
pretty Date properties - render the date as "dd Mon YYYY" (eg. "19
33703384
Mar 2004"). Takes an optional format argument, for example::
33713385

@@ -3382,6 +3396,7 @@ There are several methods available on these wrapper objects:
33823396
(default: '%0.3f') and formats the number accordingly.
33833397
If the value can't be converted, '' is returned if the
33843398
value is ``None`` otherwise it is converted to a string.
3399+
33853400
popcal Generate a link to a popup calendar which may be used to
33863401
edit the date field, for example::
33873402

@@ -3446,8 +3461,10 @@ There are several methods available on these wrapper objects:
34463461
``reverse=True`` the meaning of NoneFirst is inverted:
34473462
True sorts None/unset at the end and False sorts at the
34483463
beginning.
3464+
34493465
reverse only on Multilink properties - produce a list of the linked
34503466
items in reverse order
3467+
34513468
isset returns True if the property has been set to a value
34523469
=========== ================================================================
34533470

roundup/cgi/templating.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ def plain(self, escape=0, hyperlink=0):
18351835
s = self.hyper_re.sub(self._hyper_repl, s)
18361836
return s
18371837

1838-
def wrapped(self, escape=1, hyperlink=1):
1838+
def wrapped(self, escape=1, hyperlink=1, columns=80):
18391839
"""Render a "wrapped" representation of the property.
18401840
18411841
We wrap long lines at 80 columns on the nearest whitespace. Lines
@@ -1847,13 +1847,16 @@ def wrapped(self, escape=1, hyperlink=1):
18471847
- "escape" turns on/off HTML quoting
18481848
- "hyperlink" turns on/off in-text hyperlinking of URLs, email
18491849
addresses and designators
1850+
- "columns" sets the column where the wrapping will occur.
1851+
Default of 80.
18501852
"""
18511853
if not self.is_view_ok():
18521854
return self._('[hidden]')
18531855

18541856
if self._value is None:
18551857
return ''
1856-
s = '\n'.join(textwrap.wrap(str(self._value), 80))
1858+
s = '\n'.join(textwrap.wrap(str(self._value), columns,
1859+
break_long_words=False))
18571860
if escape:
18581861
s = html_escape(s)
18591862
if hyperlink:

test/test_templating.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,18 +450,40 @@ def test_string_wrapped(self):
450450
' Put in <html> to be escaped. Put in a'
451451
' https://example.com/link as well. Let us see if'
452452
' it will wrap properly.' )
453-
test_result = ('A long string that needs to be wrapped to 80'
453+
454+
test_result_wrap = {}
455+
test_result_wrap[80] = ('A long string that needs to be wrapped to 80'
454456
' characters and no more. Put in a\n'
455457
'link <a href="issue1">issue1</a>. Put in'
456458
' &lt;html&gt; to be escaped. Put in a <a'
457459
' href="https://example.com/link"'
458460
' rel="nofollow noopener">'
459461
'https://example.com/link</a> as\n'
460462
'well. Let us see if it will wrap properly.')
463+
test_result_wrap[20] = (
464+
'A long string that\n'
465+
'needs to be wrapped\n'
466+
'to 80 characters and\n'
467+
'no more. Put in a\nlink <a href="issue1">issue1</a>. Put in\n'
468+
'&lt;html&gt; to be\n'
469+
'escaped. Put in a\n'
470+
'<a href="https://example.com/link" rel="nofollow '
471+
'noopener">https://example.com/link</a>\n'
472+
'as well. Let us see\n'
473+
'if it will wrap\n'
474+
'properly.')
475+
test_result_wrap[100] = (
476+
'A long string that needs to be wrapped to 80 characters and no more. Put in a link <a href="issue1">issue1</a>. Put in\n'
477+
'&lt;html&gt; to be escaped. Put in a <a href="https://example.com/link" rel="nofollow noopener">https://example.com/link</a> as well. Let us see if it will wrap\n'
478+
'properly.')
461479

462480
p = StringHTMLProperty(self.client, 'test', '1', None, 'test',
463481
test_string)
464-
self.assertEqual(p.wrapped(), test_result)
482+
483+
for i in [80, 20, 100]:
484+
wrapped = p.wrapped(columns=i)
485+
print(wrapped)
486+
self.assertEqual(wrapped, test_result_wrap[i])
465487

466488
def test_string_plain_or_hyperlinked(self):
467489
''' test that email obscures the email '''

0 commit comments

Comments
 (0)