Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson committed Oct 17, 2017
2 parents 34ebbd7 + 86b2991 commit 5f5384b
Show file tree
Hide file tree
Showing 58 changed files with 701 additions and 539 deletions.
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

9 changes: 5 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
* Package version:
* Django version:
* Python version:
* Template pack: (Optional)

### Description:

// REPLACE ME: What are you trying to get done, what has happened, what went wrong, and what did you expect?

### Preferably also include:

-[ ] Example Django Crispy Forms code
-[ ] Screenshots
-[ ] Actual HTML generated
-[ ] Exepcted HTML
- [ ] Example Django Crispy Forms code
- [ ] Screenshots
- [ ] Actual HTML generated
- [ ] Expected HTML
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ __pycache__
tempfile
*.swp

# testing
.tox/

# coverage
.coverage
htmlcov
Expand Down
16 changes: 5 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ sudo: false

python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
env:
- DJANGO='django>=1.8.0,<1.9.0'
- DJANGO='django>=1.9.0,<1.10.0'
- DJANGO='django>=1.10.0,<1.11.0'
- DJANGO='django>=1.11.0,<2.0'
- DJANGO='https://github.com/django/django/archive/master.tar.gz'
before_install:
- pip install --upgrade 'pytest<3.0.0'
Expand All @@ -24,22 +24,16 @@ notifications:
email: false
matrix:
exclude:
- python: "3.2"
- python: "2.7"
env: DJANGO='https://github.com/django/django/archive/master.tar.gz'
- python: "3.2"
env: DJANGO='django>=1.10.0,<1.11.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.10.0,<1.11.0'
env: DJANGO='django>=1.11.0,<2.0'
- python: "3.3"
env: DJANGO='django>=1.9.0,<1.10.0'
env: DJANGO='django>=1.10.0,<1.11.0'
- python: "3.4"
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:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG for django-crispy-forms

## 1.7.0 (2017/10/17)

* Fixes compatibility with Django 2.0
* Various other fixes.

