Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #15535 -- Stopped the blocktrans template tag from rais…

…ing a KeyError if an included variable can't be found in the context. Thanks, melinath.

Backport from trunk (r15709).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15710 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b34a08e07019eca965d48a15caebcc9cc90b0edc 1 parent 7207481
Jannis Leidel authored March 02, 2011
2  django/templatetags/i18n.py
@@ -83,7 +83,7 @@ def render(self, context):
83 83
             result = translation.ugettext(singular)
84 84
         # Escape all isolated '%' before substituting in the context.
85 85
         result = re.sub(u'%(?!\()', u'%%', result)
86  
-        data = dict([(v, _render_value_in_context(context[v], context)) for v in vars])
  86
+        data = dict([(v, _render_value_in_context(context.get(v, ''), context)) for v in vars])
87 87
         context.pop()
88 88
         return result % data
89 89
 
3  tests/regressiontests/templates/tests.py
@@ -1138,6 +1138,9 @@ def get_template_tests(self):
1138 1138
             # translation of singular form in russian (#14126)
1139 1139
             'i18n27': ('{% load i18n %}{% blocktrans count number as counter %}1 result{% plural %}{{ counter }} results{% endblocktrans %}', {'number': 1, 'LANGUAGE_CODE': 'ru'}, u'1 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442'),
1140 1140
 
  1141
+            # blocktrans handling of variables which are not in the context.
  1142
+            'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, u''),
  1143
+
1141 1144
             ### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
1142 1145
 
1143 1146
             'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')),

0 notes on commit b34a08e

Please sign in to comment.
Something went wrong with that request. Please try again.