This commit is contained in:
tzangms 2016-03-21 02:15:52 +08:00
parent 9755e29923
commit 3ad9e7fb18
9 changed files with 461 additions and 11 deletions

3
.gitignore vendored
View File

@ -5,3 +5,6 @@
docs/_build docs/_build
/build /build
/dist /dist
.cache
.tox
.python-version

View File

@ -1,15 +1,26 @@
language: python language: python
env:
matrix:
- TOX_ENV=py27-dj15
- TOX_ENV=py27-dj16
- TOX_ENV=py27-dj17
- TOX_ENV=py27-dj18
- TOX_ENV=py34-dj15
- TOX_ENV=py34-dj16
- TOX_ENV=py34-dj17
- TOX_ENV=py34-dj18
python: python:
- "2.7" - "2.7"
- "3.4" - "3.4"
- "3.5"
install: install:
- pip install coverage coveralls - pip install tox coverage coveralls
script: script:
- coverage run --source=bootstrapform setup.py test #- coverage run --source=bootstrapform setup.py test
- tox -e $TOX_ENV
after_success: after_success:
- coveralls - coveralls

View File

@ -0,0 +1,99 @@
<div class="form-group">
<label class="control-label " for="id_char_field">Char field</label>
<div class=" ">
<input class=" form-control" id="id_char_field" name="char_field" type="text" />
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_choice_field">Choice field</label>
<div class=" ">
<select class=" form-control" id="id_choice_field" name="choice_field">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label ">Radio choice</label>
<div class="">
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="0" />
Zero
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="1" />
One
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="2" />
Two
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_multiple_choice">Multiple choice</label>
<div class=" ">
<select multiple="multiple" class=" form-control" id="id_multiple_choice" name="multiple_choice">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_multiple_checkbox">Multiple checkbox</label>
<div class=" multiple-checkbox">
<ul id="id_multiple_checkbox">
<li><label for="id_multiple_checkbox_0"><input id="id_multiple_checkbox_0" name="multiple_checkbox" type="checkbox" value="0" /> Zero</label></li>
<li><label for="id_multiple_checkbox_1"><input id="id_multiple_checkbox_1" name="multiple_checkbox" type="checkbox" value="1" /> One</label></li>
<li><label for="id_multiple_checkbox_2"><input id="id_multiple_checkbox_2" name="multiple_checkbox" type="checkbox" value="2" /> Two</label></li>
</ul>
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_file_fied">File fied</label>
<div class=" ">
<input id="id_file_fied" name="file_fied" type="file" />
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_password_field">Password field</label>
<div class=" ">
<input class=" form-control" id="id_password_field" name="password_field" type="password" />
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_textarea">Textarea</label>
<div class=" ">
<textarea class=" form-control" cols="40" id="id_textarea" name="textarea" rows="10">
</textarea>
</div>
</div>
<div class="form-group">
<div class="">
<div class="checkbox">
<label >
<input id="id_boolean_field" name="boolean_field" type="checkbox" /> <span>Boolean field</span>
</label>
</div>
</div>
</div>

View File

@ -0,0 +1,99 @@
<div class="form-group">
<label class="control-label " for="id_char_field">Char field</label>
<div class=" ">
<input class=" form-control" id="id_char_field" name="char_field" type="text" />
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_choice_field">Choice field</label>
<div class=" ">
<select class=" form-control" id="id_choice_field" name="choice_field">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label ">Radio choice</label>
<div class="">
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="0" />
Zero
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="1" />
One
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="2" />
Two
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_multiple_choice">Multiple choice</label>
<div class=" ">
<select multiple="multiple" class=" form-control" id="id_multiple_choice" name="multiple_choice">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_multiple_checkbox">Multiple checkbox</label>
<div class=" multiple-checkbox">
<ul>
<li><label for="id_multiple_checkbox_0"><input id="id_multiple_checkbox_0" name="multiple_checkbox" type="checkbox" value="0" /> Zero</label></li>
<li><label for="id_multiple_checkbox_1"><input id="id_multiple_checkbox_1" name="multiple_checkbox" type="checkbox" value="1" /> One</label></li>
<li><label for="id_multiple_checkbox_2"><input id="id_multiple_checkbox_2" name="multiple_checkbox" type="checkbox" value="2" /> Two</label></li>
</ul>
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_file_fied">File fied</label>
<div class=" ">
<input id="id_file_fied" name="file_fied" type="file" />
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_password_field">Password field</label>
<div class=" ">
<input class=" form-control" id="id_password_field" name="password_field" type="password" />
</div>
</div>
<div class="form-group">
<label class="control-label " for="id_textarea">Textarea</label>
<div class=" ">
<textarea class=" form-control" cols="40" id="id_textarea" name="textarea" rows="10">
</textarea>
</div>
</div>
<div class="form-group">
<div class="">
<div class="checkbox">
<label >
<input id="id_boolean_field" name="boolean_field" type="checkbox" /> <span>Boolean field</span>
</label>
</div>
</div>
</div>

