From 09f3f51c77d8916ed5a9b6fe7fc510de45b0b4aa Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 24 Apr 2015 20:38:36 +0000 Subject: [PATCH] Added support for an 'origin' template tag which will insert the name of the template file (within a html comment) into the page content when TEMPLATE_DEBUG is True; with the purpose of more easily being able to identify the templates from which page content comes. - Legacy-Id: 9550 --- ietf/utils/templatetags/__init__.py | 0 ietf/utils/templatetags/origin.py | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ietf/utils/templatetags/__init__.py create mode 100644 ietf/utils/templatetags/origin.py diff --git a/ietf/utils/templatetags/__init__.py b/ietf/utils/templatetags/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/ietf/utils/templatetags/origin.py b/ietf/utils/templatetags/origin.py new file mode 100644 index 000000000..3ac3028d9 --- /dev/null +++ b/ietf/utils/templatetags/origin.py @@ -0,0 +1,27 @@ +from django import template +import debug # pyflakes:ignore + +register = template.Library() + + +class OriginNode(template.Node): + def __init__(self, origin=None): + # template file path if the template comes from a file: + self.origin = origin + + def render(self, context): + if self.origin: + return "" % self.origin + else: + return "" + +@register.tag +def origin(parser, token): + """ + Returns a node which renders the + """ + if hasattr(token, "source"): + origin, source = token.source + return OriginNode(origin=origin) + else: + return OriginNode()