diff --git a/conntrackt/templates/conntrackt/html_link.html b/conntrackt/templates/conntrackt/html_link.html deleted file mode 100644 --- a/conntrackt/templates/conntrackt/html_link.html +++ /dev/null @@ -1,2 +0,0 @@ -{% load url from future %} -{{text}} diff --git a/conntrackt/templatetags/conntrackt_tags.py b/conntrackt/templatetags/conntrackt_tags.py --- a/conntrackt/templatetags/conntrackt_tags.py +++ b/conntrackt/templatetags/conntrackt_tags.py @@ -7,7 +7,7 @@ from django.core import urlresolvers register = template.Library() -@register.inclusion_tag('conntrackt/html_link.html') +@register.simple_tag(takes_context=False) def html_link(text, view, *args, **kwargs): """ A small wrapper for showing HTML links. @@ -33,23 +33,26 @@ def html_link(text, view, *args, **kwarg """ - # We'll return a context for rendering with the template. Add the text right - # away. - context = {'text': text} - # Generate the URL by using the supplied view name and arguments that should # be passed to the view. - context['url'] = urlresolvers.reverse(view, args=args) + url = urlresolvers.reverse(view, args=args) + + # Set-up the base pattern (url, parameters, text). + pattern = '%s' - # Iterate over keyword arguments, and if we support them, just assign them - # to the context as is. Raise an exception if a keyword is unsupported. - for key, value in kwargs.items(): - if key in ("class", "title", "id", "get"): - context[key] = value + # Iterate over keyword arguments, and if they're supported, add them to + # parameters. + params = "" + for key, value in kwargs.iteritems(): + if key in ("class", "title", "id"): + params += '%s="%s" ' % (key, value) + elif key == "get": + url += "?%s" % value else: raise template.TemplateSyntaxError("Unknown argument for 'advhtml_link' tag: %r" % key) - return context + # Render the tag. + return pattern % (url, params, text) @register.simple_tag(takes_context=True)