Skip to content

Commit

Permalink
Merge pull request #345 from Ijwu/master
Browse files Browse the repository at this point in the history
ADDED: Support for FileField
  • Loading branch information
insspb committed Jul 1, 2022
2 parents 9be2d92 + 29fa6ab commit 3583591
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flask_mongoengine/wtf/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def conv_Reference(self, model, field, kwargs):
def conv_GenericReference(self, model, field, kwargs):
return

@converts("FileField")
def conv_File(self, model, field, kwargs):
return f.FileField(**kwargs)

def coerce(self, field_type):
coercions = {
"IntField": int,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ class Poll(db.Document):
assert form.answer.choices == choices


def test_filefield(app, db):
with app.test_request_context("/"):

class FileUpload(db.Document):
file = db.FileField()

FileUploadForm = model_form(FileUpload)

form = FileUploadForm(file=None)

assert isinstance(form.file.widget, wtforms.widgets.FileInput)


def test_passwordfield(app, db):
with app.test_request_context("/"):

Expand Down

0 comments on commit 3583591

Please sign in to comment.