diff options
| author | Emil Stenstròˆm <em@kth.se> | 2013-05-18 13:58:45 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-05-18 23:01:48 +0200 |
| commit | 7d77e9786a118dd95a268872dd9d36664066b96a (patch) | |
| tree | 8680cbbad6c00012a07119027532e897f5a4b022 /django/utils | |
| parent | caf56ad1743778bad8af6b51b08f5baa342d4cd2 (diff) | |
Fixed #20246 -- Added non-breaking spaces between values an units
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/html.py | 7 | ||||
| -rw-r--r-- | django/utils/timesince.py | 7 |
2 files changed, 11 insertions, 3 deletions
diff --git a/django/utils/html.py b/django/utils/html.py index 8b28d97d13..edddc48e62 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -281,3 +281,10 @@ def clean_html(text): text = trailing_empty_content_re.sub('', text) return text clean_html = allow_lazy(clean_html, six.text_type) + +def avoid_wrapping(value): + """ + Avoid text wrapping in the middle of a phrase by adding non-breaking + spaces where there previously were normal spaces. + """ + return value.replace(" ", "\xa0") diff --git a/django/utils/timesince.py b/django/utils/timesince.py index d70ab2ffe1..46c387f262 100644 --- a/django/utils/timesince.py +++ b/django/utils/timesince.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import datetime +from django.utils.html import avoid_wrapping from django.utils.timezone import is_aware, utc from django.utils.translation import ugettext, ungettext_lazy @@ -40,18 +41,18 @@ def timesince(d, now=None, reversed=False): since = delta.days * 24 * 60 * 60 + delta.seconds if since <= 0: # d is in the future compared to now, stop processing. - return ugettext('0 minutes') + return avoid_wrapping(ugettext('0 minutes')) for i, (seconds, name) in enumerate(chunks): count = since // seconds if count != 0: break - result = name % count + result = avoid_wrapping(name % count) if i + 1 < len(chunks): # Now get the second item seconds2, name2 = chunks[i + 1] count2 = (since - (seconds * count)) // seconds2 if count2 != 0: - result += ugettext(', ') + name2 % count2 + result += ugettext(', ') + avoid_wrapping(name2 % count2) return result def timeuntil(d, now=None): |
