Skip to content

Commit

Permalink
Merge branch 'release/7.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Feb 24, 2016
2 parents 9a0e746 + a2d3600 commit 4d6be89
Show file tree
Hide file tree
Showing 22 changed files with 385 additions and 265 deletions.
37 changes: 13 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
# We do not use sudo
sudo: false

# Python versions for matrix
language: python
python:
- "2.7"
- "2.6"
- "3.2"
- "3.3"
- "3.4"
- "3.5"

# Django versions for matrix
env:
- DJANGO_VERSION=1.4.21
- DJANGO_VERSION=1.5.12
- DJANGO_VERSION=1.6.11
- DJANGO_VERSION=1.7.9
- DJANGO_VERSION=1.8.3
- DJANGO_VERSION='>=1.8,<1.9'
- DJANGO_VERSION='>=1.9,<1.10'

# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
# Command to install dependencies, e.g. pip install -r requirements.txt
install:
- pip install -q Django==$DJANGO_VERSION --use-mirrors --quiet
- pip install Django$DJANGO_VERSION
# Coverage 4.0 no longer supports py32. Install an older version before
# coveralls tries to install the latest
- if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then travis_retry pip install 'coverage<4.0'; fi
- pip install coveralls

# Command to run tests, e.g. python setup.py test
script:
- coverage run --source=bootstrap3 manage.py test

# Support Python3 only with Django 1.6+
# Support Django 1.7+ only with Python 2.7+
matrix:
exclude:
- python: "3.2"
env: DJANGO_VERSION=1.4.21
- python: "3.3"
env: DJANGO_VERSION=1.4.21
- python: "3.4"
env: DJANGO_VERSION=1.4.21
- python: "3.2"
env: DJANGO_VERSION=1.5.12
env: DJANGO_VERSION='>=1.9,<1.10'
- python: "3.3"
env: DJANGO_VERSION=1.5.12
- python: "3.4"
env: DJANGO_VERSION=1.5.12
- python: "2.6"
env: DJANGO_VERSION=1.7.9
- python: "2.6"
env: DJANGO_VERSION=1.8.3
env: DJANGO_VERSION='>=1.9,<1.10'

# Report to coveralls
after_success:
Expand Down
16 changes: 16 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
History
-------


7.0.0 (in progress)
+++++++++++++++++++

* Dropped support for Django < 1.8
* Dropped support for Python < 2.7
* Fix page number bug (thanks @frewsxcv)
* Fix template context warning (thanks @jieter and @jonashaag)
* Update to Bootstrap 3.3.6 (@nikolas)
* Show links and newlines in messages (@jakub3279)
* CSS classes arguments passed to the bootstrap_form are now working (@gordon)
* Support for Django 1.9/Python 3.5 (@jieter and @jonashaag)
* Better Travis CI Django versions (thanks @jonashaag)
* Improved handling of messages in `bootstrap_messages` (thanks @frewsxcv and @rjsparks)


6.2.2 (2015-08-20)
++++++++++++++++++

Expand Down
24 changes: 13 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Write Django as usual, and let ``django-bootstrap3`` make template output into B
:alt: Number of PyPI downloads per month


Requirements
------------

- Python 2.7, 3.2, 3.3, 3.4, or 3.5
- Django >= 1.8

*The latest version supporting Python 2.6 and Django < 1.8 is the 6.x.x branch.*


Installation
------------

Expand All @@ -35,6 +44,8 @@ Installation

3. In your templates, load the ``bootstrap3`` library and use the ``bootstrap_*`` tags:

This app will soon require Django 1.8+, python 2.7+. Thanks for understanding.


Example template
----------------
Expand Down Expand Up @@ -62,17 +73,8 @@ Documentation
The full documentation is at http://django-bootstrap3.readthedocs.org/.


Requirements
------------

- Python 2.6, 2.7, 3.2 or 3.3
- Django >= 1.4

Contributions and pull requests for other Django and Python versions are welcome.


Bugs and requests
-----------------
Bugs and suggestions
--------------------