View File

@ -0,0 +1,102 @@
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_char_field">Char field</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_char_field" name="char_field" type="text" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_choice_field">Choice field</label>
<div class=" col-sm-10 col-lg-10 ">
<select class=" form-control" id="id_choice_field" name="choice_field">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 ">Radio choice</label>
<div class=" col-sm-10 col-lg-10">
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="0" />
Zero
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="1" />
One
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="2" />
Two
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_multiple_choice">Multiple choice</label>
<div class=" col-sm-10 col-lg-10 ">
<select multiple="multiple" class=" form-control" id="id_multiple_choice" name="multiple_choice">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_multiple_checkbox">Multiple checkbox</label>
<div class=" col-sm-10 col-lg-10 multiple-checkbox">
<ul id="id_multiple_checkbox">
<li><label for="id_multiple_checkbox_0"><input id="id_multiple_checkbox_0" name="multiple_checkbox" type="checkbox" value="0" /> Zero</label></li>
<li><label for="id_multiple_checkbox_1"><input id="id_multiple_checkbox_1" name="multiple_checkbox" type="checkbox" value="1" /> One</label></li>
<li><label for="id_multiple_checkbox_2"><input id="id_multiple_checkbox_2" name="multiple_checkbox" type="checkbox" value="2" /> Two</label></li>
</ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_file_fied">File fied</label>
<div class=" col-sm-10 col-lg-10 ">
<input id="id_file_fied" name="file_fied" type="file" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_password_field">Password field</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_password_field" name="password_field" type="password" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_textarea">Textarea</label>
<div class=" col-sm-10 col-lg-10 ">
<textarea class=" form-control" cols="40" id="id_textarea" name="textarea" rows="10">
</textarea>
</div>
</div>
<div class="form-group">
<div class=" col-sm-offset-2 col-sm-10 col-lg-offset-2 col-lg-10">
<div class="checkbox">
<label >
<input id="id_boolean_field" name="boolean_field" type="checkbox" /> <span>Boolean field</span>
</label>
</div>
</div>
</div>

View File

@ -0,0 +1,102 @@
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_char_field">Char field</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_char_field" name="char_field" type="text" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_choice_field">Choice field</label>
<div class=" col-sm-10 col-lg-10 ">
<select class=" form-control" id="id_choice_field" name="choice_field">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 ">Radio choice</label>
<div class=" col-sm-10 col-lg-10">
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="0" />
Zero
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="1" />
One
</label>
</div>
<div class="radio">
<label>
<input name="radio_choice" type="radio" value="2" />
Two
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_multiple_choice">Multiple choice</label>
<div class=" col-sm-10 col-lg-10 ">
<select multiple="multiple" class=" form-control" id="id_multiple_choice" name="multiple_choice">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_multiple_checkbox">Multiple checkbox</label>
<div class=" col-sm-10 col-lg-10 multiple-checkbox">
<ul>
<li><label for="id_multiple_checkbox_0"><input id="id_multiple_checkbox_0" name="multiple_checkbox" type="checkbox" value="0" /> Zero</label></li>
<li><label for="id_multiple_checkbox_1"><input id="id_multiple_checkbox_1" name="multiple_checkbox" type="checkbox" value="1" /> One</label></li>
<li><label for="id_multiple_checkbox_2"><input id="id_multiple_checkbox_2" name="multiple_checkbox" type="checkbox" value="2" /> Two</label></li>
</ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_file_fied">File fied</label>
<div class=" col-sm-10 col-lg-10 ">
<input id="id_file_fied" name="file_fied" type="file" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_password_field">Password field</label>
<div class=" col-sm-10 col-lg-10 ">
<input class=" form-control" id="id_password_field" name="password_field" type="password" />
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2 col-lg-2 " for="id_textarea">Textarea</label>
<div class=" col-sm-10 col-lg-10 ">
<textarea class=" form-control" cols="40" id="id_textarea" name="textarea" rows="10">
</textarea>
</div>
</div>
<div class="form-group">
<div class=" col-sm-offset-2 col-sm-10 col-lg-offset-2 col-lg-10">
<div class="checkbox">
<label >
<input id="id_boolean_field" name="boolean_field" type="checkbox" /> <span>Boolean field</span>
</label>
</div>
</div>
</div>

