Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -536,6 +536,7 @@ answer newbie questions, and generally made Django that much better: starrynight <cmorgh@gmail.com> Vasiliy Stavenko <stavenko@gmail.com> Thomas Steinacher <http://www.eggdrop.ch/> Emil Stenström <em@kth.se> Johan C. Stöver <johan@nilling.nl> Nowell Strite <http://nowell.strite.org/> Thomas Stromberg <tstromberg@google.com> Loading django/contrib/humanize/templatetags/humanize.py +12 −6 Original line number Diff line number Diff line Loading @@ -194,17 +194,20 @@ def naturaltime(value): return _('now') elif delta.seconds < 60: return ungettext( 'a second ago', '%(count)s seconds ago', delta.seconds # Translators: \\u00a0 is non-breaking space 'a second ago', '%(count)s\u00a0seconds ago', delta.seconds ) % {'count': delta.seconds} elif delta.seconds // 60 < 60: count = delta.seconds // 60 return ungettext( 'a minute ago', '%(count)s minutes ago', count # Translators: \\u00a0 is non-breaking space 'a minute ago', '%(count)s\u00a0minutes ago', count ) % {'count': count} else: count = delta.seconds // 60 // 60 return ungettext( 'an hour ago', '%(count)s hours ago', count # Translators: \\u00a0 is non-breaking space 'an hour ago', '%(count)s\u00a0hours ago', count ) % {'count': count} else: delta = value - now Loading @@ -216,15 +219,18 @@ def naturaltime(value): return _('now') elif delta.seconds < 60: return ungettext( 'a second from now', '%(count)s seconds from now', delta.seconds # Translators: \\u00a0 is non-breaking space 'a second from now', '%(count)s\u00a0seconds from now', delta.seconds ) % {'count': delta.seconds} elif delta.seconds // 60 < 60: count = delta.seconds // 60 return ungettext( 'a minute from now', '%(count)s minutes from now', count # Translators: \\u00a0 is non-breaking space 'a minute from now', '%(count)s\u00a0minutes from now', count ) % {'count': count} else: count = delta.seconds // 60 // 60 return ungettext( 'an hour from now', '%(count)s hours from now', count # Translators: \\u00a0 is non-breaking space 'an hour from now', '%(count)s\u00a0hours from now', count ) % {'count': count} django/contrib/humanize/tests.py +13 −13 Original line number Diff line number Diff line Loading @@ -195,22 +195,22 @@ class HumanizeTests(TestCase): result_list = [ 'now', 'a second ago', '30 seconds ago', '30\xa0seconds ago', 'a minute ago', '2 minutes ago', '2\xa0minutes ago', 'an hour ago', '23 hours ago', '1 day ago', '1 year, 4 months ago', '23\xa0hours ago', '1\xa0day ago', '1\xa0year, 4\xa0months ago', 'a second from now', '30 seconds from now', '30\xa0seconds from now', 'a minute from now', '2 minutes from now', '2\xa0minutes from now', 'an hour from now', '23 hours from now', '1 day from now', '2 days, 6 hours from now', '1 year, 4 months from now', '23\xa0hours from now', '1\xa0day from now', '2\xa0days, 6\xa0hours from now', '1\xa0year, 4\xa0months from now', 'now', 'now', ] Loading @@ -218,8 +218,8 @@ class HumanizeTests(TestCase): # date in naive arithmetic is only 2 days and 5 hours after in # aware arithmetic. result_list_with_tz_support = result_list[:] assert result_list_with_tz_support[-4] == '2 days, 6 hours from now' result_list_with_tz_support[-4] == '2 days, 5 hours from now' assert result_list_with_tz_support[-4] == '2\xa0days, 6\xa0hours from now' result_list_with_tz_support[-4] == '2\xa0days, 5\xa0hours from now' orig_humanize_datetime, humanize.datetime = humanize.datetime, MockDateTime try: Loading django/template/defaultfilters.py +16 −12 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ from django.utils import formats from django.utils.dateformat import format, time_format from django.utils.encoding import force_text, iri_to_uri from django.utils.html import (conditional_escape, escapejs, fix_ampersands, escape, urlize as urlize_impl, linebreaks, strip_tags) escape, urlize as urlize_impl, linebreaks, strip_tags, avoid_wrapping) from django.utils.http import urlquote from django.utils.text import Truncator, wrap, phone2numeric from django.utils.safestring import mark_safe, SafeData, mark_for_escaping Loading Loading @@ -810,7 +810,8 @@ def filesizeformat(bytes): try: bytes = float(bytes) except (TypeError,ValueError,UnicodeDecodeError): return ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) filesize_number_format = lambda value: formats.number_format(round(value, 1), 1) Loading @@ -821,16 +822,19 @@ def filesizeformat(bytes): PB = 1<<50 if bytes < KB: return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} if bytes < MB: return ugettext("%s KB") % filesize_number_format(bytes / KB) if bytes < GB: return ugettext("%s MB") % filesize_number_format(bytes / MB) if bytes < TB: return ugettext("%s GB") % filesize_number_format(bytes / GB) if bytes < PB: return ugettext("%s TB") % filesize_number_format(bytes / TB) return ugettext("%s PB") % filesize_number_format(bytes / PB) value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} elif bytes < MB: value = ugettext("%s KB") % filesize_number_format(bytes / KB) elif bytes < GB: value = ugettext("%s MB") % filesize_number_format(bytes / MB) elif bytes < TB: value = ugettext("%s GB") % filesize_number_format(bytes / GB) elif bytes < PB: value = ugettext("%s TB") % filesize_number_format(bytes / TB) else: value = ugettext("%s PB") % filesize_number_format(bytes / PB) return avoid_wrapping(value) @register.filter(is_safe=False) def pluralize(value, arg='s'): Loading django/utils/html.py +7 −0 Original line number Diff line number Diff line Loading @@ -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") Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -536,6 +536,7 @@ answer newbie questions, and generally made Django that much better: starrynight <cmorgh@gmail.com> Vasiliy Stavenko <stavenko@gmail.com> Thomas Steinacher <http://www.eggdrop.ch/> Emil Stenström <em@kth.se> Johan C. Stöver <johan@nilling.nl> Nowell Strite <http://nowell.strite.org/> Thomas Stromberg <tstromberg@google.com> Loading
django/contrib/humanize/templatetags/humanize.py +12 −6 Original line number Diff line number Diff line Loading @@ -194,17 +194,20 @@ def naturaltime(value): return _('now') elif delta.seconds < 60: return ungettext( 'a second ago', '%(count)s seconds ago', delta.seconds # Translators: \\u00a0 is non-breaking space 'a second ago', '%(count)s\u00a0seconds ago', delta.seconds ) % {'count': delta.seconds} elif delta.seconds // 60 < 60: count = delta.seconds // 60 return ungettext( 'a minute ago', '%(count)s minutes ago', count # Translators: \\u00a0 is non-breaking space 'a minute ago', '%(count)s\u00a0minutes ago', count ) % {'count': count} else: count = delta.seconds // 60 // 60 return ungettext( 'an hour ago', '%(count)s hours ago', count # Translators: \\u00a0 is non-breaking space 'an hour ago', '%(count)s\u00a0hours ago', count ) % {'count': count} else: delta = value - now Loading @@ -216,15 +219,18 @@ def naturaltime(value): return _('now') elif delta.seconds < 60: return ungettext( 'a second from now', '%(count)s seconds from now', delta.seconds # Translators: \\u00a0 is non-breaking space 'a second from now', '%(count)s\u00a0seconds from now', delta.seconds ) % {'count': delta.seconds} elif delta.seconds // 60 < 60: count = delta.seconds // 60 return ungettext( 'a minute from now', '%(count)s minutes from now', count # Translators: \\u00a0 is non-breaking space 'a minute from now', '%(count)s\u00a0minutes from now', count ) % {'count': count} else: count = delta.seconds // 60 // 60 return ungettext( 'an hour from now', '%(count)s hours from now', count # Translators: \\u00a0 is non-breaking space 'an hour from now', '%(count)s\u00a0hours from now', count ) % {'count': count}
django/contrib/humanize/tests.py +13 −13 Original line number Diff line number Diff line Loading @@ -195,22 +195,22 @@ class HumanizeTests(TestCase): result_list = [ 'now', 'a second ago', '30 seconds ago', '30\xa0seconds ago', 'a minute ago', '2 minutes ago', '2\xa0minutes ago', 'an hour ago', '23 hours ago', '1 day ago', '1 year, 4 months ago', '23\xa0hours ago', '1\xa0day ago', '1\xa0year, 4\xa0months ago', 'a second from now', '30 seconds from now', '30\xa0seconds from now', 'a minute from now', '2 minutes from now', '2\xa0minutes from now', 'an hour from now', '23 hours from now', '1 day from now', '2 days, 6 hours from now', '1 year, 4 months from now', '23\xa0hours from now', '1\xa0day from now', '2\xa0days, 6\xa0hours from now', '1\xa0year, 4\xa0months from now', 'now', 'now', ] Loading @@ -218,8 +218,8 @@ class HumanizeTests(TestCase): # date in naive arithmetic is only 2 days and 5 hours after in # aware arithmetic. result_list_with_tz_support = result_list[:] assert result_list_with_tz_support[-4] == '2 days, 6 hours from now' result_list_with_tz_support[-4] == '2 days, 5 hours from now' assert result_list_with_tz_support[-4] == '2\xa0days, 6\xa0hours from now' result_list_with_tz_support[-4] == '2\xa0days, 5\xa0hours from now' orig_humanize_datetime, humanize.datetime = humanize.datetime, MockDateTime try: Loading
django/template/defaultfilters.py +16 −12 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ from django.utils import formats from django.utils.dateformat import format, time_format from django.utils.encoding import force_text, iri_to_uri from django.utils.html import (conditional_escape, escapejs, fix_ampersands, escape, urlize as urlize_impl, linebreaks, strip_tags) escape, urlize as urlize_impl, linebreaks, strip_tags, avoid_wrapping) from django.utils.http import urlquote from django.utils.text import Truncator, wrap, phone2numeric from django.utils.safestring import mark_safe, SafeData, mark_for_escaping Loading Loading @@ -810,7 +810,8 @@ def filesizeformat(bytes): try: bytes = float(bytes) except (TypeError,ValueError,UnicodeDecodeError): return ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) filesize_number_format = lambda value: formats.number_format(round(value, 1), 1) Loading @@ -821,16 +822,19 @@ def filesizeformat(bytes): PB = 1<<50 if bytes < KB: return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} if bytes < MB: return ugettext("%s KB") % filesize_number_format(bytes / KB) if bytes < GB: return ugettext("%s MB") % filesize_number_format(bytes / MB) if bytes < TB: return ugettext("%s GB") % filesize_number_format(bytes / GB) if bytes < PB: return ugettext("%s TB") % filesize_number_format(bytes / TB) return ugettext("%s PB") % filesize_number_format(bytes / PB) value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} elif bytes < MB: value = ugettext("%s KB") % filesize_number_format(bytes / KB) elif bytes < GB: value = ugettext("%s MB") % filesize_number_format(bytes / MB) elif bytes < TB: value = ugettext("%s GB") % filesize_number_format(bytes / GB) elif bytes < PB: value = ugettext("%s TB") % filesize_number_format(bytes / TB) else: value = ugettext("%s PB") % filesize_number_format(bytes / PB) return avoid_wrapping(value) @register.filter(is_safe=False) def pluralize(value, arg='s'): Loading
django/utils/html.py +7 −0 Original line number Diff line number Diff line Loading @@ -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")