Commits

João Pedro Francese committed 86b3f5d Merge

Merge

  • Participants
  • Parent commits bd18bd3, 817f448

Comments (0)

Files changed (2)

inoa/templatetags/__init__.py

Empty file added.

inoa/templatetags/absurl.py

+# -*- coding: utf-8 -*-
+
+# Downloaded on 2011-07-03 from http://djangosnippets.org/snippets/1518/
+# Edited with junckritter's change from http://djangosnippets.org/snippets/1518/#c2336
+
+from django.contrib.sites.models import Site
+from django.template import Library
+from django.template.defaulttags import URLNode, url
+import urlparse
+
+register = Library()
+
+class AbsoluteURLNode(URLNode):
+    def render(self, context):
+        path = super(AbsoluteURLNode, self).render(context)
+        # domain = settings.ABSOLUTE_BASE_URL
+        domain = "http://%s" % Site.objects.get_current().domain
+        if self.asvar:
+            context[self.asvar] = urlparse.urljoin(domain, context[self.asvar])
+            return ''
+        else:
+            return urlparse.urljoin(domain, path)
+
+def absurl(parser, token, node_cls=AbsoluteURLNode):
+    """Just like {% url %} but ads the domain of the current site."""
+    node_instance = url(parser, token)
+    return node_cls(view_name=node_instance.view_name,
+        args=node_instance.args,
+        kwargs=node_instance.kwargs,
+        asvar=node_instance.asvar)
+absurl = register.tag(absurl)
+
+