Changeset - 1b1abce6b0bb
[Not reviewed]
default
1 1 0
Branko Majic (branko) - 11 years ago 2013-07-25 20:29:57
branko@majic.rs
Noticket: Replaced template-based tag for HTML links with a simple string return.
2 files changed with 15 insertions and 14 deletions:
0 comments (0 inline, 0 general)
conntrackt/templates/conntrackt/html_link.html
Show inline comments
 
deleted file
conntrackt/templatetags/conntrackt_tags.py
Show inline comments
 
@@ -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 = '<a href="%s" %s>%s</a>'
 

	
 
    # 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)
0 comments (0 inline, 0 general)