|
@@ -22,6 +22,7 @@
|
|
|
# Django imports.
|
|
|
from django import template
|
|
|
from django.core import urlresolvers
|
|
|
from django.utils.html import format_html
|
|
|
|
|
|
|
|
|
# Get an instance of Django's template library.
|
|
@@ -54,26 +55,34 @@ def html_link(text, view, *args, **kwarg
|
|
|
|
|
|
"""
|
|
|
|
|
|
# Verify the passed-in keyword arguments first.
|
|
|
for key in kwargs.keys():
|
|
|
if key not in ("get", "class", "title", "id"):
|
|
|
raise template.TemplateSyntaxError("Unknown argument for 'html_link' tag: %r" % key)
|
|
|
|
|
|
# Generate the URL by using the supplied view name and arguments that should
|
|
|
# be passed to the view.
|
|
|
url = urlresolvers.reverse(view, args=args)
|
|
|
|
|
|
# Set-up the base pattern (url, parameters, text).
|
|
|
pattern = '<a href="%s" %s>%s</a>'
|
|
|
if 'get' in kwargs:
|
|
|
pattern = '<a href="{url}?{get}"'
|
|
|
else:
|
|
|
pattern = '<a href="{url}"'
|
|
|
|
|
|
if 'class' in kwargs:
|
|
|
pattern += ' class="{class}"'
|
|
|
|
|
|
# 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)
|
|
|
if 'title' in kwargs:
|
|
|
pattern += ' title="{title}"'
|
|
|
|
|
|
if 'id' in kwargs:
|
|
|
pattern += ' id="{id}"'
|
|
|
|
|
|
pattern += '>{text}</a>'
|
|
|
|
|
|
# Render the tag.
|
|
|
return pattern % (url, params, text)
|
|
|
return format_html(pattern, url=url, text=text, **kwargs)
|
|
|
|
|
|
|
|
|
@register.simple_tag(takes_context=True)
|