def crispy_addon(field, append="", prepend=""):
    """
    Renders a form field using bootstrap's prepended or appended text::

        {% crispy_addon form.my_field prepend="$" append=".00" %}

    You can also just prepend or append like so

        {% crispy_addon form.my_field prepend="$" %}
        {% crispy_addon form.my_field append=".00" %}
    """
    if (field):
        context = Context({
            'field': field,
            'form_show_errors': True
        })

        template = loader.get_template('%s/layout/prepended_appended_text.html' % get_template_pack())
        context['crispy_prepended_text'] = prepend
        context['crispy_appended_text'] = append

        if not prepend and not append:
            raise TypeError("Expected a prepend and/or append argument")

    return template.render(context)
Exemplo n.º 2
0
 def __init__(self, form, helper, template_pack=None):
     self.form = form
     if helper is not None:
         self.helper = helper
     else:
         self.helper = None
     self.template_pack = template_pack or get_template_pack()
Exemplo n.º 3
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        html = u""

        errors = self._get_errors(form, self.fields)
        if len(errors) > 0:
            self.css_class += " has-error"

        for field in self.fields:
            html += render_field(field, form, form_style, context, template_pack=template_pack)
        context.update(
            {
                "label_html": mark_safe(self.label_html),
                "field_html": mark_safe(html),
                "multifield": self,
                "error_list": errors,
                "help_bubble_text": self.help_bubble_text,
            }
        )

        if not (self.field_class or self.label_class):
            return render_to_string(self.template, context)

        with edited_classes(context, self.label_class, self.field_class):
            rendered_view = render_to_string(self.template, context)
        return rendered_view
Exemplo n.º 4
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     self.template = "style/crispy/{}/{}".format(template_pack, self.template)
     context.update({
         'help_bubble_text': self.help_bubble_text,
     })
     return super(FieldWithHelpBubble, self).render(form, form_style, context, template_pack=template_pack)
Exemplo n.º 5
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'field_label': self.field_label,
         'field_value': self.field_value,
     })
     return render_to_string(self.template, context)
Exemplo n.º 6
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     offsets = _get_offsets(context)
     context.update({
         'offsets': offsets,
     })
     return super(Field, self).render(form, form_style, context, template_pack)
Exemplo n.º 7
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     offsets = _get_offsets(context)
     context.update({
         'offsets': offsets,
     })
     return super(Field, self).render(form, form_style, context, template_pack)
Exemplo n.º 8
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'field_label': self.field_label,
         'field_value': self.field_value,
     })
     return render_to_string(self.template, context.flatten())
Exemplo n.º 9
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'field_text': self.text,
     })
     return super(TextField, self).render(form, form_style, context,
                                          template_pack=template_pack)
Exemplo n.º 10
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        html = ''

        errors = self._get_errors(form, self.fields)
        if len(errors) > 0:
            self.css_class += " has-error"

        for field in self.fields:
            html += render_field(field, form, form_style, context, template_pack=template_pack)
        context.update({
            'label_html': mark_safe(self.label_html),
            'field_html': mark_safe(html),
            'multifield': self,
            'error_list': errors,
            'help_bubble_text': self.help_bubble_text,
        })

        context_dict = context.flatten()

        if not (self.field_class or self.label_class):
            return render_to_string(self.template, context_dict)

        with edited_classes(context, self.label_class, self.field_class):
            rendered_view = render_to_string(self.template, context_dict)
        return rendered_view
Exemplo n.º 11
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        html = ''

        errors = self._get_errors(form, self.fields)
        if len(errors) > 0:
            self.css_class += " has-error"

        for field in self.fields:
            html += render_field(field,
                                 form,
                                 form_style,
                                 context,
                                 template_pack=template_pack)
        context.update({
            'label_html': mark_safe(self.label_html),
            'field_html': mark_safe(html),
            'multifield': self,
            'error_list': errors,
            'help_bubble_text': self.help_bubble_text,
        })

        context_dict = context.flatten()

        if not (self.field_class or self.label_class):
            return render_to_string(self.template, context_dict)

        with edited_classes(context, self.label_class, self.field_class):
            rendered_view = render_to_string(self.template, context_dict)
        return rendered_view
