Skip to content

Commit

Permalink
Merge bd702c9 into 6e1e3de
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Sep 27, 2016
2 parents 6e1e3de + bd702c9 commit e44d91e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 31 deletions.
20 changes: 14 additions & 6 deletions .travis.yml
@@ -1,21 +1,29 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
cache: pip
sudo: false
env:
matrix:
- TOX_ENV=py27-dj17
- TOX_ENV=py27-dj18
- TOX_ENV=py34-dj17
- TOX_ENV=py34-dj18
- TOX_ENV=dj17
- TOX_ENV=dj18
- TOX_ENV=dj19
- TOX_ENV=dj110
- TOX_ENV=djdev
matrix:
exclude:
- python: "3.5"
env: TOX_ENV=dj17
allow_failures:
- env: TOX_ENV=djdev

install:
- pip install --upgrade pip
- pip install tox
- pip install coveralls
script:
- tox -e $TOX_ENV coverage
- tox -e py${TRAVIS_PYTHON_VERSION/./}-$TOX_ENV coverage
after_success:
- coveralls
after_script:
Expand Down
18 changes: 18 additions & 0 deletions betterforms/multiform.py
Expand Up @@ -67,6 +67,24 @@ def __str__(self):
def __getitem__(self, key):
return self.forms[key]

@property
def errors(self):
errors = {}
for form_name in self.forms:
form = self.forms[form_name]
for field_name in form.errors:
errors[form.add_prefix(field_name)] = form.errors[field_name]
return errors

@property
def fields(self):
fields = []
for form_name in self.forms:
form = self.forms[form_name]
for field_name in form.fields:
fields += [form.add_prefix(field_name)]
return fields

def __iter__(self):
# TODO: Should the order of the fields be controllable from here?
return chain.from_iterable(self.forms.values())
Expand Down
61 changes: 40 additions & 21 deletions betterforms/tests.py
Expand Up @@ -353,19 +353,21 @@ class TestForm(BetterForm):
test = """
<div class="required a formField">
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
</div>
<div class="b formField">
<label for="id_b">B</label>
<input id="id_b" name="b" type="text" />
</div>
<div class="required c formField">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</div>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
render_to_string('betterforms/form_as_fieldsets.html', env),
test,
Expand All @@ -374,7 +376,7 @@ class TestForm(BetterForm):
test = """
<div class="required error a formField">
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
<ul class="errorlist"><li>this is an error message</li></ul>
</div>
<div class="b formField">
Expand All @@ -383,11 +385,13 @@ class TestForm(BetterForm):
</div>
<div class="required c formField">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</div>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
render_to_string('betterforms/form_as_fieldsets.html', env),
test,
Expand All @@ -405,22 +409,24 @@ def test_include_tag_rendering(self):
<fieldset class="formFieldset first">
<div class="required a formField">
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
</div>
<div class="required b formField">
<label class="required" for="id_b">B</label>
<input id="id_b" name="b" type="text" />
<input id="id_b" name="b" required type="text" />
</div>
</fieldset>
<fieldset class="formFieldset second">
<div class="required c formField">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</div>
</fieldset>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
render_to_string('betterforms/form_as_fieldsets.html', env),
test,
Expand All @@ -430,23 +436,25 @@ def test_include_tag_rendering(self):
<fieldset class="formFieldset first">
<div class="required error a formField">
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
<ul class="errorlist"><li>this is an error message</li></ul>
</div>
<div class="required b formField">
<label class="required" for="id_b">B</label>
<input id="id_b" name="b" type="text" />
<input id="id_b" name="b" required type="text" />
</div>
</fieldset>
<fieldset class="formFieldset second">
<div class="required c formField">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</div>
</fieldset>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
render_to_string('betterforms/form_as_fieldsets.html', env),
test,
Expand All @@ -468,7 +476,7 @@ class TestForm(forms.Form):
test = """
<div class="a formField required">
<label for="id_a">A:</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
</div>
<div class="b formField">
<label for="id_b">B:</label>
Expand All @@ -477,6 +485,8 @@ class TestForm(forms.Form):
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
render_to_string('betterforms/form_as_fieldsets.html', env),
test,
Expand All @@ -503,22 +513,24 @@ def test_form_as_p(self):
<fieldset class="formFieldset first">
<p class="required">
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
</p>
<p class="required">
<label class="required" for="id_b">B</label>
<input id="id_b" name="b" type="text" />
<input id="id_b" name="b" required type="text" />
</p>
</fieldset>
<fieldset class="formFieldset second">
<p class="required">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</p>
</fieldset>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
form.as_p(),
test,
Expand All @@ -530,22 +542,25 @@ def test_form_as_p(self):
<p class="required error">
<ul class="errorlist"><li>this is an error</li></ul>
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
</p>
<p class="required">
<label class="required" for="id_b">B</label>
<input id="id_b" name="b" type="text" />
<input id="id_b" name="b" required type="text" />
</p>
</fieldset>
<fieldset class="formFieldset second">
<p class="required">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</p>
</fieldset>
"""
self.maxDiff=None
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
form.as_p(),
test,
Expand All @@ -571,23 +586,25 @@ class Meta:
<legend>First Fieldset</legend>
<p class="required">
<label class="required" for="id_a">A</label>
<input id="id_a" name="a" type="text" />
<input id="id_a" name="a" required type="text" />
</p>
<p class="required">
<label class="required" for="id_b">B</label>
<input id="id_b" name="b" type="text" />
<input id="id_b" name="b" required type="text" />
</p>
</fieldset>
<fieldset class="formFieldset second">
<legend>Second Fieldset</legend>
<p class="required">
<label class="required" for="id_c">C</label>
<input id="id_c" name="c" type="text" />
<input id="id_c" name="c" required type="text" />
</p>
</fieldset>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
form.as_p(),
test,
Expand All @@ -603,11 +620,13 @@ class TestForm(BetterForm):
test = """
<div class="required prefix-name name formField">
<label class="required" for="id_prefix-name">Name</label>
<input type="text" id="id_prefix-name" name="prefix-name" />
<input type="text" id="id_prefix-name" required name="prefix-name" />
</div>
"""
if django.VERSION < (1, 8):
test = test.replace('label class="required"', 'label')
if django.VERSION < (1, 10):
test = test.replace(' required ', ' ')
self.assertHTMLEqual(
render_to_string('betterforms/form_as_fieldsets.html', env),
test,
Expand Down
10 changes: 10 additions & 0 deletions tests/settings.py
Expand Up @@ -12,6 +12,16 @@
'django.middleware.csrf.CsrfViewMiddleware',
)

