Skip to content

Commit 83ec96f

Browse files
committed
Back-merge branch 'master' into wtforms2
2 parents 7f8c240 + 5fa9d77 commit 83ec96f

10 files changed

Lines changed: 81 additions & 14 deletions

File tree

.travis.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
language: python
22
python:
3-
- "2.6"
4-
- "2.7"
5-
- "3.2"
6-
- "3.3"
7-
- "pypy"
3+
- 2.6
4+
- 2.7
5+
- 3.3
6+
- pypy
7+
env:
8+
global:
9+
- DATEUTIL=python-dateutil==2.1
10+
- LOCALFLAVOR=
11+
matrix:
12+
- DJANGO=Django==1.3.7
13+
- DJANGO=Django==1.4.8
14+
- DJANGO=Django==1.5.4 DATEUTIL=python-dateutil==2.2
15+
- DJANGO=Django==1.5.4 LOCALFLAVOR=django-localflavor
16+
- DJANGO=https://github.com/django/django/tarball/stable/1.6.x LOCALFLAVOR=django-localflavor
17+
18+
matrix:
19+
exclude:
20+
- python: 3.3
21+
env: DJANGO=Django==1.3.7
22+
- python: 3.3
23+
env: DJANGO=Django==1.4.8
24+
825
# command to install dependencies
926
install:
27+
- "pip install $DJANGO $DATEUTIL $LOCALFLAVOR --use-mirrors"
1028
- "pip install . --use-mirrors"
1129
- "pip install -r tests/test_requirements.txt --use-mirrors"
12-
- "if [ ${TRAVIS_PYTHON_VERSION:0:1} != 3 ]; then pip install Babel --use-mirrors; fi"
30+
1331
# command to run tests
1432
script: coverage run --source=wtforms tests/runtests.py --with-pep8
1533
after_success:

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Not yet released.
1111
- Move CSRF into core. Deprecate `wtforms.ext.csrf`.
1212
- Fix issue rendering SelectFields with ``value=True``
1313
- Make `DecimalField` able to use babel locale-based number formatting.
14+
- Drop Python 3.2 support (Python3 support for 3.3+ only)
1415

1516
Version 1.0.5
1617
-------------

docs/crash_course.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Rendering a field is as simple as coercing it to a string::
268268

269269
However, the real power comes from rendering the field with its :meth:`~wtforms.fields.Field.__call__`
270270
method. By calling the field, you can provide keyword arguments, which will be
271-
injected as html parameters in the output::
271+
injected as html attributes in the output::
272272

273273
>>> form.content(style="width: 200px;", class_="bar")
274274
u'<input class="bar" id="content" name="content" style="width: 200px;" type="text" value="foobar" />'

docs/ext.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ your forms.
183183
184184
def edit_blog_post(request, id):
185185
post = Post.query.get(id)
186-
form = ArticleEdit(obj=post)
186+
form = BlogPostEdit(obj=post)
187187
# Since we didn't provide a query_factory for the 'blog' field, we need
188188
# to set a dynamic one in the view.
189189
form.blog.query = Blog.query.filter(Blog.author == request.user).order_by(Blog.name)
190190
191191
192192
.. autoclass:: QuerySelectField(default field args, query_factory=None, get_pk=None, get_label=None, allow_blank=False, blank_text=u'')
193193

194-
.. autoclass:: QuerySelectMultipleField(default field args, query_factory=None, get_pk=None, get_label=None, allow_blank=False, blank_text=u'')
194+
.. autoclass:: QuerySelectMultipleField(default field args, query_factory=None, get_pk=None, get_label=None)
195195

196196

197197
CSRF

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
'Programming Language :: Python :: 2.6',
3535
'Programming Language :: Python :: 2.7',
3636
'Programming Language :: Python :: 3',
37-
'Programming Language :: Python :: 3.2',
3837
'Programming Language :: Python :: 3.3',
3938
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
4039
'Topic :: Software Development :: Libraries :: Python Modules'

tests/ext_django/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from __future__ import unicode_literals
22

33
from django.db import models
4-
from django.contrib.localflavor.us.models import USStateField
4+
try:
5+
from localflavor.us.models import USStateField
6+
except ImportError:
7+
from django.contrib.localflavor.us.models import USStateField
8+
59

