diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2012-01-15 02:01:21 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2012-01-15 02:01:21 +0000 |
| commit | c5dcba4159e00ed7fc43b605946be489602ab369 (patch) | |
| tree | e020844b70f1caec24b50ba384f6d7182c8823db /django | |
| parent | e308cfc0e155f51f14c8eb4e678c15c5f632ae30 (diff) | |
Made dictsort and dictsort reversed template filters fail silently
when passed list of things that aren't dictionaries.
Thanks Harris Lapiroff for the report and Daniel Barreto for the patch.
Fixes #15652.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17374 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/defaultfilters.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 9eabb6dd60..f93e799535 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -7,7 +7,7 @@ from decimal import Decimal, InvalidOperation, Context, ROUND_HALF_UP from functools import wraps from pprint import pformat -from django.template.base import Variable, Library +from django.template.base import Variable, Library, VariableDoesNotExist from django.conf import settings from django.utils import formats from django.utils.dateformat import format, time_format @@ -490,7 +490,10 @@ def dictsort(value, arg): Takes a list of dicts, returns that list sorted by the property given in the argument. """ - return sorted(value, key=Variable(arg).resolve) + try: + return sorted(value, key=Variable(arg).resolve) + except (TypeError, VariableDoesNotExist): + return u'' @register.filter(is_safe=False) def dictsortreversed(value, arg): @@ -498,7 +501,10 @@ def dictsortreversed(value, arg): Takes a list of dicts, returns that list sorted in reverse order by the property given in the argument. """ - return sorted(value, key=Variable(arg).resolve, reverse=True) + try: + return sorted(value, key=Variable(arg).resolve, reverse=True) + except (TypeError, VariableDoesNotExist): + return u'' @register.filter(is_safe=False) def first(value): |