Exemplo n.º 12
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        html = u''

        errors = self._get_errors(form, self.fields)
        if len(errors) > 0:
            self.css_class += " has-error"

        for field in self.fields:
            html += render_field(field, form, form_style, context, template_pack=template_pack)
        context.update({
            'label_html': mark_safe(self.label_html),
            'field_html': mark_safe(html),
            'multifield': self,
            'error_list': errors,
            'help_bubble_text': self.help_bubble_text,
        })

        if isinstance(context, RequestContext):
            context_dict = context.flatten()
        else:
            # TODO - remove by Nov 1 2017 if soft assert is never sent
            _soft_assert_dict(False, "context is type %s" % str(type(context)))
            context_dict = context

        if not (self.field_class or self.label_class):
            return render_to_string(self.template, context_dict)

        with edited_classes(context, self.label_class, self.field_class):
            rendered_view = render_to_string(self.template, context_dict)
        return rendered_view
Exemplo n.º 13
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'field_text': self.text,
     })
     return super(TextField, self).render(form, form_style, context,
                                          template_pack=template_pack)
Exemplo n.º 14
0
def crispy_addon(field, append="", prepend="", form_show_labels=True):
    """
    Renders a form field using bootstrap's prepended or appended text::

        {% crispy_addon form.my_field prepend="$" append=".00" %}

    You can also just prepend or append like so

        {% crispy_addon form.my_field prepend="$" %}
        {% crispy_addon form.my_field append=".00" %}
    """
    if field:
        context = Context({
            "field": field,
            "form_show_errors": True,
            "form_show_labels": form_show_labels
        })
        template = loader.get_template(
            "%s/layout/prepended_appended_text.html" % get_template_pack())
        context["crispy_prepended_text"] = prepend
        context["crispy_appended_text"] = append

        if not prepend and not append:
            raise TypeError("Expected a prepend and/or append argument")

        context = context.flatten()

    return template.render(context)
Exemplo n.º 15
0
def crispy_addon(field, append="", prepend="", form_show_labels=True):
    """
    Renders a form field using bootstrap's prepended or appended text::

        {% crispy_addon form.my_field prepend="$" append=".00" %}

    You can also just prepend or append like so

        {% crispy_addon form.my_field prepend="$" %}
        {% crispy_addon form.my_field append=".00" %}
    """
    if field:
        context = Context({
            'field': field,
            'form_show_errors': True,
            'form_show_labels': form_show_labels,
        })
        template = loader.get_template(
            '%s/layout/prepended_appended_text.html' % get_template_pack())
        context['crispy_prepended_text'] = prepend
        context['crispy_appended_text'] = append

        if not prepend and not append:
            raise TypeError("Expected a prepend and/or append argument")

        if django.VERSION >= (1, 8):
            context = context.flatten()

    return template.render(context)
Exemplo n.º 16
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'block_css_class': self.block_css_class,
     })
     return super(InlineColumnField, self).render(
         form, form_style, context, template_pack=template_pack
     )
Exemplo n.º 17
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'block_css_class': self.block_css_class,
     })
     return super(InlineColumnField, self).render(
         form, form_style, context, template_pack=template_pack
     )
Exemplo n.º 18
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     template = self.template.format(template_pack=template_pack)
     context.update({
         'button_text': self.button_text,
         'button_url': self.button_url,
         'button_attrs': flatatt(self.attrs if isinstance(self.attrs, dict) else {}),
     })
     return render_to_string(template, context)