610
class Group(models.Model):
711
name = models.CharField(max_length=20)
@@ -11,6 +15,7 @@ def __unicode__(self):
1115

1216
__str__ = __unicode__
1317

18+
1419
class User(models.Model):
1520
username = models.CharField(max_length=40)
1621
group = models.ForeignKey(Group)

tests/ext_django/tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
from wtforms.compat import text_type
4747
from wtforms.ext.django.orm import model_form
4848
from wtforms.ext.django.fields import QuerySetSelectField, ModelSelectField, DateTimeField
49+
try:
50+
import pytz
51+
has_pytz = (pytz.VERSION >= '2012')
52+
except ImportError:
53+
has_pytz = False
4954

5055
def contains_validator(field, v_type):
5156
for v in field.validators:
@@ -213,6 +218,9 @@ def test_convert_input_to_current_timezone(self):
213218

214219
@override_settings(USE_TZ=True, TIME_ZONE='America/Los_Angeles')
215220
def test_stored_value_converted_to_current_timezone(self):
221+
if not has_pytz:
222+
# Ignore this test if we don't have pytz.
223+
return
216224
utc_date = datetime.datetime(2013, 9, 25, 2, 15, tzinfo=timezone.utc)
217225
form = self.F(a=utc_date)
218226
self.assertTrue('2013-09-24 19:15:00' in form.a())

tests/test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Django
21
SQLAlchemy
32
python-dateutil
43
pep8
54
coverage
65
coveralls
6+
Babel>=1.3

wtforms/ext/dateutil/fields.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
)
1616

1717

18+
# This is a fix to handle issues in dateutil which arose in version 2.2.
19+
# A bug ticket is filed: https://bugs.launchpad.net/dateutil/+bug/1247643
20+
try:
21+
parser.parse('foobar')
22+
except TypeError:
23+
DATEUTIL_TYPEERROR_ISSUE = True
24+
except ValueError:
25+
DATEUTIL_TYPEERROR_ISSUE = False
26+
else:
27+
import warnings
28+
warnings.warn('In testing for a dateutil issue, we ran into a very strange error.', ImportWarning)
29+
30+
1831
class DateTimeField(Field):
1932
"""
2033
DateTimeField represented by a text input, accepts all input text formats
@@ -60,6 +73,14 @@ def process_formdata(self, valuelist):
6073
except ValueError:
6174
self.data = None
6275
raise ValidationError(self.gettext('Invalid date/time input'))
76+
except TypeError:
77+
if not DATEUTIL_TYPEERROR_ISSUE:
78+
raise
79+
80+
# If we're using dateutil 2.2, then consider it a normal
81+
# ValidationError. Hopefully dateutil fixes this issue soon.
82+
self.data = None
83+
raise ValidationError(self.gettext('Invalid date/time input'))
6384

6485

6586
class DateField(DateTimeField):

wtforms/ext/django/fields.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import operator
88

99
from django.conf import settings
10-
from django.utils import timezone
10+
11+
try:
12+
from django.utils import timezone
13+
has_timezone = True
14+
except ImportError:
15+
has_timezone = False
1116

1217
from wtforms import fields, widgets
1318
from wtforms.compat import string_types
@@ -103,17 +108,27 @@ def __init__(self, label=None, validators=None, model=None, **kwargs):
103108
class DateTimeField(fields.DateTimeField):
104109
"""
105110
Adds support for Django's timezone utilities.
106-
Requires Django >= 1.4
111+
Requires Django >= 1.5
107112
"""
113+
def __init__(self, *args, **kwargs):
114+
if not has_timezone:
115+
raise ImportError('DateTimeField requires Django >= 1.5')
116+
117+
super(DateTimeField, self).__init__(*args, **kwargs)
118+
108119
def process_formdata(self, valuelist):
109120
super(DateTimeField, self).process_formdata(valuelist)
121+
110122
date = self.data
123+
111124
if settings.USE_TZ and date is not None and timezone.is_naive(date):
112125
current_timezone = timezone.get_current_timezone()
113126
self.data = timezone.make_aware(date, current_timezone)
114127

115128
def _value(self):
116129
date = self.data
130+
117131
if settings.USE_TZ and isinstance(date, datetime.datetime) and timezone.is_aware(date):
118132
self.data = timezone.localtime(date)
133+
119134
return super(DateTimeField, self)._value()

0 commit comments

Comments
 (0)