Skip to content

Commit 5b2087f

Browse files
committed
Eliminated several variations on word wrapping, keeping only what used to be wrap_text(), but renamed as ietf.utils.text.wordwrap(). This performs better than django.utils.text.wrap() when there are indented text parts. Replaced django's default wordwrap filter with one calling ietf.utils.text.wordwrap in templates. Changed to triggered wrapping in some cases, with the maybewordwrap filter, which triggers on lines longer than 100 characters. This fixes the issue with undesired wrapping of reviews.
- Legacy-Id: 13505
1 parent 16d129c commit 5b2087f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+139
-411
lines changed

ietf/doc/templatetags/ietf_filters.py

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
import types
77
from email.utils import parseaddr
88

9-
import debug # pyflakes:ignore
10-
11-
from ietf.doc.models import ConsensusDocEvent
12-
from ietf.doc.utils import get_document_content
13-
from ietf.utils.text import fill
149
from django import template
1510
from django.conf import settings
1611
from django.utils.html import escape
1712
from django.template.defaultfilters import truncatewords_html, linebreaksbr, stringfilter, striptags, urlize
1813
from django.utils.safestring import mark_safe, SafeData
1914
from django.utils.html import strip_tags
2015

16+
import debug # pyflakes:ignore
17+
18+
from ietf.doc.models import ConsensusDocEvent
19+
from ietf.doc.utils import get_document_content
20+
from ietf.utils.text import wordwrap, fill, wrap_text_if_unwrapped
21+
22+
2123
register = template.Library()
2224

2325
def collapsebr(html):
@@ -254,64 +256,9 @@ def truncate_ellipsis(text, arg):
254256
def split(text, splitter=None):
255257
return text.split(splitter)
256258

257-
@register.filter(name="wrap_long_lines")
258-
def wrap_long_lines(text, width=72):
259-
"""Wraps long lines without loosing the formatting and indentation
260-
of short lines"""
261-
if not isinstance(text, (types.StringType,types.UnicodeType)):
262-
return text
263-
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
264-
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
265-
text = re.sub("( *\n){3,}", "\n\n", text) # get rid of excessive vertical whitespace
266-
lines = text.split("\n")
267-
filled = []
268-
wrapped = False
269-
for line in lines:
270-
if wrapped and line.strip() != "":
271-
line = filled[-1] + " " + line
272-
filled = filled[:-1]
273-
else:
274-
wrapped = False
275-
while (len(line) > 80) and (" " in line[:80]):
276-
wrapped = True
277-
breakpoint = line.rfind(" ",0,80)
278-
filled += [ line[:breakpoint] ]
279-
line = line[breakpoint+1:]
280-
filled += [ line.rstrip() ]
281-
return "\n".join(filled)
282-
283-
@register.filter(name="wrap_text")
284-
def wrap_text(text, width=72):
285-
"""Wraps long lines without loosing the formatting and indentation
286-
of short lines"""
287-
if not isinstance(text, (types.StringType,types.UnicodeType)):
288-
return text
289-
text = re.sub(" *\r\n", "\n", text) # get rid of DOS line endings
290-
text = re.sub(" *\r", "\n", text) # get rid of MAC line endings
291-
text = re.sub("( *\n){3,}", "\n\n", text) # get rid of excessive vertical whitespace
292-
lines = text.split("\n")
293-
filled = []
294-
wrapped = False
295-
prev_indent = None
296-
for line in lines:
297-
line = line.expandtabs()
298-
indent = " " * (len(line) - len(line.lstrip()))
299-
if wrapped and line.strip() != "" and indent == prev_indent:
300-
line = filled[-1] + " " + line.lstrip()
301-
filled = filled[:-1]
302-
else:
303-
wrapped = False
304-
while (len(line) > width) and (" " in line[:width]):
305-
linelength = len(line)
306-
wrapped = True
307-
breakpoint = line.rfind(" ",0,width)
308-
filled += [ line[:breakpoint] ]
309-
line = indent + line[breakpoint+1:]
310-
if len(line) >= linelength:
311-
break
312-
filled += [ line.rstrip() ]
313-
prev_indent = indent
314-
return "\n".join(filled)
259+
register.filter("maybewordwrap", stringfilter(wrap_text_if_unwrapped))
260+
261+
register.filter("wordwrap", stringfilter(wordwrap))
315262

316263
@register.filter(name="compress_empty_lines")
317264
def compress_empty_lines(text):

