# Path: crispy_forms/utils.py
# TEMPLATE_PACK = SimpleLazyObject(get_template_pack)
# 
# def flatatt(attrs):
#     """
#     Convert a dictionary of attributes to a single string.
# 
#     Passed attributes are redirected to `django.forms.utils.flatatt()`
#     with replaced "_" (underscores) by "-" (dashes) in their names.
#     """
#     return _flatatt({k.replace("_", "-"): v for k, v in attrs.items()})


from functools import lru_cache
from django import template
from django.conf import settings
from django.forms import boundfield
from django.forms.formsets import BaseFormSet
from django.template import Context
from django.template.loader import get_template
from django.utils.safestring import mark_safe
from crispy_forms.exceptions import CrispyError
from crispy_forms.utils import TEMPLATE_PACK, flatatt
    or::

        {{ form.field|as_crispy_field:"bootstrap4" }}
    """
    if not isinstance(field, boundfield.BoundField) and settings.DEBUG:
        raise CrispyError("|as_crispy_field got passed an invalid or inexistent field")

    attributes = {
        "field": field,
        "form_show_errors": True,
        "form_show_labels": True,
        "label_class": label_class,
        "field_class": field_class,
    }
    helper = getattr(field.form, "helper", None)

    template_path = None
    if helper is not None:
        attributes.update(helper.get_attributes(template_pack))
        template_path = helper.field_template
    if not template_path:
        template_path = "%s/field.html" % template_pack
    template = get_template(template_path)

    c = Context(attributes).flatten()
    return template.render(c)


@register.filter(name="flatatt")
def flatatt_filter(attrs):

# Path: crispy_forms/utils.py
# TEMPLATE_PACK = SimpleLazyObject(get_template_pack)
# 
# def flatatt(attrs):
#     """
#     Convert a dictionary of attributes to a single string.
# 
#     Passed attributes are redirected to `django.forms.utils.flatatt()`
#     with replaced "_" (underscores) by "-" (dashes) in their names.
#     """
#     return _flatatt({k.replace("_", "-"): v for k, v in attrs.items()})


# Path: crispy_forms/templatetags/crispy_forms_filters.py
from functools import lru_cache
from django import template
from django.conf import settings
from django.forms import boundfield
from django.forms.formsets import BaseFormSet
from django.template import Context
from django.template.loader import get_template
from django.utils.safestring import mark_safe
from crispy_forms.exceptions import CrispyError
from crispy_forms.utils import TEMPLATE_PACK, flatatt

    or::

        {{ form.field|as_crispy_field:"bootstrap4" }}
    """
    if not isinstance(field, boundfield.BoundField) and settings.DEBUG:
        raise CrispyError("|as_crispy_field got passed an invalid or inexistent field")

    attributes = {
        "field": field,
        "form_show_errors": True,
        "form_show_labels": True,
        "label_class": label_class,
        "field_class": field_class,
    }
    helper = getattr(field.form, "helper", None)

    template_path = None
    if helper is not None:
        attributes.update(helper.get_attributes(template_pack))
        template_path = helper.field_template
    if not template_path:
        template_path = "%s/field.html" % template_pack
    template = get_template(template_path)

    c = Context(attributes).flatten()
    return template.render(c)


@register.filter(name="flatatt")
def flatatt_filter(attrs):

    return mark_safe(flatatt(attrs))