Skip to content

Commit

Permalink
Merge branch 'release/6.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Jun 25, 2015
2 parents ae71661 + 892ec67 commit d61fe66
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 22 deletions.
13 changes: 13 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ History
-------


6.1.0 (2015-06-25)
++++++++++++++++++

* Upgrade to Bootstrap 3.3.5
* Properly quote help text (@joshkel)


6.0.0 (2015-04-21)
++++++++++++++++++

* No more media="screen" in CSS tags, complying to Bootstraps examples


5.4.0 (2015-04-21)
++++++++++++++++++

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.4.0'
__version__ = '6.1.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': '//netdna.bootstrapcdn.com/bootstrap/3.3.4/',
'base_url': '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/',
'css_url': None,
'theme_url': None,
'javascript_url': None,
Expand Down
6 changes: 3 additions & 3 deletions bootstrap3/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.forms.extras import SelectDateWidget
from django.forms.forms import BaseForm, BoundField
from django.forms.formsets import BaseFormSet
from django.utils.html import conditional_escape, strip_tags
from django.utils.html import conditional_escape, escape, strip_tags
from django.template import Context
from django.template.loader import get_template
from django.utils.safestring import mark_safe
Expand Down Expand Up @@ -273,7 +273,7 @@ def add_placeholder_attrs(self):
def add_help_attrs(self):
if not isinstance(self.widget, CheckboxInput):
self.widget.attrs['title'] = self.widget.attrs.get(
'title', strip_tags(self.field_help))
'title', escape(strip_tags(self.field_help)))

def add_required_attrs(self):
if self.set_required and is_widget_required_attribute(self.widget):
Expand Down Expand Up @@ -306,7 +306,7 @@ def put_inside_label(self, html):
content = '{field} {label}'.format(field=html, label=self.field.label)
return render_label(
content=content, label_for=self.field.id_for_label,
label_title=strip_tags(self.field_help))
label_title=escape(strip_tags(self.field_help)))

def fix_date_select_input(self, html):
div1 = '<div class="col-xs-4">'
Expand Down
57 changes: 47 additions & 10 deletions bootstrap3/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
from .exceptions import BootstrapError
from .utils import add_css_class

try:
from html.parser import HTMLParser
except ImportError:
from HTMLParser import HTMLParser


RADIO_CHOICES = (
('1', 'Radio 1'),
Expand Down Expand Up @@ -47,10 +52,15 @@ class TestForm(forms.Form):
)
password = forms.CharField(widget=forms.PasswordInput)
message = forms.CharField(required=False, help_text='<i>my_help_text</i>')
sender = forms.EmailField(label='Sender © unicode')
sender = forms.EmailField(
label='Sender © unicode',
help_text='E.g., "me@example.com"')
secret = forms.CharField(initial=42, widget=forms.HiddenInput)
cc_myself = forms.BooleanField(
required=False, help_text='You will get a copy in your mailbox.')
required=False,
help_text='cc stands for "carbon copy." '
'You will get a copy in your mailbox.'
)
select1 = forms.ChoiceField(choices=RADIO_CHOICES)
select2 = forms.MultipleChoiceField(
choices=RADIO_CHOICES,
Expand Down Expand Up @@ -136,21 +146,40 @@ def render_field(field, **context_args):
return render_template('{% bootstrap_field field %}', **context_args)


def get_title_from_html(html):
class GetTitleParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.title = None

def handle_starttag(self, tag, attrs):
for attr, value in attrs:
if attr == 'title':
self.title = value

parser = GetTitleParser()
parser.feed(html)

return parser.title


class SettingsTest(TestCase):
def test_settings(self):
from .bootstrap import BOOTSTRAP3
self.assertTrue(BOOTSTRAP3)

def test_bootstrap_javascript_tag(self):
res = render_template('{% bootstrap_javascript %}')
self.assertEqual(res.strip(), '<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>')

def test_bootstrap_css_tag(self):
res = render_template('{% bootstrap_css %}')
self.assertEqual(res.strip(), '<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">')

def test_settings_filter(self):
res = render_template(
'{% load bootstrap3 %}' +
'{{ "required_css_class"|bootstrap_setting }}')
res = render_template('{{ "required_css_class"|bootstrap_setting }}')
self.assertEqual(res.strip(), 'bootstrap3-req')
res = render_template(
'{% load bootstrap3 %}' +
'{% if "javascript_in_head"|bootstrap_setting %}' +
'head{% else %}body{% endif %}'
)
res = render_template('{% if "javascript_in_head"|bootstrap_setting %}head{% else %}body{% endif %}')
self.assertEqual(res.strip(), 'head')

def test_required_class(self):
Expand Down Expand Up @@ -263,6 +292,14 @@ def test_show_help(self):
res = render_template('{% bootstrap_field form.subject show_help=0 %}')
self.assertNotIn('my_help_text', res)

def test_help_with_quotes(self):
# Checkboxes get special handling, so test a checkbox and something else
res = render_form_field('sender')
self.assertEqual(get_title_from_html(res), TestForm.base_fields['sender'].help_text)

res = render_form_field('cc_myself')
self.assertEqual(get_title_from_html(res), TestForm.base_fields['cc_myself'].help_text)

def test_subject(self):
res = render_form_field('subject')
self.assertIn('type="text"', res)
Expand Down
14 changes: 8 additions & 6 deletions bootstrap3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.template import Variable, VariableDoesNotExist
from django.template.base import FilterExpression, kwarg_re, TemplateSyntaxError


from .text import text_value


Expand Down Expand Up @@ -97,14 +96,17 @@ def remove_css_class(css_classes, css_class):
return ' '.join(classes_list)


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


def render_tag(tag, attrs=None, content=None, close=True):
Expand Down
2 changes: 1 addition & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The ``BOOTSTRAP3`` dict variable contains these settings and defaults:
'jquery_url': '//code.jquery.com/jquery.min.js',
# The Bootstrap base URL
'base_url': '//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/',
'base_url': '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/',
# The complete URL to the Bootstrap CSS file (None means derive it from base_url)
'css_url': None,
Expand Down

0 comments on commit d61fe66

Please sign in to comment.