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 django import template

from crispy_forms.compatibility import memoize
from crispy_forms.exceptions import CrispyError
from crispy_forms.utils import flatatt

TEMPLATE_PACK = getattr(settings, 'CRISPY_TEMPLATE_PACK', 'bootstrap')
DEBUG = getattr(settings, 'DEBUG', False)

def uni_formset_template(template_pack=TEMPLATE_PACK):
    return get_template('%s/uni_formset.html' % template_pack)
uni_formset_template = memoize(uni_formset_template, {}, 1)

def uni_form_template(template_pack=TEMPLATE_PACK):
    return get_template('%s/uni_form.html' % template_pack)
uni_form_template = memoize(uni_form_template, {}, 1)

register = template.Library()


@register.filter(name='crispy')
def as_crispy_form(form, template_pack=TEMPLATE_PACK, label_class="", field_class=""):
    """
    The original and still very useful way to generate a div elegant form/formset::

        {% load crispy_forms_tags %}
Ejemplo n.º 2
0
            'field_class': attrs.get('field_class', ''),
        }

        # Handles custom attributes added to helpers
        for attribute_name, value in attrs.items():
            if attribute_name not in response_dict:
                response_dict[attribute_name] = value

        if 'csrf_token' in context:
            response_dict['csrf_token'] = context['csrf_token']

        return response_dict

def whole_uni_formset_template(template_pack=TEMPLATE_PACK):
    return get_template('%s/whole_uni_formset.html' % template_pack)
whole_uni_formset_template = memoize(whole_uni_formset_template, {}, 1)

def whole_uni_form_template(template_pack=TEMPLATE_PACK):
    return get_template('%s/whole_uni_form.html' % template_pack)
whole_uni_form_template = memoize(whole_uni_form_template, {}, 1)


class CrispyFormNode(BasicNode):
    def render(self, context):
        c = self.get_render(context)

        if self.actual_helper is not None and getattr(self.actual_helper, 'template', False):
            template = get_template(self.actual_helper.template)
        else:
            if c['is_formset']:
                template = whole_uni_formset_template(self.template_pack)
Ejemplo n.º 3
0
from django.utils.safestring import mark_safe
from django import template

from crispy_forms.compatibility import memoize
from crispy_forms.exceptions import CrispyError
from crispy_forms.utils import flatatt

TEMPLATE_PACK = getattr(settings, 'CRISPY_TEMPLATE_PACK', 'bootstrap')
DEBUG = getattr(settings, 'DEBUG', False)


def uni_formset_template(template_pack=TEMPLATE_PACK):
    return get_template('%s/uni_formset.html' % template_pack)


uni_formset_template = memoize(uni_formset_template, {}, 1)


def uni_form_template(template_pack=TEMPLATE_PACK):
    return get_template('%s/uni_form.html' % template_pack)


uni_form_template = memoize(uni_form_template, {}, 1)

register = template.Library()


@register.filter(name='crispy')
def as_crispy_form(form,
                   template_pack=TEMPLATE_PACK,
                   label_class="",