If you have found a bug or if you have a request for additional functionality, please use the issue tracker on GitHub.

Expand Down
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__ = '6.2.2'
__version__ = '7.0.0'
2 changes: 1 addition & 1 deletion bootstrap3/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Default settings
BOOTSTRAP3_DEFAULTS = {
'jquery_url': '//code.jquery.com/jquery.min.js',
'base_url': '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/',
'base_url': '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/',
'css_url': None,
'theme_url': None,
'javascript_url': None,
Expand Down
4 changes: 3 additions & 1 deletion bootstrap3/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def render_label(content, label_for=None, label_class=None, label_title=''):

def render_button(
content, button_type=None, icon=None, button_class='', size='',
href='', name=None, value=None):
href='', name=None, value=None, title=None):
"""
Render a button with content
"""
Expand Down Expand Up @@ -117,6 +117,8 @@ def render_button(
attrs['name'] = name
if value:
attrs['value'] = value
if title:
attrs['title'] = title
return render_tag(
tag,
attrs=attrs,
Expand Down
73 changes: 39 additions & 34 deletions bootstrap3/renderers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth.forms import ReadOnlyPasswordHashWidget

from django.contrib.auth.forms import ReadOnlyPasswordHashWidget
from django.forms import (
TextInput, DateInput, FileInput, CheckboxInput, MultiWidget,
ClearableFileInput, Select, RadioSelect, CheckboxSelectMultiple
Expand All @@ -10,17 +10,16 @@
from django.forms.forms import BaseForm, BoundField
from django.forms.formsets import BaseFormSet
from django.utils.html import conditional_escape, escape, strip_tags
from django.template.loader import get_template
from django.utils.safestring import mark_safe

from .bootstrap import get_bootstrap_setting
from .text import text_value
from .exceptions import BootstrapError
from .utils import add_css_class, render_template_to_unicode
from .forms import (
render_form, render_field, render_label, render_form_group,
is_widget_with_placeholder, is_widget_required_attribute, FORM_GROUP_CLASS
)
from .text import text_value
from .utils import add_css_class, render_template_file


class BaseRenderer(object):
Expand Down Expand Up @@ -117,7 +116,7 @@ def get_formset_errors(self):
def render_errors(self):
formset_errors = self.get_formset_errors()
if formset_errors:
return render_template_to_unicode(
return render_template_file(
'bootstrap3/form_errors.html',
context={
'errors': formset_errors,
Expand Down Expand Up @@ -151,6 +150,9 @@ def __init__(self, form, *args, **kwargs):
# Handle form.empty_permitted
if self.form.empty_permitted:
self.set_required = False
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)

def render_fields(self):
rendered_fields = []
Expand All @@ -169,6 +171,9 @@ def render_fields(self):
size=self.size,
horizontal_label_class=self.horizontal_label_class,
horizontal_field_class=self.horizontal_field_class,
error_css_class=self.error_css_class,
required_css_class=self.required_css_class,
bound_css_class=self.bound_css_class,
))
return '\n'.join(rendered_fields)

Expand All @@ -189,7 +194,7 @@ def render_errors(self, type='all'):
form_errors = self.form.non_field_errors()

if form_errors:
return render_template_to_unicode(
return render_template_file(
'bootstrap3/form_errors.html',
context={
'errors': form_errors,
Expand All @@ -209,10 +214,17 @@ class FieldRenderer(BaseRenderer):
Default field renderer
"""

# These widgets will not be wrapped in a form-control class
WIDGETS_NO_FORM_CONTROL = (
CheckboxInput,
RadioSelect,
CheckboxSelectMultiple,
FileInput,
)

def __init__(self, field, *args, **kwargs):
if not isinstance(field, BoundField):
raise BootstrapError(
'Parameter "field" should contain a valid Django BoundField.')
raise BootstrapError('Parameter "field" should contain a valid Django BoundField.')
self.field = field
super(FieldRenderer, self).__init__(*args, **kwargs)

Expand All @@ -232,22 +244,22 @@ def __init__(self, field, *args, **kwargs):

# These are set in Django or in the global BOOTSTRAP3 settings, and
# they can be overwritten in the template
error_css_class = kwargs.get('error_css_class', '')
required_css_class = kwargs.get('required_css_class', '')
bound_css_class = kwargs.get('bound_css_class', '')
if error_css_class:
error_css_class = kwargs.get('error_css_class', None)
required_css_class = kwargs.get('required_css_class', None)
bound_css_class = kwargs.get('bound_css_class', None)
if error_css_class is not None:
self.error_css_class = error_css_class
else:
self.error_css_class = getattr(
field.form, 'error_css_class',
get_bootstrap_setting('error_css_class'))
if required_css_class:
if required_css_class is not None:
self.required_css_class = required_css_class
else:
self.required_css_class = getattr(
field.form, 'required_css_class',
get_bootstrap_setting('required_css_class'))
if bound_css_class:
if bound_css_class is not None:
self.success_css_class = bound_css_class
else:
self.success_css_class = getattr(
Expand All @@ -269,12 +281,9 @@ def add_class_attrs(self, widget=None):
widget = self.widget
classes = widget.attrs.get('class', '')
if isinstance(widget, ReadOnlyPasswordHashWidget):
classes = add_css_class(
classes, 'form-control-static', prepend=True)
elif not isinstance(widget, (CheckboxInput,
RadioSelect,
CheckboxSelectMultiple,
FileInput)):
# Render this is a static control
classes = add_css_class(classes, 'form-control-static', prepend=True)
elif not isinstance(widget, self.WIDGETS_NO_FORM_CONTROL):
classes = add_css_class(classes, 'form-control', prepend=True)
# For these widget types, add the size class here
classes = add_css_class(classes, self.get_size_class())
Expand Down Expand Up @@ -367,8 +376,9 @@ def fix_clearable_file_input(self, html):
"""
# TODO This needs improvement
return '<div class="row bootstrap3-multi-input">' + \
'<div class="col-xs-12">' + html + '</div></div>'
return '<div class="row bootstrap3-multi-input"><div class="col-xs-12">{html}</div></div>'.format(
html=html
)

def post_widget_render(self, html):
if isinstance(self.widget, RadioSelect):
Expand All @@ -393,21 +403,16 @@ def wrap_widget(self, html):
return html

def make_input_group(self, html):
if (
(self.addon_before or self.addon_after) and
isinstance(self.widget, (TextInput, DateInput, Select))
):
if (self.addon_before or self.addon_after) and isinstance(self.widget, (TextInput, DateInput, Select)):
before = '<span class="input-group-addon">{addon}</span>'.format(
addon=self.addon_before) if self.addon_before else ''
after = '<span class="input-group-addon">{addon}</span>'.format(
addon=self.addon_after) if self.addon_after else ''
html = \
'<div class="input-group">' + \
'{before}{html}{after}</div>'.format(
before=before,
after=after,
html=html
)
html = '<div class="input-group">{before}{html}{after}</div>'.format(
before=before,
after=after,
html=html
)
return html

def append_to_field(self, html):
Expand All @@ -416,7 +421,7 @@ def append_to_field(self, html):
help_text_and_errors.append(self.field_help)
help_text_and_errors += self.field_errors
if help_text_and_errors:
help_html = render_template_to_unicode(
help_html = render_template_file(
'bootstrap3/field_help_text_and_errors.html',
context={
'field': self.field,
Expand Down
5 changes: 3 additions & 2 deletions bootstrap3/templates/bootstrap3/messages.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load bootstrap3 %}
{% for message in messages %}
<div class="alert{% if message.tags %} alert-{% if message.tags == 'error' %}danger{% else %}{{ message.tags }}{% endif %}{% endif %} alert-dismissable">
<div class="{{ message|bootstrap_message_classes }} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&#215;</button>
{{ message|safe }}
{{ message }}
</div>
{% endfor %}

0 comments on commit 4d6be89

Please sign in to comment.