Exemplo n.º 19
0
def do_uni_form(parser, token):
    """
    You need to pass in at least the form/formset object, and can also pass in the
    optional `crispy_forms.helpers.FormHelper` object.

    helper (optional): A `crispy_forms.helper.FormHelper` object.

    Usage::

        {% load crispy_tags %}
        {% crispy form form.helper %}

    You can also provide the templates pack as the third argument::

        {% crispy form form.helper 'bootstrap' %}

    If the `FormHelper` attribute is named `helper` you can simply do::

        {% crispy form %}
        {% crispy form 'bootstrap' %}
    """
    token = token.split_contents()
    form = token.pop(1)

    helper = None
    template_pack = "'%s'" % get_template_pack()

    # {% crispy form helper %}
    try:
        helper = token.pop(1)
    except IndexError:
        pass

    # {% crispy form helper 'bootstrap' %}
    try:
        template_pack = token.pop(1)
    except IndexError:
        pass

    # {% crispy form 'bootstrap' %}
    if helper is not None and isinstance(helper, str) and ("'" in helper
                                                           or '"' in helper):
        template_pack = helper
        helper = None

    if template_pack is not None:
        template_pack = template_pack[1:-1]
        ALLOWED_TEMPLATE_PACKS = getattr(
            settings, "CRISPY_ALLOWED_TEMPLATE_PACKS",
            ("bootstrap", "uni_form", "bootstrap3", "bootstrap4"))
        if template_pack not in ALLOWED_TEMPLATE_PACKS:
            raise template.TemplateSyntaxError(
                "crispy tag's template_pack argument should be in %s" %
                str(ALLOWED_TEMPLATE_PACKS))

    return CrispyFormNode(form, helper, template_pack=template_pack)
Exemplo n.º 20
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'help_bubble_text': self.help_bubble_text,
     })
     return super(FieldWithHelpBubble,
                  self).render(form,
                               form_style,
                               context,
                               template_pack=template_pack)
    def render(self, context):
        # Nodes are not threadsafe so we must store and look up our instance
        # variables in the current rendering context first
        if self not in context.render_context:
            context.render_context[self] = (
                template.Variable(self.field),
                self.attrs,
                template.Variable(self.html5_required)
            )

        field, attrs, html5_required = context.render_context[self]
        field = field.resolve(context)
        try:
            html5_required = html5_required.resolve(context)
        except template.VariableDoesNotExist:
            html5_required = False

        widgets = getattr(field.field.widget, 'widgets', [field.field.widget])

        if isinstance(attrs, dict):
            attrs = [attrs] * len(widgets)

        for widget, attr in zip(widgets, attrs):
            class_name = widget.__class__.__name__.lower()
            class_name = class_converter.get(class_name, class_name)
            css_class = widget.attrs.get('class', '')
            if css_class:
                if css_class.find(class_name) == -1:
                    css_class += " %s" % class_name
            else:
                css_class = class_name

            if (
                get_template_pack() == 'bootstrap3'
                and not is_checkbox(field)
                and not is_file(field)
            ):
                css_class += ' form-control'

            widget.attrs['class'] = css_class

            # HTML5 required attribute
            if html5_required and field.field.required and 'required' not in widget.attrs:
                if field.field.widget.__class__.__name__ is not 'RadioSelect':
                    widget.attrs['required'] = 'required'

            for attribute_name, attribute in attr.items():
                attribute_name = template.Variable(attribute_name).resolve(context)

                if attribute_name in widget.attrs:
                    widget.attrs[attribute_name] += " " + template.Variable(attribute).resolve(context)
                else:
                    widget.attrs[attribute_name] = template.Variable(attribute).resolve(context)

        return field
Exemplo n.º 22
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     html = u''
     for field in self.fields:
         html += render_field(field, form, form_style, context, template_pack=template_pack)
     context.update({
         'label_html': mark_safe(self.label_html),
         'field_html': mark_safe(html),
         'multifield': self,
     })
     return render_to_string(self.template, context)
Exemplo n.º 23
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     html = u''
     for field in self.fields:
         html += render_field(field, form, form_style, context, template_pack=template_pack)
     offsets = _get_offsets(context)
     return render_to_string(self.template, Context({
         'formactions': self,
         'fields_output': html,
         'offsets': offsets,
         'field_class': context.get('field_class', '')
     }))
