from django import template
from django.utils.http import urlquote

register = template.Library()

@register.inclusion_tag('jocondelab/partial/datasheet_row.html', takes_context=True)
def show_datasheet_row(context, fieldname, *args, **kwargs):
    isbold = kwargs.get('isbold',False)
    return {
            "isbold": isbold,
            "fieldname": fieldname,
            "linked_terms": context['terms_by_thesaurus'].get(fieldname.upper(),None),
            "base_field": getattr(context['object'],fieldname.lower())
    }

@register.filter
def wikiurl(label, lang):
    if label:
        return u"http://%s.wikipedia.org/wiki/%s"%(lang, urlquote(label.replace(" ","_")))
    else:
        return u"http://%s.wikipedia.org/"%lang