Skip to content

Commit

Permalink
Merge branch 'release/5.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Mar 25, 2015
2 parents 2494cf3 + 75860da commit afa9d65
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 67 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Authors
=======

This application is developed and maintained by `Zostera <https://zostera.nl>`_.

Development Lead
----------------

Expand Down
14 changes: 14 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ History
-------


5.2.0 (2015-03-20)
++++++++++++++++++

* Various bug fixes and improvements


5.2.0 (2015-03-25)
++++++++++++++++++

* Upgrade to Bootstrap 3.3.4
* Fix required bug for checkboxes
* Various bug fixes


5.1.1 (2015-01-22)
++++++++++++++++++

Expand Down
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,10 @@ You can use this under Apache 2.0. See `LICENSE
Author
------

My name is Dylan Verheul, you can reach me at dylan@dyve.net or follow me on Twitter (http://twitter.com/dyve). If you like this project, you can `support me on GitTip <https://www.gittip.com/dyve/>`_.
Developed and maintained by `Zostera <https://zostera.nl/>`_.

Original author & Development lead: `Dylan Verheul <https://github.com/dyve>`_.

Thanks to everybody that has contributed pull requests, ideas, issues, comments and kind words.

Please see AUTHORS.rst for a list of contributors.
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.1.1'
__version__ = '5.2.0'
7 changes: 5 additions & 2 deletions bootstrap3/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from __future__ import unicode_literals

from django.conf import settings
from django.utils.importlib import import_module
try:
from django.utils.importlib import import_module
except ImportError:
from importlib import import_module


# Default settings
BOOTSTRAP3_DEFAULTS = {
'jquery_url': '//code.jquery.com/jquery.min.js',
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.2/',
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.4/',
'css_url': None,
'theme_url': None,
'javascript_url': None,
Expand Down
14 changes: 10 additions & 4 deletions bootstrap3/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from django.contrib.admin.widgets import AdminFileWidget
from django.forms import (
HiddenInput, FileInput, CheckboxSelectMultiple, Textarea, TextInput
HiddenInput, FileInput, CheckboxSelectMultiple, Textarea, TextInput,
PasswordInput
)
from django.forms.widgets import CheckboxInput

from .bootstrap import (
get_bootstrap_setting, get_form_renderer, get_field_renderer,
Expand Down Expand Up @@ -75,7 +77,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=''):
href='', name=None):
"""
Render a button with content
"""
Expand Down Expand Up @@ -109,6 +111,8 @@ def render_button(
tag = 'a'
else:
tag = 'button'
if name:
attrs['name'] = name
return render_tag(
tag, attrs=attrs, content=text_concat(
icon_content, content, separator=' '))
Expand Down Expand Up @@ -159,7 +163,7 @@ def is_widget_required_attribute(widget):
if isinstance(
widget, (
AdminFileWidget, HiddenInput, FileInput,
CheckboxSelectMultiple)):
CheckboxInput, CheckboxSelectMultiple)):
return False
return True

