from django import template
from accounts.constants import STATE_CHOICES, COUNTRIES

register = template.Library()


@register.inclusion_tag("pbp_core/tags/form_table_row.html")
def form_table_row(form_field):
    return {"form_field": form_field}


@register.filter
def humanize_region(region):
    for code in STATE_CHOICES:
        if code[0] == region:
            return code[1]


@register.filter
def humanize_country(country):
    for code in COUNTRIES:
        if code[0] == country:
            return code[1]


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