ietf/group/mails.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55

66
from django.utils.html import strip_tags
7-
from django.utils.text import wrap
87
from django.conf import settings
98
from django.urls import reverse as urlreverse
109

1110
from ietf.utils.mail import send_mail, send_mail_text
11+
from ietf.utils.text import wordwrap
1212
from ietf.mailtrigger.utils import gather_address_lists
1313

1414
def email_admin_re_charter(request, group, subject, text, mailtrigger):
@@ -39,7 +39,7 @@ def wrap_up_email(addrs, text):
3939
if re.search("Added .* for review, due",text):
4040
subject = u"Review Required - " + subject
4141

42-
text = wrap(strip_tags(text), 70)
42+
text = wordwrap(strip_tags(text), 78)
4343
text += "\n\n"
4444
text += u"URL: %s" % (settings.IDTRACKER_BASE_URL + group.about_url())
4545

ietf/nomcom/templatetags/nomcom_tags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import debug # pyflakes:ignore
1010

11-
from ietf.doc.templatetags.ietf_filters import wrap_text
11+
from ietf.utils.text import wordwrap
1212
from ietf.nomcom.utils import get_nomcom_by_year, retrieve_nomcom_private_key
1313
from ietf.person.models import Person
1414
from ietf.utils.log import log
@@ -71,4 +71,4 @@ def decrypt(string, request, year, plain=False):
7171

7272
if not plain:
7373
return force_escape(linebreaksbr(out))
74-
return mark_safe(wrap_text(force_escape(out)))
74+
return mark_safe(wordwrap(force_escape(out)))

ietf/templates/doc/ballot/ballot_comment_mail.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% autoescape off %}{{ ad }} has entered the following ballot position for
1+
{% load ietf_filters %}{% autoescape off %}{{ ad }} has entered the following ballot position for
22
{{ doc.name }}-{{ doc.rev }}: {{ pos.name }}
33

44
When responding, please keep the subject line intact and reply to all
@@ -21,13 +21,13 @@ There are no remarks associated with this position.
2121
{{ blocking_name }}:
2222
----------------------------------------------------------------------
2323

24-
{{ discuss|safe|wordwrap:73 }}
24+
{{ discuss|safe|maybewordwrap:80 }}
2525

2626

2727
{% endif %}{% if comment %}----------------------------------------------------------------------
2828
COMMENT:
2929
----------------------------------------------------------------------
3030

31-
{{ comment|safe|wordwrap:73 }}
31+
{{ comment|safe|maybewordwrap:80 }}
3232
{% endif %}
3333
{% endautoescape %}

ietf/templates/doc/ballot/send_ballot_comment.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ <h1>Send ballot position for {{ ad }} on <a href="{% url "ietf.doc.views_doc.doc
4242

4343
<div class="form-group">
4444
<label>Body</label>
45-
<pre>{{ body|wrap_text }}</pre>
45+
<pre>{{ body|maybewordwrap }}</pre>
4646
</div>
4747

4848
{% buttons %}

ietf/templates/doc/charter/action_text.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ To: {{ to }}{% if cc %}
33
Cc: {{ cc }} {% endif %}
44
Subject: {{ group.type.name }} Action: {{ action_type }} {{ group.name }} ({{ group.acronym }})
55

6-
{% filter wordwrap:73 %}{% if action_type == "Formed" %}A new {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} {{ group.type.name }} has been formed in the {{ group.parent.name }}.{% endif %}{% if action_type == "Rechartered" %}The {{ group.name }} ({{ group.acronym }}) {{ group.type.name }} in the {{ group.parent.name }} of the {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} has been rechartered.{% endif %} For additional information, please contact the {% if group.type_id == "rg" %}IRTF Chair, the Internet Research Steering Group{% else %}Area Directors{% endif %} or the {{ group.type.name }} Chair{{ chairs|pluralize}}.
6+
{% filter wordwrap:78 %}{% if action_type == "Formed" %}A new {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} {{ group.type.name }} has been formed in the {{ group.parent.name }}.{% endif %}{% if action_type == "Rechartered" %}The {{ group.name }} ({{ group.acronym }}) {{ group.type.name }} in the {{ group.parent.name }} of the {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} has been rechartered.{% endif %} For additional information, please contact the {% if group.type_id == "rg" %}IRTF Chair, the Internet Research Steering Group{% else %}Area Directors{% endif %} or the {{ group.type.name }} Chair{{ chairs|pluralize}}.
77