See [1.7 Milestone](https://github.com/django-crispy-forms/django-crispy-forms/milestone/4?closed=1)
for full issue list.

## 1.6.1 (2016/10/17)

* Updates compatibility for Django 1.10
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
django-crispy-forms
===================

.. image:: https://travis-ci.org/maraujop/django-crispy-forms.png?branch=dev
.. image:: https://travis-ci.org/django-crispy-forms/django-crispy-forms.png?branch=dev
:alt: Build Status
:target: https://travis-ci.org/maraujop/django-crispy-forms
:target: https://travis-ci.org/django-crispy-forms/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
.. image:: http://codecov.io/github/django-crispy-forms/django-crispy-forms/coverage.svg?branch=master
:target: http://codecov.io/github/django-crispy-forms/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.

`django-crispy-forms` supports Python 2.7/Python 3.2+ and Django 1.8+
`django-crispy-forms` supports Python 2.7/Python 3.3+ and Django 1.8/Django 1.10+

The application mainly provides:

Expand All @@ -27,7 +27,7 @@ Django-crispy-forms supports several frontend frameworks, such as Twitter `Boots
Authors
=======

django-crispy-forms is the new django-uni-form. django-uni-form was an application created by `Daniel Greenfeld`_ that I leaded since version 0.8.0. The name change tries to better explain the purpose of the application, which changed in a significant way since its birth.
django-crispy-forms is the new django-uni-form. django-uni-form was an application created by `Daniel Greenfeld`_ that I led since version 0.8.0. The name change tries to better explain the purpose of the application, which changed in a significant way since its birth.

If you are upgrading from django-uni-form, we have `instructions`_ for helping you.

Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '1.6.1'
__version__ = '1.7.0'
16 changes: 9 additions & 7 deletions crispy_forms/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import unicode_literals

from random import randint

from django.template import Template
from django.template.loader import render_to_string
from django.template.defaultfilters import slugify
from django.template.loader import render_to_string

from .compatibility import text_type
from .layout import LayoutObject, Field, Div
from .utils import render_field, flatatt, TEMPLATE_PACK
from .layout import Div, Field, LayoutObject, TemplateNameMixin
from .utils import TEMPLATE_PACK, flatatt, render_field


class PrependedAppendedText(Field):
Expand All @@ -30,12 +31,13 @@ def __init__(self, field, prepended_text=None, appended_text=None, *args, **kwar
super(PrependedAppendedText, self).__init__(field, *args, **kwargs)

def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_context=None, **kwargs):
extra_context = {
extra_context = extra_context.copy() if extra_context is not None else {}
extra_context.update({
'crispy_appended_text': self.appended_text,
'crispy_prepended_text': self.prepended_text,
'input_size': self.input_size,
'active': getattr(self, "active", False)
}
})
if hasattr(self, 'wrapper_class'):
extra_context['wrapper_class'] = self.wrapper_class
template = self.get_template_name(template_pack)
Expand Down Expand Up @@ -159,7 +161,7 @@ def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, extra_c
)


class StrictButton(object):
class StrictButton(TemplateNameMixin):
"""
Layout object for rendering an HTML button::
Expand All @@ -185,7 +187,7 @@ def __init__(self, content, **kwargs):

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
template = self.get_template_name(template_pack)
context.update({'button': self})

return render_to_string(template, context.flatten())
Expand Down
17 changes: 0 additions & 17 deletions crispy_forms/compatibility.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import sys

from django.utils.functional import SimpleLazyObject

try:
basestring
except:
Expand All @@ -18,18 +16,3 @@
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
44 changes: 30 additions & 14 deletions crispy_forms/helper.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# -*- coding: utf-8 -*-
import re

from django.core.urlresolvers import reverse, NoReverseMatch
from django.utils.safestring import mark_safe

from crispy_forms.compatibility import string_types
from crispy_forms.exceptions import FormHelpersException
from crispy_forms.layout import Layout
from crispy_forms.layout_slice import LayoutSlice
from crispy_forms.utils import render_field, flatatt, TEMPLATE_PACK, list_intersection, list_difference
from crispy_forms.exceptions import FormHelpersException
from crispy_forms.utils import (
TEMPLATE_PACK, flatatt, list_difference, list_intersection, render_field,
)

try:
from django.urls import reverse, NoReverseMatch
except ImportError:
# Django < 1.10
from django.core.urlresolvers import reverse, NoReverseMatch


class DynamicLayoutHandler(object):
Expand Down Expand Up @@ -131,10 +138,13 @@ class FormHelper(DynamicLayoutHandler):
**form_id**: Generates a form id for dom identification.
If no id provided then no id attribute is created on the form.
**form_class**: String containing separated CSS clases to be applied
**form_class**: String containing separated CSS classes to be applied
to form class attribute. The form will always have by default
'uniForm' class.
**form_group_wrapper_class**: String containing separated CSS classes to be applied
to each row of inputs.
**form_tag**: It specifies if <form></form> tags should be rendered when using a Layout.
If set to False it renders the form without the <form></form> tags. Defaults to True.
Expand Down Expand Up @@ -189,6 +199,7 @@ def helper(self):
form = None
form_id = ''
form_class = ''
form_group_wrapper_class = ''
layout = None
form_tag = True
form_error_title = None
Expand Down Expand Up @@ -326,7 +337,16 @@ def render_layout(self, form, context, template_pack=TEMPLATE_PACK):
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)
# We still respect the configuration of the helper
# regarding which fields to render
if (
self.render_unmentioned_fields or
(self.render_hidden_fields and
form.fields[field].widget.is_hidden) or
(self.render_required_fields and
form.fields[field].widget.is_required)
):
html += render_field(field, form, self.form_style, context)

return mark_safe(html)

Expand All @@ -348,15 +368,9 @@ def get_attributes(self, template_pack=TEMPLATE_PACK):
'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)
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
bootstrap_size_match = re.findall('col-(lg|md|sm|xs)-(\d+)', self.label_class)
if bootstrap_size_match:
items['bootstrap_checkbox_offsets'] = ['col-%s-offset-%s' % m for m in bootstrap_size_match]

items['attrs'] = {}
if self.attrs:
Expand All @@ -374,6 +388,8 @@ def get_attributes(self, template_pack=TEMPLATE_PACK):
else:
if template_pack == 'uni_form':
items['attrs']['class'] = self.attrs.get('class', '') + " uniForm"
if self.form_group_wrapper_class:
items['attrs']['form_group_wrapper_class'] = self.form_group_wrapper_class

items['flat_attrs'] = flatatt(items['attrs'])

Expand Down
11 changes: 9 additions & 2 deletions crispy_forms/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from django.utils.html import conditional_escape

from crispy_forms.compatibility import string_types, text_type
from crispy_forms.utils import render_field, flatatt, TEMPLATE_PACK, get_template_pack
from crispy_forms.utils import (
TEMPLATE_PACK, flatatt, get_template_pack, render_field,
)


class TemplateNameMixin(object):
Expand Down Expand Up @@ -53,7 +55,7 @@ def get_field_names(self, index=None):
[[0,3], 'field_name2']
]
"""
return self.get_layout_objects(string_types, greedy=True)
return self.get_layout_objects(string_types, index=None, greedy=True)

def get_layout_objects(self, *LayoutClasses, **kwargs):
"""
Expand Down Expand Up @@ -306,6 +308,7 @@ def __init__(self, label, *fields, **kwargs):
self.label_class = kwargs.pop('label_class', 'blockLabel')
self.css_class = kwargs.pop('css_class', 'ctrlHolder')
self.css_id = kwargs.pop('css_id', None)
self.help_text = kwargs.pop('help_text', None)
self.template = kwargs.pop('template', self.template)
self.field_template = kwargs.pop('field_template', self.field_template)
self.flat_attrs = flatatt(kwargs)
Expand Down Expand Up @@ -416,6 +419,9 @@ def __init__(self, *args, **kwargs):

if not hasattr(self, 'attrs'):
self.attrs = {}
else:
# Make sure shared state is not edited.
self.attrs = self.attrs.copy()

if 'css_class' in kwargs:
if 'class' in self.attrs:
Expand Down Expand Up @@ -465,3 +471,4 @@ def __init__(self, *args, **kwargs):
self.fields = list(args)
self.attrs = kwargs.pop('attrs', {})
self.template = kwargs.pop('template', self.template)
self.wrapper_class = kwargs.pop('wrapper_class', None)
2 changes: 1 addition & 1 deletion crispy_forms/layout_slice.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from crispy_forms.bootstrap import Container
from crispy_forms.compatibility import integer_types, string_types
from crispy_forms.exceptions import DynamicError
from crispy_forms.layout import Fieldset, MultiField
from crispy_forms.bootstrap import Container


class LayoutSlice(object):
Expand Down
Empty file removed crispy_forms/models.py
Empty file.
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% if field|is_checkbox and form_show_labels %}
<label for="{{ field.id_for_label }}" class="checkbox {% if field.field.required %}requiredField{% endif %}">
{% crispy_field field %}
{{ field.label|safe }}
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
</label>
{% include 'bootstrap/layout/help_text_and_errors.html' %}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% for choice in field.field.choices %}
<label class="checkbox{% if inline_class %} {{ 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 }}
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|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>
{% endfor %}

Expand Down
4 changes: 2 additions & 2 deletions crispy_forms/templates/bootstrap/layout/radioselect.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{% include 'bootstrap/layout/field_errors_block.html' %}

{% for choice in field.field.choices %}
<label class="radio{% if inline_class %} {{ 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 for="id_{{ field.html_name }}_{{ forloop.counter }}" class="radio{% if inline_class %} {{ inline_class }}{% endif %}">
<input type="radio"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|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>
{% endfor %}

Expand Down
6 changes: 6 additions & 0 deletions crispy_forms/templates/bootstrap/table_inline_formset.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
</thead>

<tbody>
<tr class="hidden empty-form">
{% for field in formset.empty_form %}
{% include 'bootstrap/field.html' with tag="td" form_show_labels=False %}
{% endfor %}
</tr>

{% for form in formset %}
{% if form_show_errors and not form.is_extra %}
{% include "bootstrap/errors.html" %}
Expand Down

0 comments on commit 5f5384b

Please sign in to comment.