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 ...@@ -23,6 +23,7 @@ tempfile
# coverage # coverage
.coverage .coverage
htmlcov
_build _build
# OSX # OSX
......
language: python language: python
sudo: false
python: python:
- "2.6" - "2.6"
- "2.7" - "2.7"
- "3.2"
- "3.3" - "3.3"
- "3.4"
env: env:
- DJANGO=1.3.7 - DJANGO='django>=1.4.0,<1.5.0'
- DJANGO=1.4.5 - DJANGO='django>=1.7.0,<1.8.0'
- DJANGO=1.5.1 - DJANGO='django>=1.8.0,<1.9.0'
- DJANGO='https://github.com/django/django/archive/master.tar.gz'
install: install:
- pip install Django==$DJANGO - pip install $DJANGO
- pip install "file://`pwd`#egg=django-crispy-forms[tests]" - pip install -e .
- pip install -e . --use-mirrors
script: script:
- make test - make test
notifications: notifications:
email: false email: false
matrix: matrix:
exclude: 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" - python: "3.3"
env: DJANGO=1.4.5 env: DJANGO='django>=1.4.0,<1.5.0'
- python: "3.3" - 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 @@ ...@@ -2,10 +2,11 @@
Contributors Contributors
============ ============
django-crispy-forms Project Lead django-crispy-forms Project Maintainers
================================ =======================================
* Miguel Araujo <miguel.araujo.perez@gmail.com> * Miguel Araujo <miguel.araujo.perez@gmail.com>
* Carlton Gibson <carlton.gibson@noumenal.es>
django-uni-form Project Founder django-uni-form Project Founder
=============================== ===============================
...@@ -85,10 +86,23 @@ Contributors ...@@ -85,10 +86,23 @@ Contributors
* Chris Vigelius <chrisv2> * Chris Vigelius <chrisv2>
* David Cramer <dcramer> * David Cramer <dcramer>
* Stas Rudakou <nott> * Stas Rudakou <nott>
* <tepez> * Tom Yam <tepez>
* Svyatoslav Bulbakha <ssbb> * Svyatoslav Bulbakha <ssbb>
* Andres Vargas <zodman> * Andres Vargas <zodman>
* Gabe Jackson <gabejackson> * Gabe Jackson <gabejackson>
* Camilo Nova <camilonova> * Camilo Nova <camilonova>
* <mrkre> * <mrkre>
* Daniel Mascarenhas <danielmt> * 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 Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation
......
...@@ -4,4 +4,4 @@ include MANIFEST.in ...@@ -4,4 +4,4 @@ include MANIFEST.in
include README.rst include README.rst
recursive-include crispy_forms/static * recursive-include crispy_forms/static *
recursive-include crispy_forms/templates * recursive-include crispy_forms/templates *
recursive-include crispy_forms/tests * recursive-include crispy_forms/tests *.py
.PHONY: develop test .PHONY: develop test
develop: develop:
pip install -q "file://`pwd`#egg=django-crispy-forms[tests]" pip install -q -r requirements.txt
pip install -q -e . --use-mirrors pip install -q -e .
test: develop test: develop
cd crispy_forms/tests && python runtests.py DJANGO_SETTINGS_MODULE=crispy_forms.tests.test_settings py.test crispy_forms/tests --cov=crispy_forms
\ No newline at end of file \ No newline at end of file
...@@ -2,10 +2,13 @@ ...@@ -2,10 +2,13 @@
django-crispy-forms 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 :alt: Build Status
:target: https://travis-ci.org/maraujop/django-crispy-forms :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 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: The application mainly provides:
......
# -*- coding: utf-8 -*- # -*- 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): class KeepContext(object):
""" """
Context manager that receives a `django.template.Context` instance, tracks its changes Context manager that receives a `django.template.Context` instance and a list of keys
and rolls them back when exiting the context manager, leaving the context unchanged.
Layout objects can introduce context variables, that may cause side effects in later Once the context manager is exited, it removes `keys` from the context, to avoid
layout objects. This avoids that situation, without copying context every time. 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.context = context
self.keys = keys
def __enter__(self): def __enter__(self):
self.old_set_keys = set(from_iterable(self.context.dicts)) pass
def __exit__(self, type, value, traceback): def __exit__(self, type, value, traceback):
current_set_keys = set(from_iterable(self.context.dicts)) for key in list(self.keys):
diff_keys = current_set_keys - self.old_set_keys if key in self.context:
del self.context[key]
# 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]
This diff is collapsed.
import sys 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 PY2 = sys.version_info[0] == 2
if not PY2: if not PY2:
...@@ -12,3 +30,18 @@ else: ...@@ -12,3 +30,18 @@ else:
binary_type = str binary_type = str
string_types = basestring string_types = basestring
integer_types = (int, long) 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): ...@@ -202,7 +202,6 @@ class FormHelper(DynamicLayoutHandler):
field_template = None field_template = None
disable_csrf = False disable_csrf = False
label_class = '' label_class = ''
label_size = ''
field_class = '' field_class = ''
def __init__(self, form=None): def __init__(self, form=None):
...@@ -216,65 +215,63 @@ class FormHelper(DynamicLayoutHandler): ...@@ -216,65 +215,63 @@ class FormHelper(DynamicLayoutHandler):
def build_default_layout(self, form): def build_default_layout(self, form):
return Layout(*form.fields.keys()) return Layout(*form.fields.keys())
def get_form_method(self): @property
def form_method(self):
return self._form_method 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'): if method.lower() not in ('get', 'post'):
raise FormHelpersException('Only GET and POST are valid in the \ raise FormHelpersException('Only GET and POST are valid in the \
form_method helper attribute') form_method helper attribute')
self._form_method = method.lower() self._form_method = method.lower()
# we set properties the old way because we want to support pre-2.6 python @property
form_method = property(get_form_method, set_form_method) def form_action(self):
def get_form_action(self):
try: try:
return reverse(self._form_action) return reverse(self._form_action)
except NoReverseMatch: except NoReverseMatch:
return self._form_action return self._form_action
def set_form_action(self, action): @form_action.setter
def form_action(self, action):
self._form_action = action self._form_action = action
# we set properties the old way because we want to support pre-2.6 python @property
form_action = property(get_form_action, set_form_action) def form_style(self):
def get_form_style(self):
if self._form_style == "default": if self._form_style == "default":
return '' return ''
if self._form_style == "inline": if self._form_style == "inline":
return 'inlineLabels' return 'inlineLabels'
def set_form_style(self, style): @form_style.setter
def form_style(self, style):
if style.lower() not in ('default', 'inline'): if style.lower() not in ('default', 'inline'):
raise FormHelpersException('Only default and inline are valid in the \ raise FormHelpersException('Only default and inline are valid in the \
form_style helper attribute') form_style helper attribute')
self._form_style = style.lower() self._form_style = style.lower()
form_style = property(get_form_style, set_form_style) @property
def help_text_inline(self):
def get_help_text_inline(self):
return self._help_text_inline 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._help_text_inline = flag
self._error_text_inline = not flag self._error_text_inline = not flag
help_text_inline = property(get_help_text_inline, set_help_text_inline) @property
def error_text_inline(self):
def get_error_text_inline(self):
return self._error_text_inline 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._error_text_inline = flag
self._help_text_inline = not 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): def add_input(self, input_object):
self.inputs.append(input_object) self.inputs.append(input_object)
...@@ -288,7 +285,7 @@ class FormHelper(DynamicLayoutHandler): ...@@ -288,7 +285,7 @@ class FormHelper(DynamicLayoutHandler):
form.rendered_fields = set() form.rendered_fields = set()
form.crispy_field_template = self.field_template form.crispy_field_template = self.field_template
# This renders the specifed Layout strictly # This renders the specified Layout strictly
html = self.layout.render( html = self.layout.render(
form, form,
self.form_style, self.form_style,
...@@ -333,22 +330,26 @@ class FormHelper(DynamicLayoutHandler): ...@@ -333,22 +330,26 @@ class FormHelper(DynamicLayoutHandler):
""" """
Used by crispy_forms_tags to get helper attributes Used by crispy_forms_tags to get helper attributes
""" """
items = {} items = {
items['form_method'] = self.form_method.strip() 'form_method': self.form_method.strip(),
items['form_tag'] = self.form_tag 'form_tag': self.form_tag,
items['form_style'] = self.form_style.strip() 'form_style': self.form_style.strip(),
items['form_show_errors'] = self.form_show_errors 'form_show_errors': self.form_show_errors,
items['help_text_inline'] = self.help_text_inline 'help_text_inline': self.help_text_inline,
items['error_text_inline'] = self.error_text_inline 'error_text_inline': self.error_text_inline,
items['html5_required'] = self.html5_required 'html5_required': self.html5_required,
items['form_show_labels'] = self.form_show_labels 'form_show_labels': self.form_show_labels,
items['disable_csrf'] = self.disable_csrf 'disable_csrf': self.disable_csrf,
items['label_class'] = self.label_class 'label_class': self.label_class,
items['field_class'] = self.field_class 'field_class': self.field_class
label_size_match = re.match('col-lg-(\d+)', self.label_class) }
if label_size_match: # 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: try:
items['label_size'] = int(label_size_match.groups()[0]) items['label_size'] = int(label_size_match.groups()[0])
items['bootstrap_device_type'] = device_type_match.groups()[0]
except: except:
pass pass
......
This diff is collapsed.
...@@ -12,7 +12,7 @@ class LayoutSlice(object): ...@@ -12,7 +12,7 @@ class LayoutSlice(object):
def __init__(self, layout, key): def __init__(self, layout, key):
self.layout = layout self.layout = layout
if isinstance(key, integer_types): if isinstance(key, integer_types):
self.slice = slice(key, key+1, 1) self.slice = slice(key, key + 1, 1)
else: else:
self.slice = key self.slice = key
...@@ -23,7 +23,7 @@ class LayoutSlice(object): ...@@ -23,7 +23,7 @@ class LayoutSlice(object):
""" """
if args: if args:
if isinstance(fields, list): if isinstance(fields, list):
fields= tuple(fields) fields = tuple(fields)
else: else:
fields = (fields,) fields = (fields,)
......
{% if form.form_html %} {% if form.form_html %}
{{ form.media }}
{% if form_show_errors %} {% if form_show_errors %}
{% include "bootstrap/errors.html" %} {% include "bootstrap/errors.html" %}
{% endif %} {% endif %}
......
{% load crispy_forms_field %} {% load crispy_forms_field %}
{% if field.is_hidden %} {% if field.is_hidden %}
{{ field }} {{ field }}
{% else %} {% 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 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 %} {% 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 %}"> <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 %} {{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label> </label>
{% endif %} {% endif %}
{% if field|is_checkboxselectmultiple %} {% if field|is_checkboxselectmultiple %}
{% include 'bootstrap/layout/checkboxselectmultiple.html' %} {% include 'bootstrap/layout/checkboxselectmultiple.html' %}
...@@ -32,5 +32,5 @@ ...@@ -32,5 +32,5 @@
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}
</{% if tag %}{{ tag }}{% else %}div{% endif %}> </{% if tag %}{{ tag }}{% else %}div{% endif %}>
{% endif %} {% endif %}
<div{% if alert.css_id %} id="{{ alert.css_id }}"{% endif %}{% if alert.css_class %} class="{{ alert.css_class }}"{% 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 %} {% if dismiss %}<button type="button" class="close" data-dismiss="alert">&times;</button>{% endif %}
{{ content|safe }} {{ content|safe }}
</div> </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 @@ ...@@ -13,9 +13,9 @@
<div class="controls"> <div class="controls">
<div class="{% if crispy_prepended_text %}input-prepend{% endif %} {% if crispy_appended_text %}input-append{% endif %}"> <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 %} {% 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> </div>
{% include 'bootstrap/layout/help_text_and_errors.html' %} {% include 'bootstrap/layout/help_text_and_errors.html' %}
......
...@@ -16,18 +16,18 @@ ...@@ -16,18 +16,18 @@
<table{% if form_id %} id="{{ form_id }}_table"{% endif%} class="table table-striped table-condensed"> <table{% if form_id %} id="{{ form_id }}_table"{% endif%} class="table table-striped table-condensed">
<thead> <thead>
{% if formset.readonly and not formset.queryset.exists %} {% if formset.readonly and not formset.queryset.exists %}
{% else %} {% else %}
<tr> <tr>
{% for field in formset.forms.0 %} {% for field in formset.forms.0 %}
{% if field.label and not field|is_checkbox and not field.is_hidden %} {% if field.label and not field.is_hidden %}
<th for="{{ field.auto_id }}" class="control-label {% if field.field.required %}requiredField{% endif %}"> <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 %}<span class="asteriskField">*</span>{% endif %} {{ field.label|safe }}{% if field.field.required and not field|is_checkbox %}<span class="asteriskField">*</span>{% endif %}
</th> </th>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
{% endif %} {% endif %}
</thead> </thead>
<tbody> <tbody>
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
{% if inputs %} {% if inputs %}
<div class="form-actions"> <div class="form-actions">
{% for input in inputs %} {% for input in inputs %}
{% include "uni_form/layout/baseinput.html" %} {% include "bootstrap/layout/baseinput.html" %}
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
......
{% load crispy_forms_utils %} {% load crispy_forms_utils %}
{% specialspaceless %} {% specialspaceless %}
{% if form_show_errors %} {{ form.media }}
{% include "bootstrap/errors.html" %} {% if form_show_errors %}
{% endif %} {% include "bootstrap/errors.html" %}
{% for field in form %} {% endif %}
{% include "bootstrap/field.html" %} {% for field in form %}
{% endfor %} {% include "bootstrap/field.html" %}
{% endfor %}
{% endspecialspaceless %} {% endspecialspaceless %}
{% if form.form_html %} {% if form.form_html %}
{{ form.media }}
{% if form_show_errors %} {% if form_show_errors %}
{% include "bootstrap3/errors.html" %} {% include "bootstrap3/errors.html" %}
{% endif %} {% endif %}
......
{% load crispy_forms_field %} {% load crispy_forms_field %}
{% if field.is_hidden %}