Skip to content

Commit 2abfff6

Browse files
committed
Merge branch 'release/5.1.0'
2 parents 9947dc7 + ec5dff5 commit 2abfff6

File tree

11 files changed

+132
-84
lines changed

11 files changed

+132
-84
lines changed

HISTORY.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ History
44
-------
55

66

7-
5.0.2 (2014-11-24)
7+
5.1.0 (2015-01-22)
88
++++++++++++++++++
99

10-
* Cleaning up some mess in 5.0.1 created by PyPI malfunction
10+
* Make Bootstrap 3.3.2 default
11+
* Fix issue #140 (bad behaviour in Python 3)
1112

1213

1314
5.0.3 (2014-12-02)

bootstrap3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '5.0.3'
3+
__version__ = '5.1.0'

bootstrap3/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Default settings
99
BOOTSTRAP3_DEFAULTS = {
1010
'jquery_url': '//code.jquery.com/jquery.min.js',
11-
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.1/',
11+
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.2/',
1212
'css_url': None,
1313
'theme_url': None,
1414
'javascript_url': None,

bootstrap3/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)
1313
from .text import text_concat, text_value
1414
from .exceptions import BootstrapError
15-
from .html import add_css_class, render_tag
15+
from .utils import add_css_class, render_tag
1616
from .components import render_icon
1717

1818

bootstrap3/html.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