Exemplo n.º 24
0
def do_uni_form(parser, token):
    """
    You need to pass in at least the form/formset object, and can also pass in the
    optional `crispy_forms.helpers.FormHelper` object.

    helper (optional): A `crispy_forms.helper.FormHelper` object.

    Usage::

        {% include crispy_tags %}
        {% crispy form form.helper %}

    You can also provide the template pack as the third argument::

        {% crispy form form.helper 'bootstrap' %}

    If the `FormHelper` attribute is named `helper` you can simply do::

        {% crispy form %}
        {% crispy form 'bootstrap' %}
    """
    token = token.split_contents()
    form = token.pop(1)

    try:
        helper = token.pop(1)
    except IndexError:
        helper = None

    try:
        # {% crispy form helper 'bootstrap' %}
        template_pack = token.pop(1)
        if not (template_pack[0] == template_pack[-1] and template_pack[0] in ('"', "'")):
            raise template.TemplateSyntaxError("crispy tag's template_pack argument should be in quotes")

        template_pack = template_pack[1:-1]
        if template_pack not in ALLOWED_TEMPLATE_PACKS:
            raise template.TemplateSyntaxError("crispy tag's template_pack argument should be \
                in " + str(ALLOWED_TEMPLATE_PACKS))
    except IndexError:
        # {% crispy form 'bootstrap' %}
        # ('"'bootstrap'"', '"'uni_form'"','"'"bootstrap'"'", '"'"uni_form"'")
        if (
            helper in ['"%s"' % x for x in ALLOWED_TEMPLATE_PACKS] + \
            ["'%s'" % x for x in ALLOWED_TEMPLATE_PACKS]
        ):
            template_pack = helper[1:-1]
            helper = None
        # {% crispy form helper %} OR {% crispy form %}
        else:
            template_pack = get_template_pack()

    return CrispyFormNode(form, helper, template_pack=template_pack)
Exemplo n.º 25
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     html = u''
     for field in self.fields:
         html += render_field(field, form, form_style, context, template_pack=template_pack)
     offsets = _get_offsets(context)
     return render_to_string(self.template, Context({
         'formactions': self,
         'fields_output': html,
         'offsets': offsets,
         'field_class': context.get('field_class', '')
     }))
Exemplo n.º 26
0
 def __init__(self, *args, **kwargs):
     # Map template packs to the css class they need here.
     # TODO: This is a _Smell_. There should be a factory which creates a
     #       template pack specific subclass. (Or such...)
     row_class_map = {
         'uni_form': 'formRow',
         'bootstrap4': 'form-row',
         'bootstrap3': 'row',
     }
     # Fetch the class, with a suitable default.
     self.css_class = row_class_map.get(get_template_pack(), 'row')
     super(Row, self).__init__(*args, **kwargs)
