# -*- coding: utf-8 -*-
from cms.models import Page
from cms.utils.page import _page_is_published
from django import template
from parler.utils.i18n import get_language

register = template.Library()


@register.filter
def page_image(id):
    try:
        return Page.objects.get(pk=id).imageextension.image
    except:
        return None


@register.filter
def page_published(page):
    return page.is_published(get_language()) and _page_is_published(page)


@register.filter
def page_image_cropping(id):
    try:
        return Page.objects.get(pk=id).imageextension.cropping
    except:
        return None


@register.filter
def field_type(field):
    return field.field.widget.__class__.__name__