Expand All @@ -170,4 +174,6 @@ def is_widget_with_placeholder(widget):
Only text, search, url, tel, e-mail, password, number have placeholders
These are all derived form TextInput, except for Textarea
"""
return isinstance(widget, (TextInput, Textarea))
# PasswordInput inherits from Input in Django 1.4.
# It was changed to inherit from TextInput in 1.5.
return isinstance(widget, (TextInput, Textarea, PasswordInput))
2 changes: 2 additions & 0 deletions bootstrap3/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def render_forms(self):
form_group_class=self.form_group_class,
field_class=self.field_class,
label_class=self.label_class,
show_label=self.show_label,
show_help=self.show_help,
exclude=self.exclude,
set_required=self.set_required,
Expand Down Expand Up @@ -144,6 +145,7 @@ def render_fields(self):
form_group_class=self.form_group_class,
field_class=self.field_class,
label_class=self.label_class,
show_label=self.show_label,
show_help=self.show_help,
exclude=self.exclude,
set_required=self.set_required,
Expand Down
56 changes: 0 additions & 56 deletions bootstrap3/templates.py

This file was deleted.

2 changes: 1 addition & 1 deletion bootstrap3/templatetags/bootstrap3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
render_label, render_form_errors, render_formset_errors
)
from ..components import render_icon, render_alert
from ..templates import handle_var, parse_token_contents
from ..utils import handle_var, parse_token_contents
from ..text import force_text


Expand Down
26 changes: 26 additions & 0 deletions bootstrap3/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.test import TestCase

from django import forms
from django.forms.formsets import formset_factory
from django.template import Template, Context

from .text import text_value, text_concat
Expand Down Expand Up @@ -44,6 +45,7 @@ class TestForm(forms.Form):
required=True,
widget=forms.TextInput(attrs={'placeholder': 'placeholdertest'}),
)
password = forms.CharField(widget=forms.PasswordInput)
message = forms.CharField(required=False, help_text='<i>my_help_text</i>')
sender = forms.EmailField(label='Sender © unicode')
secret = forms.CharField(initial=42, widget=forms.HiddenInput)
Expand Down Expand Up @@ -266,6 +268,11 @@ def test_subject(self):
self.assertIn('type="text"', res)
self.assertIn('placeholder="placeholdertest"', res)

def test_password(self):
res = render_form_field('password')
self.assertIn('type="password"', res)
self.assertIn('placeholder="Password"', res)

def test_required_field(self):
required_field = render_form_field('subject')
self.assertIn('required', required_field)
Expand Down Expand Up @@ -445,3 +452,22 @@ def test_button(self):
res.strip(),
'<a class="btn btn-lg" href="#">button</a><a href="#" ' +
'class="btn btn-lg">button</a>')


class ShowLabelTest(TestCase):
def test_show_label(self):
form = TestForm()
res = render_template(
'{% bootstrap_form form show_label=False %}',
form=form
)
self.assertIn('sr-only', res)

def test_for_formset(self):
TestFormSet = formset_factory(TestForm, extra=1)
test_formset = TestFormSet()
res = render_template(
'{% bootstrap_formset formset show_label=False %}',
formset=test_formset
)
self.assertIn('sr-only', res)
58 changes: 57 additions & 1 deletion bootstrap3/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re

from django.forms.widgets import flatatt
from django.template import Variable, VariableDoesNotExist
from django.template.base import FilterExpression, kwarg_re, TemplateSyntaxError


from .text import text_value


# Handle HTML and CSS manipulation
# RegEx for quoted string
QUOTED_STRING = re.compile(r'^["\'](?P<noquotes>.+)["\']$')


def handle_var(value, context):
"""
Handle template tag variable
"""
# Resolve FilterExpression and Variable immediately
if isinstance(value, FilterExpression) or isinstance(value, Variable):
return value.resolve(context)
# Return quoted strings unquoted
# http://djangosnippets.org/snippets/886
stringval = QUOTED_STRING.search(value)
if stringval:
return stringval.group('noquotes')
# Resolve variable or return string value
try:
return Variable(value).resolve(context)
except VariableDoesNotExist:
return value


def parse_token_contents(parser, token):
"""
Parse template tag contents
"""
bits = token.split_contents()
tag = bits.pop(0)
args = []
kwargs = {}
asvar = None
if len(bits) >= 2 and bits[-2] == 'as':
asvar = bits[-1]
bits = bits[:-2]
if len(bits):
for bit in bits:
match = kwarg_re.match(bit)
if not match:
raise TemplateSyntaxError(
'Malformed arguments to tag "{}"'.format(tag))
name, value = match.groups()
if name:
kwargs[name] = parser.compile_filter(value)
else:
args.append(parser.compile_filter(value))
return {
'tag': tag,
'args': args,
'kwargs': kwargs,
'asvar': asvar,
}


def split_css_classes(css_classes):
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 is contains these settings and defaults:
'jquery_url': '//code.jquery.com/jquery.min.js',
# The Bootstrap base URL
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.1/',
'base_url': '//netdna.bootstrapcdn.com/bootstrap/3.3.4/',
# The complete URL to the Bootstrap CSS file (None means derive it from base_url)
'css_url': None,
Expand Down

0 comments on commit afa9d65

Please sign in to comment.