Commit 8d1af358 authored by Michael Fladischer's avatar Michael Fladischer

Import python-django-crispy-forms_1.6.0.orig.tar.gz

parent 344c0776
......@@ -28,3 +28,8 @@ _build
# OSX
*.DS_Store
# editors
.project
.pydevproject
.settings/
\ No newline at end of file
......@@ -3,15 +3,14 @@ language: python
sudo: false
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
env:
- DJANGO='django>=1.4.0,<1.5.0'
- DJANGO='django>=1.7.0,<1.8.0'
- DJANGO='django>=1.8.0,<1.9.0'
- DJANGO='django>=1.9.0,<1.10.0'
- DJANGO='https://github.com/django/django/archive/master.tar.gz'
install:
- pip install $DJANGO
......@@ -22,22 +21,18 @@ notifications:
email: false
matrix:
exclude:
- python: "3.2"
env: DJANGO='django>=1.4.0,<1.5.0'
- python: "3.2"
env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
- python: "3.3"
env: DJANGO='django>=1.4.0,<1.5.0'
- python: "3.2"
env: DJANGO='django>=1.9.0,<1.10.0'
- python: "3.3"
env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
- python: "3.3"
env: DJANGO='django>=1.9.0,<1.10.0'
- python: "3.4"
env: DJANGO='django>=1.4.0,<1.5.0'
- python: "2.6"
env: DJANGO='django>=1.7.0,<1.8.0'
- python: "2.6"
env: DJANGO='django>=1.8.0,<1.9.0'
- python: "2.6"
env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
- python: "3.5"
env: DJANGO='django>=1.7.0,<1.8.0'
allow_failures:
- env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
after_success:
......
# CHANGELOG for django-crispy-forms
## 1.6.0 (2016/1/7)
* Fixed compatibility with Django 1.9
* Added Bootstrap 4 template pack
* Other small fixes.
See [1.6.0 Milestone](https://github.com/maraujop/django-crispy-forms/issues?q=milestone%3A1.6.0+is%3Aclosed) for full issue list.
## 1.5.2 (2015/9/10)
* Fix: KeyError: u'wrapper_class' when clearing template context. #511, #512
......
# -*- coding: utf-8 -*-
__version__ = '1.5.2'
__version__ = '1.6.0'
......@@ -36,7 +36,7 @@ class PrependedAppendedText(Field):
'input_size': self.input_size,
'active': getattr(self, "active", False)
}
template = self.template % template_pack
template = self.get_template_name(template_pack)
return render_field(
self.field, form, form_style, context,
template=template, attrs=self.attrs,
......@@ -82,12 +82,13 @@ class FormActions(LayoutObject):
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
html = self.get_rendered_fields(form, form_style, context, template_pack, **kwargs)
extra_context = {
template = self.get_template_name(template_pack)
context.update({
'formactions': self,
'fields_output': html
}
template = self.template % template_pack
return render_to_string(template, extra_context, context)
})
return render_to_string(template, context.flatten())
def flat_attrs(self):
return flatatt(self.attrs)
......@@ -139,7 +140,7 @@ class FieldWithButtons(Div):
)
extra_context = {'div': self, 'buttons': buttons}
template = self.template % template_pack
template = self.get_template_name(template_pack)
if isinstance(self.fields[0], Field):
# FieldWithButtons(Field('field_name'), StrictButton("go"))
......@@ -183,7 +184,9 @@ class StrictButton(object):
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
self.content = Template(text_type(self.content)).render(context)
template = self.template % template_pack
return render_to_string(template, {'button': self}, context)
context.update({'button': self})
return render_to_string(template, context.flatten())
class Container(Div):
......@@ -287,13 +290,13 @@ class TabHolder(ContainerHolder):
content = self.get_rendered_fields(form, form_style, context, template_pack)
links = ''.join(tab.render_link(template_pack) for tab in self.fields)
extra_context = {
context.update({
'tabs': self,
'links': links,
'content': content
}
template = self.template % template_pack
return render_to_string(template, extra_context, context)
})
template = self.get_template_name(template_pack)
return render_to_string(template, context.flatten())
class AccordionGroup(Container):
......@@ -335,12 +338,10 @@ class Accordion(ContainerHolder):
group, form, form_style, context, template_pack=template_pack, **kwargs
)
template = self.template % template_pack
return render_to_string(
template,
{'accordion': self, 'content': content},
context
)
template = self.get_template_name(template_pack)
context.update({'accordion': self, 'content': content})
return render_to_string(template, context.flatten())
class Alert(Div):
......@@ -362,12 +363,10 @@ class Alert(Div):
self.dismiss = dismiss
def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):
template = self.template % template_pack
return render_to_string(
template,
{'alert': self, 'content': self.content, 'dismiss': self.dismiss},
context
)
template = self.get_template_name(template_pack)
context.update({'alert': self, 'content': self.content, 'dismiss': self.dismiss})
return render_to_string(template, context.flatten())
class UneditableField(Field):
......
import sys
import django
if (1, 4) <= django.VERSION <= (1, 5):
from django.utils.functional import SimpleLazyObject as DefaultSimpleLazyObject
class SimpleLazyObject(DefaultSimpleLazyObject):
def __contains__(self, item):
if self._wrapped is None:
self._setup()
return self._wrapped.__contains__(item)
else:
from django.utils.functional import SimpleLazyObject
from django.utils.functional import SimpleLazyObject
try:
basestring
......
......@@ -7,7 +7,7 @@ from django.utils.safestring import mark_safe
from crispy_forms.compatibility import string_types
from crispy_forms.layout import Layout
from crispy_forms.layout_slice import LayoutSlice
from crispy_forms.utils import render_field, flatatt, TEMPLATE_PACK
from crispy_forms.utils import render_field, flatatt, TEMPLATE_PACK, list_intersection, list_difference
from crispy_forms.exceptions import FormHelpersException
......@@ -148,6 +148,9 @@ class FormHelper(DynamicLayoutHandler):
**form_style**: Uni-form has two built in different form styles. You can choose
your favorite. This can be set to "default" or "inline". Defaults to "default".
**include_media**: Whether to automatically include form media. Set to False if
you want to manually include form media outside the form. Defaults to True.
Public Methods:
**add_input(input)**: You can add input buttons using this method. Inputs
......@@ -203,6 +206,7 @@ class FormHelper(DynamicLayoutHandler):
disable_csrf = False
label_class = ''
field_class = ''
include_media = True
def __init__(self, form=None):
self.attrs = {}
......@@ -315,11 +319,11 @@ class FormHelper(DynamicLayoutHandler):
# we suppose they need to be rendered
if hasattr(form, 'Meta'):
if hasattr(form.Meta, 'fields'):
current_fields = set(getattr(form, 'fields', []))
meta_fields = set(getattr(form.Meta, 'fields'))
current_fields = tuple(getattr(form, 'fields', {}).keys())
meta_fields = getattr(form.Meta, 'fields')
fields_to_render = current_fields & meta_fields
left_fields_to_render = fields_to_render - form.rendered_fields
fields_to_render = list_intersection(current_fields, meta_fields)
left_fields_to_render = list_difference(fields_to_render, form.rendered_fields)
for field in left_fields_to_render:
html += render_field(field, form, self.form_style, context)
......@@ -341,7 +345,8 @@ class FormHelper(DynamicLayoutHandler):
'form_show_labels': self.form_show_labels,
'disable_csrf': self.disable_csrf,
'label_class': self.label_class,
'field_class': self.field_class
'field_class': self.field_class,
'include_media': self.include_media
}
# col-[lg|md|sm|xs]-<number>
label_size_match = re.search('(\d+)', self.label_class)
......
......@@ -164,11 +164,9 @@ class ButtonHolder(LayoutObject):
html = self.get_rendered_fields(form, form_style, context, template_pack, **kwargs)
template = self.get_template_name(template_pack)
return render_to_string(
template,
{'buttonholder': self, 'fields_output': html},
context
)
context.update({'buttonholder': self, 'fields_output': html})
return render_to_string(template, context.flatten())
class BaseInput(TemplateNameMixin):
......@@ -196,7 +194,9 @@ class BaseInput(TemplateNameMixin):
"""
self.value = Template(text_type(self.value)).render(context)
template = self.get_template_name(template_pack)
return render_to_string(template, {'input': self}, context)
context.update({'input': self})
return render_to_string(template, context.flatten())
class Submit(BaseInput):
......@@ -323,12 +323,13 @@ class MultiField(LayoutObject):
labelclass=self.label_class, layout_object=self, **kwargs
)
extra_context = {
template = self.get_template_name(template_pack)
context.update({
'multifield': self,
'fields_output': fields_output
}
template = self.get_template_name(template_pack)
return render_to_string(template, extra_context, context)
})
return render_to_string(template, context.flatten())
class Div(LayoutObject):
......
{% if form.form_html %}
{{ form.media }}
{% if include_media %}{{ form.media }}{% endif %}
{% if form_show_errors %}
{% include "bootstrap/errors.html" %}
{% endif %}
......
{% load crispy_forms_utils %}
{% specialspaceless %}
{{ form.media }}
{% if include_media %}{{ form.media }}{% endif %}
{% if form_show_errors %}
{% include "bootstrap/errors.html" %}
{% endif %}
......
{% if form.form_html %}
{{ form.media }}
{% if include_media %}{{ form.media }}{% endif %}
{% if form_show_errors %}
{% include "bootstrap3/errors.html" %}
{% endif %}
......
<div {% if buttonholder.css_id %}id="{{ buttonholder.css_id }}"{% endif %}
class="buttonHolder{% if buttonholder.css_class %} {{ buttonholder.css_class }}{% endif %}">
{{ fields_output|safe }}
</div>
{% load crispy_forms_utils %}
{% specialspaceless %}
{{ form.media }}
{% if include_media %}{{ form.media }}{% endif %}
{% if form_show_errors %}
{% include "bootstrap3/errors.html" %}
{% endif %}
......
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#{{ div.data_parent }}" href="#{{ div.css_id }}">{{ div.name }}</a>
</h4>
</div>
<div id="{{ div.css_id }}" class="panel-collapse collapse{% if div.active %} in{% endif %}" >
<div class="panel-body">
{{ fields|safe }}
</div>
</div>
</div>
<div class="panel-group" id="{{ accordion.css_id }}">
{{ content|safe }}
</div>
{% for fieldset in form.fieldsets %}
<fieldset class="fieldset-{{ forloop.counter }} {{ fieldset.classes }}">
{% if fieldset.legend %}
<legend>{{ fieldset.legend }}</legend>
{% endif %}
{% if fieldset.description %}
<p class="description">{{ fieldset.description }}</p>
{% endif %}
{% for field in fieldset %}
{% if field.is_hidden %}
{{ field }}
{% else %}
{% include "bootstrap4/field.html" %}
{% endif %}
{% endfor %}
{% if not forloop.last or not fieldset_open %}
</fieldset>
{% endif %}
{% endfor %}
{% if form.form_html %}
{% if include_media %}{{ form.media }}{% endif %}
{% if form_show_errors %}
{% include "bootstrap4/errors.html" %}
{% endif %}
{{ form.form_html }}
{% else %}
{% include "bootstrap4/uni_form.html" %}
{% endif %}
{% if form.non_field_errors %}
<div class="alert alert-block alert-danger">
{% if form_error_title %}<h4 class="alert-heading">{{ form_error_title }}</h4>{% endif %}
<ul>
{{ form.non_field_errors|unordered_list }}
</ul>
</div>
{% endif %}
{% if formset.non_form_errors %}
<div class="alert alert-block alert-danger">
{% if formset_error_title %}<h4 class="alert-heading">{{ formset_error_title }}</h4>{% endif %}
<ul>
{{ formset.non_form_errors|unordered_list }}
</ul>
</div>
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
{% if field|is_checkbox %}
<div class="form-group row">
{% if label_class %}
<div class="controls col-{{ bootstrap_device_type }}-offset-{{ label_size }} {{ field_class }}">
{% endif %}
{% endif %}
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" {% if not field|is_checkbox %}class="form-group row{% else %}class="checkbox{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} has-error{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label and not field|is_checkbox and form_show_labels %}
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
{% if field|is_checkboxselectmultiple %}
{% include 'bootstrap4/layout/checkboxselectmultiple.html' %}
{% endif %}
{% if field|is_radioselect %}
{% include 'bootstrap4/layout/radioselect.html' %}
{% endif %}
{% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
{% if field|is_checkbox and form_show_labels %}
<label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
{% crispy_field field %}
{{ field.label|safe }}
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
</label>
{% else %}
<div class="controls {{ field_class }}">
{% crispy_field field %}
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
</div>
{% endif %}
{% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% if field|is_checkbox %}
{% if label_class %}
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
{% if inputs %}
<div class="form-group row">
{% if label_class %}
<div class="aab controls {{ label_class }}"></div>
{% endif %}
<div class="controls {{ field_class }}">
{% for input in inputs %}
{% include "bootstrap4/layout/baseinput.html" %}
{% endfor %}
</div>
</div>
{% endif %}
<div{% if alert.css_id %} id="{{ alert.css_id }}"{% endif %}{% if alert.css_class %} class="{{ alert.css_class }}"{% endif %}>
{% if dismiss %}<button type="button" class="close" data-dismiss="alert">&times;</button>{% endif %}
{{ content|safe }}
</div>
\ No newline at end of file
<input type="{{ input.input_type }}"
name="{% if input.name|wordcount > 1 %}{{ input.name|slugify }}{% else %}{{ input.name }}{% endif %}"
value="{{ input.value }}"
{% if input.input_type != "hidden" %}
class="{{ input.field_classes }}"
id="{% if input.id %}{{ input.id }}{% else %}{{ input.input_type }}-id-{{ input.name|slugify }}{% endif %}"
{% endif %}
{{ input.flat_attrs|safe }}
/>
<button {{ button.flat_attrs|safe }}>{{ button.content|safe }}</button>
<div {% if buttonholder.css_id %}id="{{ buttonholder.css_id }}"{% endif %}
class="buttonHolder{% if buttonholder.css_class %} {{ buttonholder.css_class }}{% endif %}">
{{ fields_output|safe }}
</div>
{% load crispy_forms_filters %}
{% load l10n %}
<div class="controls {{ field_class }}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
{% include 'bootstrap4/layout/field_errors_block.html' %}
{% for choice in field.field.choices %}
{% if not inline_class %}<div class="checkbox">{% endif %}
<label class="{% if inline_class %}checkbox-{{ inline_class }}{% endif %}">
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>
{{ choice.1|unlocalize }}
</label>
{% if not inline_class %}</div>{% endif %}
{% endfor %}
{% include 'bootstrap4/layout/help_text.html' %}
</div>
{% if field.is_hidden %}
{{ field }}
{% else %}
<div id="div_{{ field.auto_id }}" class="form-group row{% if form_show_errors and field.errors %} has-error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label %}
<label for="{{ field.auto_id }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
{% include 'bootstrap4/layout/checkboxselectmultiple.html' %}
</div>
{% endif %}
<div {% if div.css_id %}id="{{ div.css_id }}"{% endif %}
{% if div.css_class %}class="{{ div.css_class }}"{% endif %} {{ div.flat_attrs|safe }}>
{{ fields|safe }}
</div>
{% if form_show_errors and field.errors %}
{% for error in field.errors %}
<span id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="help-block"><strong>{{ error }}</strong></span>
{% endfor %}
{% endif %}
{% if form_show_errors and field.errors %}
{% for error in field.errors %}
<p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="help-block"><strong>{{ error }}</strong></p>
{% endfor %}
{% endif %}
{% load crispy_forms_field %}
<div{% if div.css_id %} id="{{ div.css_id }}"{% endif %} class="form-group row{% if form_show_errors and field.errors %} has-error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}{% if div.css_class %} {{ div.css_class }}{% endif %}" {{ div.flat_attrs|safe }}>
{% if field.label and form_show_labels %}
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<div class="controls {{ field_class }}">
<div class="input-group">
{% crispy_field field %}
<span class="input-group-btn{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ buttons|safe }}</span>
</div>
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
</div>
</div>
<fieldset {% if fieldset.css_id %}id="{{ fieldset.css_id }}"{% endif %}
{% if fieldset.css_class or form_style %}class="{{ fieldset.css_class }} {{ form_style }}"{% endif %}
{{ fieldset.flat_attrs|safe }}>
{% if legend %}<legend>{{ legend|safe }}</legend>{% endif %}
{{ fields|safe }}
</fieldset>
<div{% if formactions.attrs %} {{ formactions.flat_attrs|safe }}{% endif %} class="form-group row">
{% if label_class %}
<div class="aab controls {{ label_class }}"></div>
{% endif %}
<div class="controls {{ field_class }}">
{{ fields_output|safe }}
</div>
</div>
{% if field.help_text %}
{% if help_text_inline %}
<span id="hint_{{ field.auto_id }}" class="help-block">{{ field.help_text|safe }}</span>
{% else %}
<p id="hint_{{ field.auto_id }}" class="help-block">{{ field.help_text|safe }}</p>
{% endif %}
{% endif %}
{% if help_text_inline and not error_text_inline %}
{% include 'bootstrap4/layout/help_text.html' %}
{% endif %}
{% if error_text_inline %}
{% include 'bootstrap4/layout/field_errors.html' %}
{% else %}
{% include 'bootstrap4/layout/field_errors_block.html' %}
{% endif %}
{% if not help_text_inline %}
{% include 'bootstrap4/layout/help_text.html' %}
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
{% if field|is_checkbox %}
<div id="div_{{ field.auto_id }}" class="checkbox">
<label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
{% crispy_field field 'class' 'checkbox' %}
{{ field.label|safe }}
</label>
</div>
{% else %}
<div id="div_{{ field.auto_id }}" class="form-group">
<label for="{{ field.id_for_label }}" class="sr-only{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}
</label>
{% crispy_field field 'placeholder' field.label %}
</div>
{% endif %}
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
{% if field.label %}
<label for="{{ field.id_for_label }}"{% if labelclass %} class="{{ labelclass }}"{% endif %}>
{% endif %}
{% if field|is_checkbox %}
{% crispy_field field %}
{% endif %}
{% if field.label %}
{{ field.label }}
{% endif %}
{% if not field|is_checkbox %}
{% crispy_field field %}
{% endif %}
{% if field.label %}
</label>
{% endif %}
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div id="div_{{ field.auto_id }}" class="form-group row{% if form_show_errors and field.errors %} has-error{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label and form_show_labels %}
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<div class="controls {{ field_class }}">
{% if field|is_select %}
{% if crispy_prepended_text %}<span class="input-group{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_prepended_text|safe }}</span>{% endif %}
{% crispy_field field %}
{% if crispy_appended_text %}<span class="input-group{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_appended_text|safe }}</span>{% endif %}
{% else %}
<div class="input-group">
{% if crispy_prepended_text %}<span class="input-group-addon{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_prepended_text|safe }}</span>{% endif %}
{% crispy_field field %}
{% if crispy_appended_text %}<span class="input-group-addon{% if active %} active{% endif %}{% if input_size %} {{ input_size }}{% endif %}">{{ crispy_appended_text|safe }}</span>{% endif %}
</div>
{% endif %}
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
</div>
</div>
{% endif %}
{% load crispy_forms_filters %}
{% load l10n %}
<div class="controls {{ field_class }}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>
{% include 'bootstrap4/layout/field_errors_block.html' %}
{% for choice in field.field.choices %}
{% if not inline_class %}<div class="radio">{% endif %}
<label class="{% if inline_class %}radio-{{ inline_class }}{% endif %}">
<input type="radio"{% if choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>
{{ choice.1|unlocalize }}
</label>