TEMPLATES = [
{
'DIRS': [
os.path.join(PROJECT_PATH, 'templates/'),
],
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
},
]

INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.contenttypes',
Expand Down
16 changes: 14 additions & 2 deletions tests/tests.py
@@ -1,5 +1,6 @@
from collections import OrderedDict

import django
from django.test import TestCase
from django.test.client import RequestFactory
from django.views.generic import CreateView
Expand Down Expand Up @@ -47,6 +48,14 @@ def test_as_table(self):
profile_table = form['profile'].as_table()
self.assertEqual(form.as_table(), user_table + profile_table)

def test_fields(self):
form = UserProfileMultiForm()
self.assertEqual(form.fields, ['user-name', 'profile-name', 'profile-display_name'])

def test_errors(self):
form = ErrorMultiForm()
self.assertEqual(form.errors, {})

def test_to_str_is_as_table(self):
form = UserProfileMultiForm()
self.assertEqual(force_text(form), form.as_table())
Expand Down Expand Up @@ -94,9 +103,12 @@ def test_is_multipart(self):

def test_media(self):
form = NeedsFileField()
static_prefix = ""
if django.VERSION < (1, 10):
static_prefix = "/static/"
self.assertEqual(form.media._js, [
'/static/admin/js/calendar.js',
'/static/admin/js/admin/DateTimeShortcuts.js',
static_prefix + 'admin/js/calendar.js',
static_prefix + 'admin/js/admin/DateTimeShortcuts.js',
'test.js',
])

Expand Down
8 changes: 6 additions & 2 deletions tox.ini
@@ -1,17 +1,21 @@
[tox]
envlist=
{py27,py34}-{dj17,dj18}
{py27,py34,py35}-{dj17,dj18,dj19,dj110,djdev}

[testenv]
commands=
make {posargs:test}
basepython=
py27: python2.7
py34: python3.4
py35: python3.5
deps=
dj17: Django>=1.7,<1.8
dj18: Django>=1.8,<1.9
dj18: django-formtools
dj19: Django>=1.9,<1.10
dj110: Django>=1.10,<1.11
djdev: https://github.com/django/django/archive/master.tar.gz
django-formtools
pytest
pytest-django
pytest-cov
Expand Down

0 comments on commit e44d91e

Please sign in to comment.