Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Jan 22, 2015
2 parents 9947dc7 + ec5dff5 commit 2abfff6
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 84 deletions.
5 changes: 3 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ History
-------


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

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


5.0.3 (2014-12-02)
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__ = '5.0.3'
__version__ = '5.1.0'
2 changes: 1 addition & 1 deletion bootstrap3/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Default settings
BOOTSTRAP3_DEFAULTS = {
'jquery_url': '//code.jquery.com/jquery.min.js',
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.1/',
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.2/',
'css_url': None,
'theme_url': None,
'javascript_url': None,
Expand Down
2 changes: 1 addition & 1 deletion bootstrap3/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from .text import text_concat, text_value
from .exceptions import BootstrapError
from .html import add_css_class, render_tag
from .utils import add_css_class, render_tag
from .components import render_icon


Expand Down
65 changes: 0 additions & 65 deletions bootstrap3/html.py

This file was deleted.

6 changes: 3 additions & 3 deletions bootstrap3/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .bootstrap import get_bootstrap_setting
from .text import text_value
from .exceptions import BootstrapError
from .html import add_css_class
from .utils import add_css_class
from .forms import (
render_form, render_field, render_label, render_form_group,
is_widget_with_placeholder, is_widget_required_attribute, FORM_GROUP_CLASS
Expand Down Expand Up @@ -209,8 +209,8 @@ def __init__(self, field, *args, **kwargs):
else:
self.placeholder = ''

self.addon_before = kwargs.get('addon_before', '')
self.addon_after = kwargs.get('addon_after', '')
self.addon_before = kwargs.get('addon_before', self.initial_attrs.pop('addon_before', ''))
self.addon_after = kwargs.get('addon_after', self.initial_attrs.pop('addon_after', ''))

# These are set in Django or in the global BOOTSTRAP3 settings, and
# they can be overwritten in the template
Expand Down
10 changes: 5 additions & 5 deletions bootstrap3/templates/bootstrap3/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
<ul class="{{ pagination_css_classes }}">

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

{% if pages_back %}
<li>
<a href="{{ bootstrap_pagination_url }}page={{ pages_back }}">&hellip;</a>
<a href="{{ bootstrap_pagination_url }}{{ parameter_name }}={{ pages_back }}">&hellip;</a>
</li>
{% endif %}

{% for p in pages_shown %}
<li{% if current_page == p %} class="active"{% endif %}>
<a href="{% if current_page == p %}#{% else %}{{ bootstrap_pagination_url }}page={{ p }}{% endif %}">{{ p }}</a>
<a href="{% if current_page == p %}#{% else %}{{ bootstrap_pagination_url }}{{ parameter_name }}={{ p }}{% endif %}">{{ p }}</a>
</li>
{% endfor %}

{% if pages_forward %}
<li>
<a href="{{ bootstrap_pagination_url }}page={{ pages_forward }}">&hellip;</a>
<a href="{{ bootstrap_pagination_url }}{{ parameter_name }}={{ pages_forward }}">&hellip;</a>
</li>
{% endif %}

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

</ul>
Expand Down
13 changes: 8 additions & 5 deletions bootstrap3/templatetags/bootstrap3.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..bootstrap import (
css_url, javascript_url, jquery_url, theme_url, get_bootstrap_setting
)
from ..html import render_link_tag
from ..utils import render_link_tag
from ..forms import (
render_button, render_field, render_field_and_label, render_form,
render_form_group, render_formset,
Expand Down Expand Up @@ -326,7 +326,7 @@ def bootstrap_field(*args, **kwargs):
**example**::
{% bootstrap_form form_field %}
{% bootstrap_field form_field %}
"""
return render_field(*args, **kwargs)

Expand Down Expand Up @@ -536,6 +536,7 @@ def bootstrap_pagination(page, **kwargs):
**Parameters**:
:page:
:parameter_name: Name of paging URL parameter (default: "page")
:kwargs:
**usage**::
Expand All @@ -553,7 +554,8 @@ def bootstrap_pagination(page, **kwargs):


def get_pagination_context(page, pages_to_show=11,
url=None, size=None, extra=None):
url=None, size=None, extra=None,
parameter_name='page'):
"""
Generate Bootstrap pagination context from a page object
"""
Expand Down Expand Up @@ -600,8 +602,8 @@ def get_pagination_context(page, pages_to_show=11,
if url:
# Remove existing page GET parameters
url = force_text(url)
url = re.sub(r'\?page\=[^\&]+', '?', url)
url = re.sub(r'\&page\=[^\&]+', '', url)
url = re.sub(r'\?{0}\=[^\&]+'.format(parameter_name), '?', url)
url = re.sub(r'\&{0}\=[^\&]+'.format(parameter_name), '', url)
# Append proper separator
if '?' in url:
url += '&'
Expand Down Expand Up @@ -631,4 +633,5 @@ def get_pagination_context(page, pages_to_show=11,
'pages_back': pages_back,
'pages_forward': pages_forward,
'pagination_css_classes': ' '.join(pagination_css_classes),
'parameter_name': parameter_name,
}
11 changes: 10 additions & 1 deletion bootstrap3/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .text import text_value, text_concat
from .exceptions import BootstrapError
from .html import add_css_class
from .utils import add_css_class


RADIO_CHOICES = (
Expand Down Expand Up @@ -73,6 +73,9 @@ class TestForm(forms.Form):
widget=forms.CheckboxSelectMultiple,
help_text='Check as many as you like.',
)
addon = forms.CharField(
widget=forms.TextInput(attrs={'addon_before': 'before', 'addon_after': 'after'}),
)

required_css_class = 'bootstrap3-req'

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

def test_field_addons(self):
form = TestForm()
res = render_form(form)
self.assertIn('<div class="input-group"><span class="input-group-addon">before</span><input', res)
self.assertIn('/><span class="input-group-addon">after</span></div>', res)

def test_exclude(self):
form = TestForm()
res = render_template(
Expand Down
65 changes: 65 additions & 0 deletions bootstrap3/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.forms.widgets import flatatt

from .text import text_value


# Handle HTML and CSS manipulation


def split_css_classes(css_classes):
"""
Turn string into a list of CSS classes
"""
classes_list = text_value(css_classes).split(' ')
return [c for c in classes_list if c]


def add_css_class(css_classes, css_class, prepend=False):
"""
Add a CSS class to a string of CSS classes
"""
classes_list = split_css_classes(css_classes)
classes_to_add = [c for c in split_css_classes(css_class)
if c not in classes_list]
if prepend:
classes_list = classes_to_add + classes_list
else:
classes_list += classes_to_add
return ' '.join(classes_list)


def remove_css_class(css_classes, css_class):
"""
Remove a CSS class from a string of CSS classes
"""
remove = set(split_css_classes(css_class))
classes_list = [c for c in split_css_classes(css_classes)
if c not in remove]
return ' '.join(classes_list)


def render_link_tag(url, rel='stylesheet', media='all'):
"""
Build a link tag
"""
return render_tag(
'link',
attrs={'href': url, 'rel': rel, 'media': media},
close=False)


def render_tag(tag, attrs=None, content=None, close=True):
"""
Render a HTML tag
"""
builder = '<{tag}{attrs}>{content}'
if content or close:
builder += '</{tag}>'
return builder.format(
tag=tag,
attrs=flatatt(attrs) if attrs else '',
content=text_value(content),
)
35 changes: 35 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Tox (http://codespeak.net/~hpk/tox/) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it, "pip install tox"
# and then run "tox" from this directory.

[tox]
minversion=1.8.0
envlist =
py26-django14,
py26-django15,

py27-django14,
py27-django15,
py27-django16,
py27-django17,

py32-django15,
py32-django16,
py32-django17,

py33-django15,
py33-django16,
py33-django17,

py34-django15,
py34-django16,
py34-django17,

[testenv]
commands = python manage.py test
deps =
django14: django >=1.4.2,<1.5
django15: django >=1.5,<1.6
django16: django >=1.6,<1.7
django17: django >=1.7,<1.8

0 comments on commit 2abfff6

Please sign in to comment.