import logging

from django import template

register = template.Library()

logger = logging.getLogger(__name__)


@register.filter(name="is_selected")
def value(tree_category, category):
    logger.error("Don't use ocyan_oscar templatetags, use oxyan instead")
    return category.path.startswith(tree_category.path[:-4])


@register.simple_tag
def rootimage(category):
    logger.error("Don't use ocyan_oscar templatetags, use oxyan instead")
    for cat in category.get_ancestors_and_self():
        if cat.image:
            return cat.image.url


@register.filter(name="startswith")
def startswith_tag(tree_category, category):
    logger.error("Don't use ocyan_oscar templatetags, use oxyan instead")
    return category.path.startswith(tree_category.path)
