from django import template
from django.utils.safestring import mark_safe

from favicon.models import Favicon, config

register = template.Library()


@register.simple_tag(takes_context=True)
def placeFavicon(context):
    """
    Gets Favicon-URL for the Model.

    Template Syntax:

        {% placeFavicon %}

    """
    fav = Favicon.objects.filter(isFavicon=True).first()
    if not fav:
        return '<!-- no favicon -->'
    html = ''
    for rel in config:
        for size in sorted(config[rel], reverse=True):
            n = fav.get_favicon(size=size, rel=rel)
            html += '<link rel="%s" size ="%sx%s" href="%s"/>' % (
                n.rel, n.size, n.size, n.faviconImage.url)

    default_fav = fav.get_favicon(size=32, rel='shortcut icon')
    html += '<link rel="%s" size ="%sx%s" href="%s"/>' % (
        default_fav.rel, default_fav.size, default_fav.size, default_fav.faviconImage.url)

    return mark_safe(html)

@@ -601,33 +601,33 @@
 nk rel=%22%25s%22 size
- 
+s
 =%22%25sx%25s%22 href=%22%25
@@ -792,17 +792,17 @@
 %25s%22 size
- 
+s
 =%22%25sx%25s%22

Set propper link attribute 'sizes' in templatetag