diff options
author | Arthur Koziel <arthur@arthurkoziel.com> | 2010-09-13 00:04:27 +0000 |
---|---|---|
committer | Arthur Koziel <arthur@arthurkoziel.com> | 2010-09-13 00:04:27 +0000 |
commit | dd49269c7db008b2567f50cb03c4d3d9b321daa1 (patch) | |
tree | 326dd25bb045ac016cda7966b43cbdfe1f67d699 /django/template | |
parent | c9b188c4ec939abbe48dae5a371276742e64b6b8 (diff) | |
download | django-soc2010/app-loading.tar.gz |
[soc2010/app-loading] merged trunkarchive/soc2010/app-loadingsoc2010/app-loading
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13818 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template')
-rw-r--r-- | django/template/defaultfilters.py | 16 | ||||
-rw-r--r-- | django/template/defaulttags.py | 13 |
2 files changed, 22 insertions, 7 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 4b720093b3..739f50f235 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -11,9 +11,10 @@ except ImportError: from django.template import Variable, Library from django.conf import settings from django.utils import formats -from django.utils.translation import ugettext, ungettext from django.utils.encoding import force_unicode, iri_to_uri +from django.utils.html import conditional_escape from django.utils.safestring import mark_safe, SafeData +from django.utils.translation import ugettext, ungettext register = Library() @@ -255,6 +256,8 @@ def truncatewords(value, arg): Truncates a string after a certain number of words. Argument: Number of words to truncate after. + + Newlines within the string are removed. """ from django.utils.text import truncate_words try: @@ -270,6 +273,8 @@ def truncatewords_html(value, arg): Truncates HTML after a certain number of words. Argument: Number of words to truncate after. + + Newlines in the HTML are preserved. """ from django.utils.text import truncate_html_words try: @@ -496,10 +501,9 @@ def join(value, arg, autoescape=None): """ value = map(force_unicode, value) if autoescape: - from django.utils.html import conditional_escape value = [conditional_escape(v) for v in value] try: - data = arg.join(value) + data = conditional_escape(arg).join(value) except AttributeError: # fail silently but nicely return value return mark_safe(data) @@ -809,7 +813,11 @@ def filesizeformat(bytes): return ugettext("%.1f KB") % (bytes / 1024) if bytes < 1024 * 1024 * 1024: return ugettext("%.1f MB") % (bytes / (1024 * 1024)) - return ugettext("%.1f GB") % (bytes / (1024 * 1024 * 1024)) + if bytes < 1024 * 1024 * 1024 * 1024: + return ugettext("%.1f GB") % (bytes / (1024 * 1024 * 1024)) + if bytes < 1024 * 1024 * 1024 * 1024 * 1024: + return ugettext("%.1f TB") % (bytes / (1024 * 1024 * 1024 * 1024)) + return ugettext("%.1f PB") % (bytes / (1024 * 1024 * 1024 * 1024 * 1024)) filesizeformat.is_safe = True def pluralize(value, arg=u's'): diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 318ae5ffd2..1b07413530 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -42,7 +42,7 @@ class CsrfTokenNode(Node): if csrf_token == 'NOTPROVIDED': return mark_safe(u"") else: - return mark_safe(u"<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='%s' /></div>" % (csrf_token)) + return mark_safe(u"<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='%s' /></div>" % csrf_token) else: # It's very probable that the token is missing because of # misconfiguration, so we raise a warning @@ -157,15 +157,22 @@ class ForNode(Node): loop_dict['first'] = (i == 0) loop_dict['last'] = (i == len_values - 1) + pop_context = False if unpack: # If there are multiple loop variables, unpack the item into # them. - context.update(dict(zip(self.loopvars, item))) + try: + unpacked_vars = dict(zip(self.loopvars, item)) + except TypeError: + pass + else: + pop_context = True + context.update(unpacked_vars) else: context[self.loopvars[0]] = item for node in self.nodelist_loop: nodelist.append(node.render(context)) - if unpack: + if pop_context: # The loop variables were pushed on to the context so pop them # off again. This is necessary because the tag lets the length # of loopvars differ to the length of each set of items and we |