88
{% include "doc/charter/group_info.txt" %}{% endfilter %}{% endautoescape %}

ietf/templates/doc/charter/charter_with_milestones.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load ietf_filters %}{% autoescape off %}{% filter wrap_long_lines %}{{ charter_text }}{% endfilter %}
1+
{% load ietf_filters %}{% autoescape off %}{% filter maybewordwrap %}{{ charter_text }}{% endfilter %}
22

33
Milestones
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
{% autoescape off %}To: {{ to }} {% if cc %}
1+
{% load ietf_filters %}{% autoescape off %}To: {{ to }} {% if cc %}
22
Cc: {{ cc }}
33
{% endif %}From: IESG Secretary <iesg-secretary@ietf.org>
44
Reply-To: IESG Secretary <iesg-secretary@ietf.org>
55
Subject: Evaluation: {{ doc.name }}
66

7-
{% filter wordwrap:73 %}Evaluation for {{ doc.title }} can be found at {{ doc_url }}
7+
{% filter wordwrap:78 %}Evaluation for {{ doc.title }} can be found at {{ doc_url }}
88
{% endfilter %}
99

1010
{% endautoescape%}

ietf/templates/doc/charter/review_text.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ To: {{ to }}{% if cc %}
33
Cc: {{ cc }} {% endif %}
44
Subject: {{ group.type.name }} Review: {{ group.name }} ({{ group.acronym }})
55

6-
{% filter wordwrap:73 %}{% if review_type == "new" %}A new {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} {{ group.type.name }} has been proposed in the {{ group.parent.name }}.{% elif review_type == "recharter" %}The {{ group.name }} ({{group.acronym}}) {{ group.type.name }} in the {{ group.parent.name }} of the {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} is undergoing rechartering.{% endif %} The {% if group.type_id == "rg" %}IRSG{% else %}IESG{% endif %} has not made any determination yet. The following draft charter was submitted, and is provided for informational purposes only. Please send your comments to the {% if group.type_id == "rg" %}IRSG{% else %}IESG{% endif %} mailing list ({% if group.type_id == "rg" %}irsg@irtf.org{% else %}iesg@ietf.org{% endif %}) by {{ review_date }}.
6+
{% filter wordwrap:78 %}{% if review_type == "new" %}A new {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} {{ group.type.name }} has been proposed in the {{ group.parent.name }}.{% elif review_type == "recharter" %}The {{ group.name }} ({{group.acronym}}) {{ group.type.name }} in the {{ group.parent.name }} of the {% if group.type_id == "rg" %}IRTF{% else %}IETF{% endif %} is undergoing rechartering.{% endif %} The {% if group.type_id == "rg" %}IRSG{% else %}IESG{% endif %} has not made any determination yet. The following draft charter was submitted, and is provided for informational purposes only. Please send your comments to the {% if group.type_id == "rg" %}IRSG{% else %}IESG{% endif %} mailing list ({% if group.type_id == "rg" %}irsg@irtf.org{% else %}iesg@ietf.org{% endif %}) by {{ review_date }}.
77

88
{% include "doc/charter/group_info.txt" %}{% endfilter %}{% endautoescape %}

ietf/templates/doc/conflict_review/approval_text.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{% load mail_filters %}{% autoescape off %}From: The IESG <iesg-secretary@ietf.org>
1+
{% load ietf_filters %}{% load mail_filters %}{% autoescape off %}From: The IESG <iesg-secretary@ietf.org>
22
To: {{ to }}
33
Cc: {{ cc }}
44
Subject: Results of IETF-conflict review for {{conflictdoc.canonical_name}}-{{conflictdoc.rev}}
55

6-
{% filter wordwrap:73 %}The IESG has completed a review of {{conflictdoc.canonical_name}}-{{conflictdoc.rev}} consistent with RFC5742.
6+
{% filter wordwrap:78 %}The IESG has completed a review of {{conflictdoc.canonical_name}}-{{conflictdoc.rev}} consistent with RFC5742.
77

88
{% if review.get_state_slug == 'appr-reqnopub-pend' %}
99
The IESG recommends that '{{ conflictdoc.title }}' {{ conflictdoc.file_tag|safe }} NOT be published as {{ conflictdoc|std_level_prompt_with_article }}.

0 commit comments

Comments
 (0)