Commit 344c0776 authored by Michael Fladischer's avatar Michael Fladischer

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

parent 130880f6
[run]
branch = True
# http://editorconfig.org
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{html,py,rst}]
indent_style = space
indent_size = 4
[*.{html,rst}]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
insert_final_newline = false
......@@ -23,6 +23,7 @@ tempfile
# coverage
.coverage
htmlcov
_build
# OSX
......
language: python
sudo: false
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
env:
- DJANGO=1.3.7
- DJANGO=1.4.5
- DJANGO=1.5.1
- 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='https://github.com/django/django/archive/master.tar.gz'
install:
- pip install Django==$DJANGO
- pip install "file://`pwd`#egg=django-crispy-forms[tests]"
- pip install -e . --use-mirrors
- pip install $DJANGO
- pip install -e .
script:
- make test
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=1.4.5
env: DJANGO='django>=1.4.0,<1.5.0'
- python: "3.3"
env: DJANGO=1.3.7
env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
- 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'
allow_failures:
- env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
after_success:
- bash <(curl -s https://codecov.io/bash)
This diff is collapsed.
......@@ -2,10 +2,11 @@
Contributors
============
django-crispy-forms Project Lead
================================
django-crispy-forms Project Maintainers
=======================================
* Miguel Araujo <miguel.araujo.perez@gmail.com>
* Carlton Gibson <carlton.gibson@noumenal.es>
django-uni-form Project Founder
===============================
......@@ -85,10 +86,23 @@ Contributors
* Chris Vigelius <chrisv2>
* David Cramer <dcramer>
* Stas Rudakou <nott>
* <tepez>
* Tom Yam <tepez>
* Svyatoslav Bulbakha <ssbb>
* Andres Vargas <zodman>
* Gabe Jackson <gabejackson>
* Camilo Nova <camilonova>
* <mrkre>
* Daniel Mascarenhas <danielmt>
* Paras Kuhad <pkuhad>
* Kevin Trad <hekevintran>
* Steven Klass <rh0dium>
* David Fischer <davidfischer-ch>
* Stefan Tjarks <stj>
* Jan Dittberner <jandd>
* Michael Nielsen <K0den>
* Stephen Mitchell <scuml>
* <pySilver>
* Christopher Adams <adamsc64>
* John Comeau <jcomeauictx>
* Yoong Kang Lim <yoongkang>
* Dmitry Dygalo <Stranger6667>
Copyright (c) 2009-2011 Miguel Araujo and contributors.
Copyright (c) 2009-2015 Miguel Araujo and contributors.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
......
......@@ -4,4 +4,4 @@ include MANIFEST.in
include README.rst
recursive-include crispy_forms/static *
recursive-include crispy_forms/templates *
recursive-include crispy_forms/tests *
recursive-include crispy_forms/tests *.py
.PHONY: develop test
develop:
pip install -q "file://`pwd`#egg=django-crispy-forms[tests]"
pip install -q -e . --use-mirrors
pip install -q -r requirements.txt
pip install -q -e .
test: develop
cd crispy_forms/tests && python runtests.py
\ No newline at end of file
DJANGO_SETTINGS_MODULE=crispy_forms.tests.test_settings py.test crispy_forms/tests --cov=crispy_forms
\ No newline at end of file
......@@ -2,10 +2,13 @@
django-crispy-forms
===================
.. image:: https://travis-ci.org/maraujop/django-crispy-forms.png?branch=master
.. image:: https://travis-ci.org/maraujop/django-crispy-forms.png?branch=dev
:alt: Build Status
:target: https://travis-ci.org/maraujop/django-crispy-forms
.. image:: http://codecov.io/github/maraujop/django-crispy-forms/coverage.svg?branch=master
:target: http://codecov.io/github/maraujop/django-crispy-forms?branch=master
The best way to have Django_ DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered HTML without writing HTML in templates. All this without breaking the standard way of doing things in Django, so it plays nice with any other form application.
The application mainly provides:
......
# -*- coding: utf-8 -*-
__version__ = '1.4.0'
__version__ = '1.5.2'
# -*- coding: utf-8 -*-
def from_iterable(iterables):
"""
Backport of `itertools.chain.from_iterable` compatible with Python 2.5
"""
for it in iterables:
for element in it:
if isinstance(element, dict):
for key in element:
yield key
else:
yield element
class KeepContext(object):
"""
Context manager that receives a `django.template.Context` instance, tracks its changes
and rolls them back when exiting the context manager, leaving the context unchanged.
Context manager that receives a `django.template.Context` instance and a list of keys
Layout objects can introduce context variables, that may cause side effects in later
layout objects. This avoids that situation, without copying context every time.
Once the context manager is exited, it removes `keys` from the context, to avoid
side effects in later layout objects that may use the same context variables.
Layout objects should use `extra_context` to introduce context variables, never
touch context object themselves, that could introduce side effects.
"""
def __init__(self, context):
def __init__(self, context, keys):
self.context = context
self.keys = keys
def __enter__(self):
self.old_set_keys = set(from_iterable(self.context.dicts))
pass
def __exit__(self, type, value, traceback):
current_set_keys = set(from_iterable(self.context.dicts))
diff_keys = current_set_keys - self.old_set_keys
# We remove added keys for rolling back changes
for key in diff_keys:
self._delete_key_from_context(key)
def _delete_key_from_context(self, key):
for d in self.context.dicts:
if key in d:
del d[key]
for key in list(self.keys):
if key in self.context:
del self.context[key]
This diff is collapsed.
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
try:
basestring
except:
basestring = str # Python3
PY2 = sys.version_info[0] == 2
if not PY2:
......@@ -12,3 +30,18 @@ else:
binary_type = str
string_types = basestring
integer_types = (int, long)
try:
# avoid RemovedInDjango19Warning by using lru_cache where available
from django.utils.lru_cache import lru_cache
except ImportError:
from django.utils.functional import memoize
def lru_cache():
def decorator(function, cache_dict=None):
if cache_dict is None:
cache_dict = {}
return memoize(function, cache_dict, 1)
return decorator
......@@ -202,7 +202,6 @@ class FormHelper(DynamicLayoutHandler):
field_template = None
disable_csrf = False
label_class = ''
label_size = ''
field_class = ''
def __init__(self, form=None):
......@@ -216,65 +215,63 @@ class FormHelper(DynamicLayoutHandler):
def build_default_layout(self, form):
return Layout(*form.fields.keys())
def get_form_method(self):
@property
def form_method(self):
return self._form_method
def set_form_method(self, method):
@form_method.setter
def form_method(self, method):
if method.lower() not in ('get', 'post'):
raise FormHelpersException('Only GET and POST are valid in the \
form_method helper attribute')
self._form_method = method.lower()
# we set properties the old way because we want to support pre-2.6 python
form_method = property(get_form_method, set_form_method)
def get_form_action(self):
@property
def form_action(self):
try:
return reverse(self._form_action)
except NoReverseMatch:
return self._form_action
def set_form_action(self, action):
@form_action.setter
def form_action(self, action):
self._form_action = action
# we set properties the old way because we want to support pre-2.6 python
form_action = property(get_form_action, set_form_action)
def get_form_style(self):
@property
def form_style(self):
if self._form_style == "default":
return ''
if self._form_style == "inline":
return 'inlineLabels'
def set_form_style(self, style):
@form_style.setter
def form_style(self, style):
if style.lower() not in ('default', 'inline'):
raise FormHelpersException('Only default and inline are valid in the \
form_style helper attribute')
self._form_style = style.lower()
form_style = property(get_form_style, set_form_style)
def get_help_text_inline(self):
@property
def help_text_inline(self):
return self._help_text_inline
def set_help_text_inline(self, flag):
@help_text_inline.setter
def help_text_inline(self, flag):
self._help_text_inline = flag
self._error_text_inline = not flag
help_text_inline = property(get_help_text_inline, set_help_text_inline)
def get_error_text_inline(self):
@property
def error_text_inline(self):
return self._error_text_inline
def set_error_text_inline(self, flag):
@error_text_inline.setter
def error_text_inline(self, flag):
self._error_text_inline = flag
self._help_text_inline = not flag
error_text_inline = property(get_error_text_inline, set_error_text_inline)
def add_input(self, input_object):
self.inputs.append(input_object)
......@@ -288,7 +285,7 @@ class FormHelper(DynamicLayoutHandler):
form.rendered_fields = set()
form.crispy_field_template = self.field_template
# This renders the specifed Layout strictly
# This renders the specified Layout strictly
html = self.layout.render(
form,
self.form_style,
......@@ -333,22 +330,26 @@ class FormHelper(DynamicLayoutHandler):
"""
Used by crispy_forms_tags to get helper attributes
"""
items = {}
items['form_method'] = self.form_method.strip()
items['form_tag'] = self.form_tag
items['form_style'] = self.form_style.strip()
items['form_show_errors'] = self.form_show_errors
items['help_text_inline'] = self.help_text_inline
items['error_text_inline'] = self.error_text_inline
items['html5_required'] = self.html5_required
items['form_show_labels'] = self.form_show_labels
items['disable_csrf'] = self.disable_csrf
items['label_class'] = self.label_class
items['field_class'] = self.field_class
label_size_match = re.match('col-lg-(\d+)', self.label_class)
if label_size_match:
items = {
'form_method': self.form_method.strip(),
'form_tag': self.form_tag,
'form_style': self.form_style.strip(),
'form_show_errors': self.form_show_errors,
'help_text_inline': self.help_text_inline,
'error_text_inline': self.error_text_inline,
'html5_required': self.html5_required,
'form_show_labels': self.form_show_labels,
'disable_csrf': self.disable_csrf,
'label_class': self.label_class,
'field_class': self.field_class
}
# col-[lg|md|sm|xs]-<number>
label_size_match = re.search('(\d+)', self.label_class)
device_type_match = re.search('(lg|md|sm|xs)', self.label_class)
if label_size_match and device_type_match:
try:
items['label_size'] = int(label_size_match.groups()[0])
items['bootstrap_device_type'] = device_type_match.groups()[0]
except:
pass
......
This diff is collapsed.
......@@ -12,7 +12,7 @@ class LayoutSlice(object):
def __init__(self, layout, key):
self.layout = layout
if isinstance(key, integer_types):
self.slice = slice(key, key+1, 1)
self.slice = slice(key, key + 1, 1)
else:
self.slice = key
......@@ -23,7 +23,7 @@ class LayoutSlice(object):
"""
if args:
if isinstance(fields, list):
fields= tuple(fields)
fields = tuple(fields)
else:
fields = (fields,)
......
{% if form.form_html %}
{{ form.media }}
{% if form_show_errors %}
{% include "bootstrap/errors.html" %}
{% endif %}
......
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{{ field }}
{% else %}
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="control-group{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} 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 {% if field.field.required %}requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="control-group{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} 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 {% 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 'bootstrap/layout/checkboxselectmultiple.html' %}
......@@ -32,5 +32,5 @@
{% endif %}
</div>
{% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% 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 }}
{% if dismiss %}<button type="button" class="close" data-dismiss="alert">&times;</button>{% endif %}
{{ content|safe }}
</div>
\ No newline at end of file
<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>
<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>
......@@ -13,9 +13,9 @@
<div class="controls">
<div class="{% if crispy_prepended_text %}input-prepend{% endif %} {% if crispy_appended_text %}input-append{% endif %}">
{% if crispy_prepended_text %}<span class="add-on{% if active %} active{% endif %}">{{ crispy_prepended_text|safe }}</span>{% endif %}
{% if crispy_prepended_text %}<span class="{% if not field|is_select %}add-on{% endif %}{% if active %} active{% endif %}">{{ crispy_prepended_text|safe }}</span>{% endif %}
{% crispy_field field %}
{% if crispy_appended_text %}<span class="add-on{% if active %} active{% endif %}">{{ crispy_appended_text|safe }}</span>{% endif %}
{% if crispy_appended_text %}<span class="{% if not field|is_select %}add-on{% endif %}{% if active %} active{% endif %}">{{ crispy_appended_text|safe }}</span>{% endif %}
</div>
{% include 'bootstrap/layout/help_text_and_errors.html' %}
......
......@@ -16,18 +16,18 @@
<table{% if form_id %} id="{{ form_id }}_table"{% endif%} class="table table-striped table-condensed">
<thead>
{% if formset.readonly and not formset.queryset.exists %}
{% else %}
<tr>
{% for field in formset.forms.0 %}
{% if field.label and not field|is_checkbox and not field.is_hidden %}
<th for="{{ field.auto_id }}" class="control-label {% if field.field.required %}requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</th>
{% endif %}
{% endfor %}
</tr>
{% endif %}
{% if formset.readonly and not formset.queryset.exists %}
{% else %}
<tr>
{% for field in formset.forms.0 %}
{% if field.label and not field.is_hidden %}
<th for="{{ field.auto_id }}" class="control-label {% if field.field.required and not field|is_checkbox %}requiredField{% endif %}">
{{ field.label|safe }}{% if field.field.required and not field|is_checkbox %}<span class="asteriskField">*</span>{% endif %}
</th>
{% endif %}
{% endfor %}
</tr>
{% endif %}
</thead>
<tbody>
......@@ -48,7 +48,7 @@
{% if inputs %}
<div class="form-actions">
{% for input in inputs %}
{% include "uni_form/layout/baseinput.html" %}
{% include "bootstrap/layout/baseinput.html" %}
{% endfor %}
</div>
{% endif %}
......
{% load crispy_forms_utils %}
{% specialspaceless %}
{% if form_show_errors %}
{% include "bootstrap/errors.html" %}
{% endif %}
{% for field in form %}
{% include "bootstrap/field.html" %}
{% endfor %}
{{ form.media }}
{% if form_show_errors %}
{% include "bootstrap/errors.html" %}
{% endif %}
{% for field in form %}
{% include "bootstrap/field.html" %}
{% endfor %}
{% endspecialspaceless %}
{% if form.form_html %}
{{ form.media }}
{% if form_show_errors %}
{% include "bootstrap3/errors.html" %}
{% endif %}
......
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{{ field }}
{% else %}
{% if field|is_checkbox %}
<div class="form-group">
{% 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{% 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 tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" {% if not field|is_checkbox %}class="form-group{% 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 'bootstrap3/layout/checkboxselectmultiple.html' %}
......@@ -23,17 +26,11 @@
{% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
{% if field|is_checkbox and form_show_labels %}
{% if label_class %}
<div class="controls col-lg-offset-{{ label_size }} {{ field_class }}">
{% endif %}
<label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
{% crispy_field field 'class' 'checkbox' %}
{% crispy_field field %}
{{ field.label|safe }}
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</label>
{% if label_class %}
</div>
{% endif %}
{% else %}
<div class="controls {{ field_class }}">
{% crispy_field field %}
......@@ -41,8 +38,11 @@
</div>
{% endif %}
{% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% if field|is_checkbox %}
{% if label_class %}
</div>
{% endif %}
</div>
{% endif %}
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
{% if field|is_checkbox %}
<div class="form-group">
{% endif %}
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" {% if not field|is_checkbox %}class="form-group{% 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 'bootstrap3/layout/checkboxselectmultiple.html' %}
{% endif %}
{% if field|is_radioselect %}
{% include 'bootstrap3/layout/radioselect.html' %}
{% endif %}
{% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
{% if field|is_checkbox and form_show_labels %}
{% if label_class %}
<label class="{{ label_class }}"></label>
<div class="controls {{ field_class }}">
{% endif %}
<label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
{% crispy_field field %}
{{ field.label|safe }}
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</label>
{% if label_class %}
</div>
{% endif %}
{% else %}
<div class="controls {{ field_class }}">
{% crispy_field field %}
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</div>
{% endif %}
{% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% if field|is_checkbox %}
</div>
{% endif %}
{% endif %}
{% load crispy_forms_field %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div id="div_{{ field.auto_id }}" class="ctrlHolder{% if field.errors %} has-error{% endif %}{% if field|is_checkbox %} checkbox{% endif %} {% if field.field.widget.attrs.class %} {{ field.field.widget.attrs.class }}{% endif %}">
{% for error in field.errors %}
<p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="errorField">
{{ error }}
</p>
{% endfor %}
{% if field|is_checkbox %}
{% crispy_field field %}
{% endif %}
{% if field.label %}
<label for="{{ field.id_for_label }}" class="inlineLabel">
{{ field.label|safe }}{% if field.field.required %}<em>*</em>{% endif %}
</label>
{% endif %}
{% if not field|is_checkbox %}
{% crispy_field field %}
{% endif %}
{% if field.help_text %}
<p id="hint_{{ field.auto_id }}" class="formHint">{{ field.help_text|safe }}</p>
{% endif %}