Skip to content

Commit 2427a20

Browse files
committed
Fixed EmailField rendering and validation (MongoEngine#44, MongoEngine#9)
1 parent aa6f13c commit 2427a20

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

AUTHORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ that much better:
2424
* Marcus Carlsson - https://github.com/xintron
2525
* RealJTG - https://github.com/RealJTG
2626
* Peter D. Gray
27-
* Rodrigue Cloutier
27+
* Massimo Santini

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44

55
Changes in 0.7
66
==============
7+
- Fixed EmailField rendering and validation (#44, #9)
78
- Use help_text for field description (#43)
89
- Fixed Pagination and added Document.paginate_field() helper
910
- Keep model_forms fields in order of creation

flask_mongoengine/wtf/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class NoneStringField(Field):
162162
def process_formdata(self, valuelist):
163163
if valuelist:
164164
self.data = valuelist[0]
165-
else:
165+
if not self.data:
166166
self.data = None
167167

168168
def _value(self):
169-
return txt_type(self.data) if self.data else None
169+
return txt_type(self.data) if self.data else ""

tests/test_forms.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ def setUp(self):
3232
def tearDown(self):
3333
self.db.connection.drop_database(self.db_name)
3434

35+
def test_emailfield(self):
36+
37+
with self.app.test_request_context('/'):
38+
db = self.db
39+
40+
class Email(db.Document):
41+
email = db.EmailField(required=False)
42+
43+
EmailForm = model_form(Email)
44+
form = EmailForm(instance=Email())
45+
self.assertFalse("None" in "%s" % form.email)
46+
self.assertTrue(form.validate())
47+
48+
form = EmailForm(MultiDict({"email": ""}))
49+
self.assertFalse("None" in "%s" % form.email)
50+
self.assertTrue(form.validate())
51+
3552
def test_model_form(self):
3653
with self.app.test_request_context('/'):
3754
db = self.db
@@ -276,7 +293,7 @@ class Post(db.Document):
276293

277294
PostForm = model_form(Post)
278295
form = PostForm()
279-
self.assertTrue("content-text" in form.content.text)
296+
self.assertTrue("content-text" in "%s" % form.content.text)
280297

281298

282299
if __name__ == '__main__':

0 commit comments

Comments
 (0)