View File

@ -1,9 +1,9 @@
import os import os
from distutils.version import StrictVersion
import django import django
from django.test import TestCase from django.test import TestCase
from django.template import Template, Context from django.template import Template, Context
from django.core.management import call_command
from django import forms from django import forms
@ -37,15 +37,20 @@ class ExampleForm(forms.Form):
class BootstrapTemplateTagTests(TestCase): class BootstrapTemplateTagTests(TestCase):
maxDiff = None maxDiff = None
def setUp(self):
call_command('migrate', interactive=False)
def test_basic_form(self): def test_basic_form(self):
form = ExampleForm() form = ExampleForm()
html = Template("{% load bootstrap %}{{ form|bootstrap }}").render(Context({'form': form})) html = Template("{% load bootstrap %}{{ form|bootstrap }}").render(Context({'form': form}))
tpl = os.path.join('fixtures', 'basic.html')
if StrictVersion(django.get_version()) >= StrictVersion('1.7'):
fixture = 'basic.html'
elif StrictVersion(django.get_version()) >= StrictVersion('1.6'):
fixture = 'basic_dj16.html'
else:
fixture = 'basic_old.html'
tpl = os.path.join('fixtures', fixture)
with open(os.path.join(TEST_DIR, tpl)) as f: with open(os.path.join(TEST_DIR, tpl)) as f:
content = f.read() content = f.read()
@ -56,7 +61,14 @@ class BootstrapTemplateTagTests(TestCase):
html = Template("{% load bootstrap %}{{ form|bootstrap_horizontal }}").render(Context({'form': form})) html = Template("{% load bootstrap %}{{ form|bootstrap_horizontal }}").render(Context({'form': form}))
tpl = os.path.join('fixtures', 'horizontal.html') if StrictVersion(django.get_version()) >= StrictVersion('1.7'):
fixture = 'horizontal.html'
elif StrictVersion(django.get_version()) >= StrictVersion('1.6'):
fixture = 'horizontal_dj16.html'
else:
fixture = 'horizontal_old.html'
tpl = os.path.join('fixtures', fixture)
with open(os.path.join(TEST_DIR, tpl)) as f: with open(os.path.join(TEST_DIR, tpl)) as f:
content = f.read() content = f.read()

View File

@ -20,10 +20,10 @@ setup(
author='tzangms', author='tzangms',
author_email='tzangms@gmail.com', author_email='tzangms@gmail.com',
url='http://github.com/tzangms/django-bootstrap-form', url='http://github.com/tzangms/django-bootstrap-form',
license='BSD', license='MIT',
test_suite='runtests.runtests', test_suite='runtests.runtests',
install_requires = [ install_requires = [
"django>=1.3", "django>=1.5",
], ],
packages=find_packages(), packages=find_packages(),
include_package_data=True, include_package_data=True,

22
tox.ini Normal file
View File

@ -0,0 +1,22 @@
[tox]
envlist = {py27,py34}-django{15,16,17,18}
skipsdist=True
[testenv]
basepython =
py27: python2.7
py34: python3.4
deps =
pytest
django15: Django>=1.5,<1.6
django16: Django>=1.6,<1.7
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
commands = python setup.py test
[testenv:py27-cov]
deps =
django18: Django>=1.8,<1.9
command = coverage run --source=bootstrapform setup.py test