Exemplo n.º 27
0
    def get_response_dict(self, helper, context, is_formset):
        """
        Returns a dictionary with all the parameters necessary to render the form/formset in a template.

        :param attrs: Dictionary with the helper's attributes used for rendering the form/formset
        :param context: `django.template.Context` for the node
        :param is_formset: Boolean value. If set to True, indicates we are working with a formset.
        """
        if not isinstance(helper, FormHelper):
            raise TypeError('helper object provided to {% crispy %} tag must be a crispy.helper.FormHelper object.')

        attrs = helper.get_attributes(template_pack=self.template_pack)
        form_type = "form"
        if is_formset:
            form_type = "formset"

        # We take form/formset parameters from attrs if they are set, otherwise we use defaults
        response_dict = {
            'template_pack': get_template_pack(),
            '%s_action' % form_type: attrs['attrs'].get("action", ''),
            '%s_method' % form_type: attrs.get("form_method", 'post'),
            '%s_tag' % form_type: attrs.get("form_tag", True),
            '%s_class' % form_type: attrs['attrs'].get("class", ''),
            '%s_id' % form_type: attrs['attrs'].get("id", ""),
            '%s_style' % form_type: attrs.get("form_style", None),
            'form_error_title': attrs.get("form_error_title", None),
            'formset_error_title': attrs.get("formset_error_title", None),
            'form_show_errors': attrs.get("form_show_errors", True),
            'help_text_inline': attrs.get("help_text_inline", False),
            'html5_required': attrs.get("html5_required", False),
            'form_show_labels': attrs.get("form_show_labels", True),
            'disable_csrf': attrs.get("disable_csrf", False),
            'inputs': attrs.get('inputs', []),
            'is_formset': is_formset,
            '%s_attrs' % form_type: attrs.get('attrs', ''),
            'flat_attrs': attrs.get('flat_attrs', ''),
            'error_text_inline': attrs.get('error_text_inline', True),
            'label_class': attrs.get('label_class', ''),
            'label_size': attrs.get('label_size', 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
Exemplo n.º 28
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        context.update({
            'field_text': self.text,
        })
        if hasattr(self, 'wrapper_class'):
            context['wrapper_class'] = self.wrapper_class

        html = ''
        for field in self.fields:
            html += render_field(field, form, form_style, context,
                                 template=self.template, attrs=self.attrs,
                                 template_pack=template_pack)
        return html
def bs4_appended_prepended_text(field,
                                append="",
                                prepend="",
                                form_show_labels=True):
    """
    Similar to the `crispy_addon` tag. However, this one respects classes that
    have been set in the corresponding Form layout object.
    """

    template_pack = get_template_pack()
    if template_pack != "bootstrap4":
        raise CrispyError(
            "bs4_appended_prepended_text can only be used with Bootstrap 4")

    if field:
        attributes = {
            'field': field,
            'form_show_errors': True,
            'form_show_labels': form_show_labels,
        }
        helper = getattr(field.form, "helper", None)
        if helper is not None:
            attributes.update(helper.get_attributes(get_template_pack()))

        context = Context(attributes)
        template = loader.get_template(
            "%s/layout/prepended_appended_text.html" % get_template_pack())
        context["crispy_prepended_text"] = prepend
        context["crispy_appended_text"] = append

        if not prepend and not append:
            raise TypeError("Expected a prepend and/or append argument")

        context = context.flatten()

    return template.render(context)
    def render(self, context):
        try:
            template_pack = template.Variable('template_pack').resolve(context)
        except:
            template_pack = get_template_pack()

        try:
            form_attrs = template.Variable('form_attrs').resolve(context)
        except:
            form_attrs = {}

        return selectively_remove_spaces_between_tags(
            self.nodelist.render(context).strip(),
            template_pack,
            form_attrs.get('class', ''),
        )
Exemplo n.º 31
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     html = u""
     for field in self.fields:
         html += render_field(field, form, form_style, context, template_pack=template_pack)
     offsets = _get_offsets(context)
     return render_to_string(
         self.template,
         Context(
             {
                 "formactions": self,
                 "fields_output": html,
                 "offsets": offsets,
                 "field_class": context.get("field_class", ""),
             }
         ),
     )
def as_crispy_field(field, template_pack=None):
    """
    Renders a form field like a django-crispy-forms field::

        {% load crispy_forms_tags %}
        {{ form.field|as_crispy_field }}

    or::

        {{ form.field|as_crispy_field:"bootstrap" }}
    """
    template_pack = template_pack or get_template_pack()
    if not isinstance(field, forms.BoundField) and DEBUG:
        raise CrispyError('|as_crispy_field got passed an invalid or inexistent field')

    template = get_template('%s/field.html' % template_pack)
    c = Context({'field': field, 'form_show_errors': True, 'form_show_labels': True})
    return template.render(c)
def as_crispy_errors(form, template_pack=None):
    """
    Renders only form errors the same way as django-crispy-forms::

        {% load crispy_forms_tags %}
        {{ form|as_crispy_errors }}

    or::

        {{ form|as_crispy_errors:"bootstrap" }}
    """
    template_pack = template_pack or get_template_pack()
    if isinstance(form, BaseFormSet):
        template = get_template('%s/errors_formset.html' % template_pack)
        c = Context({'formset': form})
    else:
        template = get_template('%s/errors.html' % template_pack)
        c = Context({'form': form})
    return template.render(c)
def crispy_addon(field, append="", prepend="", form_show_labels=True):
    """
    Renders a form field using bootstrap's prepended or appended text::

        {% crispy_addon form.my_field prepend="$" append=".00" %}

    You can also just prepend or append like so

        {% crispy_addon form.my_field prepend="$" %}
        {% crispy_addon form.my_field append=".00" %}
    """
    if field:
        context = Context({"field": field, "form_show_errors": True, "form_show_labels": form_show_labels})
        template = loader.get_template("%s/layout/prepended_appended_text.html" % get_template_pack())
        context["crispy_prepended_text"] = prepend
        context["crispy_appended_text"] = append

        if not prepend and not append:
            raise TypeError("Expected a prepend and/or append argument")

    return template.render(context)
Exemplo n.º 35
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        fields_output = u''
        for field in self.fields:
            fields_output += render_field(
                field, form, form_style, context,
                self.field_template, self.label_class, layout_object=self,
                template_pack=template_pack
            )

        errors = self._get_errors(form, self.fields)
        if len(errors) > 0:
            self.css_class += " error"

        context.update({
            'multifield': self,
            'fields_output': fields_output,
            'error_list': errors,
            'help_bubble_text': self.help_bubble_text,
        })
        return render_to_string(self.template, context)
Exemplo n.º 36
0
    def render(self, form, form_style, context, template_pack=None):
        template_pack = template_pack or get_template_pack()
        fields_output = u''
        for field in self.fields:
            fields_output += render_field(
                field, form, form_style, context,
                self.field_template, self.label_class, layout_object=self,
                template_pack=template_pack
            )

        errors = self._get_errors(form, self.fields)
        if len(errors) > 0:
            self.css_class += " error"

        context.update({
            'multifield': self,
            'fields_output': fields_output,
            'error_list': errors,
            'help_bubble_text': self.help_bubble_text,
        })
        return render_to_string(self.template, context)
def as_crispy_form(form, template_pack=None, label_class="", field_class=""):
    """
    The original and still very useful way to generate a div elegant form/formset::

        {% load crispy_forms_tags %}

        <form class="uniForm" method="post">
            {% csrf_token %}
            {{ myform|crispy }}
        </form>

    or, if you want to explicitly set the template pack::

        {{ myform|crispy:"bootstrap" }}

    In ``bootstrap3`` for horizontal forms you can do::

        {{ myform|label_class:"col-lg-2",field_class:"col-lg-8" }}
    """
    template_pack = template_pack or get_template_pack()
    if isinstance(form, BaseFormSet):
        template = uni_formset_template(template_pack)
        c = Context({
            'formset': form,
            'form_show_errors': True,
            'form_show_labels': True,
            'label_class': label_class,
            'field_class': field_class,
        })
    else:
        template = uni_form_template(template_pack)
        c = Context({
            'form': form,
            'form_show_errors': True,
            'form_show_labels': True,
            'label_class': label_class,
            'field_class': field_class,
        })
    return template.render(c)
 def __init__(self, *args, **kwargs):
     self.field_classes = 'button' if get_template_pack() == 'uni_form' else 'btn'
     super(Button, self).__init__(*args, **kwargs)
 def __init__(self, *args, **kwargs):
     self.field_classes = 'reset resetButton' if get_template_pack() == 'uni_form' else 'btn btn-inverse'
     super(Reset, self).__init__(*args, **kwargs)
 def __init__(self, *args, **kwargs):
     self.css_class = 'formRow' if get_template_pack() == 'uni_form' else 'row'
     super(Row, self).__init__(*args, **kwargs)
Exemplo n.º 41
0
 def __init__(self, *args, **kwargs):
     self.field_classes = "reset resetButton" if get_template_pack(
     ) == "uni_form" else "btn btn-inverse"
     super().__init__(*args, **kwargs)
Exemplo n.º 42
0
 def __init__(self, *args, **kwargs):
     self.field_classes = "button" if get_template_pack(
     ) == "uni_form" else "btn"
     super().__init__(*args, **kwargs)
Exemplo n.º 43
0
 def __init__(self, *args, **kwargs):
     self.field_classes = 'button' if get_template_pack(
     ) == 'uni_form' else 'btn'
     super(Button, self).__init__(*args, **kwargs)
Exemplo n.º 44
0
def do_uni_form(parser, token):
    """
    You need to pass in at least the form/formset object, and can also pass in the
    optional `crispy_forms.helpers.FormHelper` object.

    helper (optional): A `crispy_forms.helper.FormHelper` object.

    Usage::

        {% load crispy_tags %}
        {% crispy form form.helper %}

    You can also provide the template pack as the third argument::

        {% crispy form form.helper 'bootstrap' %}

    If the `FormHelper` attribute is named `helper` you can simply do::

        {% crispy form %}
        {% crispy form 'bootstrap' %}
    """
    token = token.split_contents()
    form = token.pop(1)

    helper = None
    template_pack = "'%s'" % get_template_pack()

    # {% crispy form helper %}
    try:
        helper = token.pop(1)
    except IndexError:
        pass

    # {% crispy form helper 'bootstrap' %}
    try:
        template_pack = token.pop(1)
    except IndexError:
        pass

    # {% crispy form 'bootstrap' %}
    if (
        helper is not None and
        isinstance(helper, string_types) and
        ("'" in helper or '"' in helper)
    ):
        template_pack = helper
        helper = None

    if template_pack is not None:
        template_pack = template_pack[1:-1]
        ALLOWED_TEMPLATE_PACKS = getattr(
            settings,
            'CRISPY_ALLOWED_TEMPLATE_PACKS',
            ('bootstrap', 'uni_form', 'bootstrap3', 'bootstrap4')
        )
        if template_pack not in ALLOWED_TEMPLATE_PACKS:
            raise template.TemplateSyntaxError(
                "crispy tag's template_pack argument should be in %s" %
                str(ALLOWED_TEMPLATE_PACKS)
            )

    return CrispyFormNode(form, helper, template_pack=template_pack)
Exemplo n.º 45
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     self.template = self.template.format(template_pack=template_pack)
     return super(HiddenFieldWithErrors, self).render(form, form_style, context, template_pack)
Exemplo n.º 46
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     self.template = self.template.format(template_pack=template_pack)
     return super(FieldsetAccordionGroup, self).render(form, form_style, context, template_pack)
Exemplo n.º 47
0
 def render(self, form, form_style, context, template_pack=None):
     template_pack = template_pack or get_template_pack()
     context.update({
         'help_bubble_text': self.help_bubble_text,
     })
     return super(FieldWithHelpBubble, self).render(form, form_style, context, template_pack=template_pack)
Exemplo n.º 48
0
 def __init__(self, *args, **kwargs):
     self.field_classes = 'submit submitButton' if get_template_pack(
     ) == 'uni_form' else 'btn btn-primary'
     super(Submit, self).__init__(*args, **kwargs)
Exemplo n.º 49
0
def crispy_html(context, layout):
    return mark_safe(
        layout.render({}, (), context, template_pack=get_template_pack()))
Exemplo n.º 50
0
 def __init__(self, *args, **kwargs):
     self.css_class = 'formRow' if get_template_pack() == 'uni_form' else 'row'
     super(Row, self).__init__(*args, **kwargs)
Exemplo n.º 51
0
 def __init__(self, *args, **kwargs):
     self.field_classes = "submit submitButton" if get_template_pack(
     ) == "uni_form" else "btn btn-primary"
     super().__init__(*args, **kwargs)
Exemplo n.º 52
0
 def __init__(self, *args, **kwargs):
     self.field_classes = 'reset resetButton' if get_template_pack(
     ) == 'uni_form' else 'btn btn-inverse'
     super(Reset, self).__init__(*args, **kwargs)