bootstrap3/renderers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .bootstrap import get_bootstrap_setting
1818
from .text import text_value
1919
from .exceptions import BootstrapError
20-
from .html import add_css_class
20+
from .utils import add_css_class
2121
from .forms import (
2222
render_form, render_field, render_label, render_form_group,
2323
is_widget_with_placeholder, is_widget_required_attribute, FORM_GROUP_CLASS
@@ -209,8 +209,8 @@ def __init__(self, field, *args, **kwargs):
209209
else:
210210
self.placeholder = ''
211211

212-
self.addon_before = kwargs.get('addon_before', '')
213-
self.addon_after = kwargs.get('addon_after', '')
212+
self.addon_before = kwargs.get('addon_before', self.initial_attrs.pop('addon_before', ''))
213+
self.addon_after = kwargs.get('addon_after', self.initial_attrs.pop('addon_after', ''))
214214

215215
# These are set in Django or in the global BOOTSTRAP3 settings, and
216216
# they can be overwritten in the template

bootstrap3/templates/bootstrap3/pagination.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
<ul class="{{ pagination_css_classes }}">
44

55
<li class="prev{% if current_page == 1 %} disabled{% endif %}">
6-
<a href="{% if current_page == 1 %}#{% else %}{{ bootstrap_pagination_url }}page=1{% endif %}">&laquo;</a>
6+
<a href="{% if current_page == 1 %}#{% else %}{{ bootstrap_pagination_url }}{{ parameter_name }}=1{% endif %}">&laquo;</a>
77
</li>
88

99
{% if pages_back %}
1010
<li>
11-
<a href="{{ bootstrap_pagination_url }}page={{ pages_back }}">&hellip;</a>
11+
<a href="{{ bootstrap_pagination_url }}{{ parameter_name }}={{ pages_back }}">&hellip;</a>
1212
</li>
1313
{% endif %}
1414

1515
{% for p in pages_shown %}
1616
<li{% if current_page == p %} class="active"{% endif %}>
17-
<a href="{% if current_page == p %}#{% else %}{{ bootstrap_pagination_url }}page={{ p }}{% endif %}">{{ p }}</a>
17+
<a href="{% if current_page == p %}#{% else %}{{ bootstrap_pagination_url }}{{ parameter_name }}={{ p }}{% endif %}">{{ p }}</a>
1818
</li>
1919
{% endfor %}
2020

2121
{% if pages_forward %}
2222
<li>
23-
<a href="{{ bootstrap_pagination_url }}page={{ pages_forward }}">&hellip;</a>
23+
<a href="{{ bootstrap_pagination_url }}{{ parameter_name }}={{ pages_forward }}">&hellip;</a>
2424
</li>
2525
{% endif %}
2626

2727
<li class="last{% if current_page == num_pages %} disabled{% endif %}">
28-
<a href="{% if current_page == num_pages %}#{% else %}{{ bootstrap_pagination_url }}page={{ num_pages }}{% endif %}">&raquo;</a>
28+
<a href="{% if current_page == num_pages %}#{% else %}{{ bootstrap_pagination_url }}{{ parameter_name }}={{ num_pages }}{% endif %}">&raquo;</a>
2929
</li>
3030

3131
</ul>

bootstrap3/templatetags/bootstrap3.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ..bootstrap import (
1212
css_url, javascript_url, jquery_url, theme_url, get_bootstrap_setting
1313
)
14-
from ..html import render_link_tag
14+
from ..utils import render_link_tag
1515
from ..forms import (
1616
render_button, render_field, render_field_and_label, render_form,
1717
render_form_group, render_formset,
@@ -326,7 +326,7 @@ def bootstrap_field(*args, **kwargs):
326326
327327
**example**::
328328
329-
{% bootstrap_form form_field %}
329+
{% bootstrap_field form_field %}
330330
"""
331331
return render_field(*args, **kwargs)
332332

@@ -536,6 +536,7 @@ def bootstrap_pagination(page, **kwargs):
536536
**Parameters**:
537537
538538
:page:
539+
:parameter_name: Name of paging URL parameter (default: "page")
539540
:kwargs:
540541
541542
**usage**::
@@ -553,7 +554,8 @@ def bootstrap_pagination(page, **kwargs):
553554

554555

555556
def get_pagination_context(page, pages_to_show=11,
556-
url=None, size=None, extra=None):
557+
url=None, size=None, extra=None,
558+
parameter_name='page'):
557559
"""
558560
Generate Bootstrap pagination context from a page object
559561
"""
@@ -600,8 +602,8 @@ def get_pagination_context(page, pages_to_show=11,
600602
if url:
601603
# Remove existing page GET parameters
602604
url = force_text(url)
603-
url = re.sub(r'\?page\=[^\&]+', '?', url)
604-
url = re.sub(r'\&page\=[^\&]+', '', url)
605+
url = re.sub(r'\?{0}\=[^\&]+'.format(parameter_name), '?', url)
606+
url = re.sub(r'\&{0}\=[^\&]+'.format(parameter_name), '', url)
605607
# Append proper separator
606608
if '?' in url:
607609
url += '&'
@@ -631,4 +633,5 @@ def get_pagination_context(page, pages_to_show=11,
631633
'pages_back': pages_back,
632634
'pages_forward': pages_forward,
633635
'pagination_css_classes': ' '.join(pagination_css_classes),
636+
'parameter_name': parameter_name,
634637
}

bootstrap3/tests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .text import text_value, text_concat
1212
from .exceptions import BootstrapError
13-
from .html import add_css_class
13+
from .utils import add_css_class
1414

1515

1616
RADIO_CHOICES = (
@@ -73,6 +73,9 @@ class TestForm(forms.Form):
7373
widget=forms.CheckboxSelectMultiple,
7474
help_text='Check as many as you like.',
7575
)
76+
addon = forms.CharField(
77+
widget=forms.TextInput(attrs={'addon_before': 'before', 'addon_after': 'after'}),
78+
)
7679

7780
required_css_class = 'bootstrap3-req'
7881

@@ -211,6 +214,12 @@ def test_field_names(self):
211214
for field in form:
212215
self.assertIn('name="%s"' % field.name, res)
213216

217+
def test_field_addons(self):
218+
form = TestForm()
219+
res = render_form(form)
220+
self.assertIn('<div class="input-group"><span class="input-group-addon">before</span><input', res)
221+
self.assertIn('/><span class="input-group-addon">after</span></div>', res)
222+
214223
def test_exclude(self):
215224
form = TestForm()
216225
res = render_template(

bootstrap3/utils.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.forms.widgets import flatatt
5+
6+
from .text import text_value
7+
8+
9+
# Handle HTML and CSS manipulation
10+
11+
12+
def split_css_classes(css_classes):
13+
"""
14+
Turn string into a list of CSS classes
15+
"""
16+
classes_list = text_value(css_classes).split(' ')
17+
return [c for c in classes_list if c]
18+
19+
20+
def add_css_class(css_classes, css_class, prepend=False):
21+
"""
22+
Add a CSS class to a string of CSS classes
23+
"""
24+
classes_list = split_css_classes(css_classes)
25+
classes_to_add = [c for c in split_css_classes(css_class)
26+
if c not in classes_list]
27+
if prepend:
28+
classes_list = classes_to_add + classes_list
29+
else:
30+
classes_list += classes_to_add
31+
return ' '.join(classes_list)
32+
33+
34+
def remove_css_class(css_classes, css_class):
35+
"""
36+
Remove a CSS class from a string of CSS classes
37+
"""
38+
remove = set(split_css_classes(css_class))
39+
classes_list = [c for c in split_css_classes(css_classes)
40+
if c not in remove]
41+
return ' '.join(classes_list)
42+
43+
44+
def render_link_tag(url, rel='stylesheet', media='all'):
45+
"""
46+
Build a link tag
47+
"""
48+
return render_tag(
49+
'link',
50+
attrs={'href': url, 'rel': rel, 'media': media},
51+
close=False)
52+
53+
54+
def render_tag(tag, attrs=None, content=None, close=True):
55+
"""
56+
Render a HTML tag
57+
"""
58+
builder = '<{tag}{attrs}>{content}'
59+
if content or close:
60+
builder += '</{tag}>'
61+
return builder.format(
62+
tag=tag,
63+
attrs=flatatt(attrs) if attrs else '',
64+
content=text_value(content),
65+
)

tox.ini

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Tox (http://codespeak.net/~hpk/tox/) is a tool for running tests
2+
# in multiple virtualenvs. This configuration file will run the
3+
# test suite on all supported python versions. To use it, "pip install tox"
4+
# and then run "tox" from this directory.
5+
6+
[tox]
7+
minversion=1.8.0
8+
envlist =
9+
py26-django14,
10+
py26-django15,
11+
12+
py27-django14,
13+
py27-django15,
14+
py27-django16,
15+
py27-django17,
16+
17+
py32-django15,
18+
py32-django16,
19+
py32-django17,
20+
21+
py33-django15,
22+
py33-django16,
23+
py33-django17,
24+
25+
py34-django15,
26+
py34-django16,
27+
py34-django17,
28+
29+
[testenv]
30+
commands = python manage.py test
31+
deps =
32+
django14: django >=1.4.2,<1.5
33+
django15: django >=1.5,<1.6
34+
django16: django >=1.6,<1.7
35+
django17: django >=1.7,<1.8

0 commit comments

Comments
 (0)