~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/template/defaultfilters.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import re
5
5
import random as random_module
6
 
import unicodedata
7
6
from decimal import Decimal, InvalidOperation, Context, ROUND_HALF_UP
8
7
from functools import wraps
9
8
from pprint import pformat
14
13
from django.utils.dateformat import format, time_format
15
14
from django.utils.encoding import force_text, iri_to_uri
16
15
from django.utils.html import (conditional_escape, escapejs, fix_ampersands,
17
 
    escape, urlize as urlize_impl, linebreaks, strip_tags)
 
16
    escape, urlize as urlize_impl, linebreaks, strip_tags, avoid_wrapping)
18
17
from django.utils.http import urlquote
19
18
from django.utils.text import Truncator, wrap, phone2numeric
20
19
from django.utils.safestring import mark_safe, SafeData, mark_for_escaping
49
48
    # when multiple decorators are applied).
50
49
    _dec._decorated_function = getattr(func, '_decorated_function', func)
51
50
 
52
 
    for attr in ('is_safe', 'needs_autoescape'):
53
 
        if hasattr(func, attr):
54
 
            import warnings
55
 
            warnings.warn("Setting the %s attribute of a template filter "
56
 
                          "function is deprecated; use @register.filter(%s=%s) "
57
 
                          "instead" % (attr, attr, getattr(func, attr)),
58
 
                          DeprecationWarning)
59
 
            setattr(_dec, attr, getattr(func, attr))
60
 
 
61
51
    return wraps(func)(_dec)
62
52
 
63
53
 
560
550
    Returns a slice of the list.
561
551
 
562
552
    Uses the same syntax as Python's list slicing; see
563
 
    http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice
 
553
    http://www.diveintopython3.net/native-datatypes.html#slicinglists
564
554
    for an introduction.
565
555
    """
566
556
    try:
819
809
    try:
820
810
        bytes = float(bytes)
821
811
    except (TypeError,ValueError,UnicodeDecodeError):
822
 
        return ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
 
812
        value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
 
813
        return avoid_wrapping(value)
823
814
 
824
815
    filesize_number_format = lambda value: formats.number_format(round(value, 1), 1)
825
816
 
830
821
    PB = 1<<50
831
822
 
832
823
    if bytes < KB:
833
 
        return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
834
 
    if bytes < MB:
835
 
        return ugettext("%s KB") % filesize_number_format(bytes / KB)
836
 
    if bytes < GB:
837
 
        return ugettext("%s MB") % filesize_number_format(bytes / MB)
838
 
    if bytes < TB:
839
 
        return ugettext("%s GB") % filesize_number_format(bytes / GB)
840
 
    if bytes < PB:
841
 
        return ugettext("%s TB") % filesize_number_format(bytes / TB)
842
 
    return ugettext("%s PB") % filesize_number_format(bytes / PB)
 
824
        value = ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes}
 
825
    elif bytes < MB:
 
826
        value = ugettext("%s KB") % filesize_number_format(bytes / KB)
 
827
    elif bytes < GB:
 
828
        value = ugettext("%s MB") % filesize_number_format(bytes / MB)
 
829
    elif bytes < TB:
 
830
        value = ugettext("%s GB") % filesize_number_format(bytes / GB)
 
831
    elif bytes < PB:
 
832
        value = ugettext("%s TB") % filesize_number_format(bytes / TB)
 
833
    else:
 
834
        value = ugettext("%s PB") % filesize_number_format(bytes / PB)
 
835
 
 
836
    return avoid_wrapping(value)
843
837
 
844
838
@register.filter(is_safe=False)
845
839
def pluralize(value, arg='s'):