from __future__ import unicode_literals

from django import template
from django.urls import reverse

from pictures.models import Picture


register = template.Library()


@register.filter(name='set_css_class')
def set_css_class(field, css_class):
    return field.as_widget(attrs={"class": css_class})


@register.filter(name='get_details_url')
def get_details_url(item):

    obj = item.content_type.get_object_for_this_type(id=item.id)

    if isinstance(obj, Picture):
        return reverse('frontend:pictures:detail', kwargs={'pk': str(obj.id)})

    return ''
