Created
June 20, 2012 14:12
-
-
Save felipe-prenholato/2960098 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iff --git a/django/template/__init__.py b/django/template/__init__.py | |
index 8c89c67..576e7b1 100644 | |
--- a/django/template/__init__.py | |
+++ b/django/template/__init__.py | |
@@ -839,6 +839,14 @@ class VariableNode(Node): | |
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 @@ class VariableNode(Node): | |
# 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