Skip to content

Commit

Permalink
Merge branch 'release/9.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Jul 11, 2017
2 parents 0e83d9d + 7ad05ff commit d5ffb42
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 139 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ pip-log.txt
*.log

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.tox
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
Expand Down
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ Contributors
* Caio Ariede <caio.ariede@gmail.com>
* Fabio C. Barrionuevo da Luz <bnafta@gmail.com>
* Fabio Perfetti <perfabio87@gmail.com>
* Irving Ckam <https://github.com/ickam>
* Jay Pipes <jaypipes@gmail.com>
* Jonas Hagstedt <hagstedt@gmail.com>
* Jordan Starcher <jstarcher@gmail.com>
* Juan Carlos <juancarlospaco@gmail.com>
* Markus Holtermann <info@markusholtermann.eu>
* Martin Koistinen <mkoistinen@gmail.com>
* Nick S <nsmith448@gmail.com>
* Owais Lone <loneowais@gmail.com>
* pmav99 <pmav99@users.noreply.github.com>
Expand Down
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ History
-------


9.0.0 (2017-07-11)
++++++++++++++++++

* Renamed requirements-dev.txt back to requirements.txt because that suits ReadTheDocs better
* Added `error_types` support on bootstrap3_form (thanks @mkoistinen and @ickam)
* **BREAKING** Default setting of `error_types` to `non_field_errors` is different fro behavior in versions < 9


8.2.3 (2017-05-05)
++++++++++++++++++

Expand Down
36 changes: 26 additions & 10 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
Copyright 2013-2014 Dylan Verheul
BSD 3-Clause License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Copyright (c) 2017, Dylan Verheul and individual contributors
All rights reserved.

http://www.apache.org/licenses/LICENSE-2.0
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion bootstrap3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

__version__ = '8.2.3'
__version__ = '9.0.0'
17 changes: 11 additions & 6 deletions bootstrap3/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@

FORM_GROUP_CLASS = 'form-group'

WIDGETS_NO_REQUIRED = (
AdminFileWidget,
HiddenInput,
FileInput,
CheckboxInput,
CheckboxSelectMultiple
)


def render_formset(formset, **kwargs):
"""
Expand All @@ -45,12 +53,12 @@ def render_form(form, **kwargs):
return renderer_cls(form, **kwargs).render()


def render_form_errors(form, type='all', **kwargs):
def render_form_errors(form, error_types='non_field_errors', **kwargs):
"""
Render form errors to a Bootstrap layout
"""
renderer_cls = get_form_renderer(**kwargs)
return renderer_cls(form, **kwargs).render_errors(type)
return renderer_cls(form, **kwargs).render_errors(error_types)


def render_field(field, **kwargs):
Expand Down Expand Up @@ -167,10 +175,7 @@ def is_widget_required_attribute(widget):
return False
if not widget.is_required:
return False
if isinstance(
widget, (
AdminFileWidget, HiddenInput, FileInput,
CheckboxInput, CheckboxSelectMultiple)):
if isinstance(widget, WIDGETS_NO_REQUIRED):
return False
return True

Expand Down
17 changes: 10 additions & 7 deletions bootstrap3/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(self, form, *args, **kwargs):
if DBS3_SET_REQUIRED_SET_DISABLED and self.form.empty_permitted:
self.set_required = False

self.error_types = kwargs.get('error_types', 'non_field_errors')
self.error_css_class = kwargs.get('error_css_class', None)
self.required_css_class = kwargs.get('required_css_class', None)
self.bound_css_class = kwargs.get('bound_css_class', None)
Expand Down Expand Up @@ -201,14 +202,16 @@ def get_fields_errors(self):
form_errors += field.errors
return form_errors

def render_errors(self, type='all'):
form_errors = None
if type == 'all':
def render_errors(self, error_types='all'):
form_errors = []
if error_types == 'all':
form_errors = self.get_fields_errors() + self.form.non_field_errors()
elif type == 'fields':
elif error_types == 'field_errors':
form_errors = self.get_fields_errors()
elif type == 'non_fields':
elif error_types == 'non_field_errors':
form_errors = self.form.non_field_errors()
elif error_types and error_types != 'none':
raise Exception('Illegal value "{}" for error_types.')

if form_errors:
return render_template_file(
Expand All @@ -217,14 +220,14 @@ def render_errors(self, type='all'):
'errors': form_errors,
'form': self.form,
'layout': self.layout,
'type': type,
'error_types': error_types,
}
)

return ''

def _render(self):
return self.render_errors() + self.render_fields()
return self.render_errors(self.error_types) + self.render_fields()


class FieldRenderer(BaseRenderer):
Expand Down
23 changes: 15 additions & 8 deletions bootstrap3/templatetags/bootstrap3.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ def bootstrap_form(*args, **kwargs):
A list of field names (comma separated) that should not be rendered
E.g. exclude=subject,bcc
error_types
This controls the types of errors that are rendered above the form.
Choices are: "all", "field_errors", "non_field_errors" or "none". This will not
affect the display of errors on the fields themselves.
Default is "non_field_errors".
See bootstrap_field_ for other arguments
**Usage**::
Expand Down Expand Up @@ -345,16 +352,16 @@ def bootstrap_form_errors(*args, **kwargs):
form
The form that is to be rendered
type
error_types
Control which type of errors should be rendered.
One of the following values:
* ``'all'``
* ``'fields'``
* ``'non_fields'``
* ``'field_errors'``
* ``'non_field_errors'``
:default: ``'all'``
:default: ``'non_field_errors'``
layout
Context value that is available in the template ``bootstrap3/form_errors.html`` as ``layout``.
Expand Down Expand Up @@ -451,20 +458,20 @@ def bootstrap_field(*args, **kwargs):
addon_before
Text that should be prepended to the form field. Can also be an icon, e.g.
``'<span class="glyphicon glyphicon-calendar"></span>'``
See the `Bootstrap docs <http://getbootstrap.com/components/#input-groups-basic>` for more examples.
addon_after
Text that should be appended to the form field. Can also be an icon, e.g.
``'<span class="glyphicon glyphicon-calendar"></span>'``
See the `Bootstrap docs <http://getbootstrap.com/components/#input-groups-basic>` for more examples.
addon_before_class
Class used on the span when ``addon_before`` is used.
One of the following values:
* ``'input-group-addon'``
* ``'input-group-btn'``
Expand All @@ -474,7 +481,7 @@ def bootstrap_field(*args, **kwargs):
Class used on the span when ``addon_after`` is used.
One of the following values:
* ``'input-group-addon'``
* ``'input-group-btn'``
Expand Down

0 comments on commit d5ffb42

Please sign in to comment.