Skip to content

Instantly share code, notes, and snippets.

@chronossc
Created May 2, 2011 16:37
Show Gist options
  • Save chronossc/951892 to your computer and use it in GitHub Desktop.
Save chronossc/951892 to your computer and use it in GitHub Desktop.
diff -ur django_original/template//debug.py django/template//debug.py
--- django_original/template//debug.py 2011-05-02 13:36:03.872849001 -0300
+++ django/template//debug.py 2011-05-05 14:17:20.522849008 -0300
@@ -87,6 +87,7 @@
def render(self, context):
try:
output = self.filter_expression.resolve(context)
+ output = self.clean_pks(output)
output = localize(output)
output = force_unicode(output)
except TemplateSyntaxError, e:
@@ -95,6 +96,7 @@
raise
except UnicodeDecodeError:
return ''
+
if (context.autoescape and not isinstance(output, SafeData)) or isinstance(output, EscapeData):
return escape(output)
else:
diff -ur django_original/template//__init__.py django/template//__init__.py
--- django_original/template//__init__.py 2011-05-02 13:36:03.872849001 -0300
+++ django/template//__init__.py 2011-05-05 13:58:18.882848995 -0300
@@ -839,6 +839,14 @@
def __repr__(self):
return "<Variable Node: %s>" % self.filter_expression
+ def clean_pks(self, output):
+ # avoid localization of pk or ids
+ var_token = self.filter_expression.token
+ filters = self.filter_expression.filters
+ if ((var_token.endswith('.pk') and type(output) in (long,int)) or var_token.endswith('.id')) and not filters:
+ output = mark_safe(output)
+ return output
+
def render(self, context):
try:
output = self.filter_expression.resolve(context)
@@ -846,6 +854,9 @@
# Unicode conversion can fail sometimes for reasons out of our
# control (e.g. exception rendering). In that case, we fail quietly.
return ''
+
+ output = self.clean_pks(output)
+
return _render_value_in_context(output, context)
def generic_tag_compiler(params, defaults, name, node_class, parser, token):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment