Permalink
Browse files

Added field arg option to generate wtforms PasswordField for mongoeng…

…ine StringField
  • Loading branch information...
1 parent 469b315 commit 83c2f3059d41c922be166569e2e12e688205d5e0 @rodcloutier rodcloutier committed Feb 13, 2012
Showing with 12 additions and 0 deletions.
  1. +3 −0 flask_mongoengine/wtf/orm.py
  2. +9 −0 tests.py
View
3 flask_mongoengine/wtf/orm.py
@@ -79,6 +79,9 @@ def conv_String(self, model, field, kwargs):
if field.regex:
kwargs['validators'].append(validators.Regexp(regex=field.regex))
self._string_common(model, field, kwargs)
+ if 'password' in kwargs:
+ if kwargs.pop('password'):
+ return f.PasswordField(**kwargs)
if field.max_length:
return f.TextField(**kwargs)
return f.TextAreaField(**kwargs)
View
9 tests.py
@@ -105,6 +105,7 @@ class TextPost(BlogPost):
class LinkPost(BlogPost):
url = db.StringField(required=True)
+
# Create a text-based post
TextPostForm = model_form(TextPost)
@@ -196,5 +197,13 @@ class DogOwner(db.Document):
self.assertEqual(True, form.dogs.widget.multiple)
+ def test_passwordfield(self):
+ db = self.db
+ class User(db.Document):
+ password = db.StringField()
+
+ UserForm = model_form(User, field_args = { 'password': {'password' : True} })
+ form = UserForm(password='12345')
+ self.assertEqual(wtforms.widgets.PasswordInput, type(form.password.widget))

0 comments on commit 83c2f30

Please sign in to comment.