Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
65937041
Commit
65937041
authored
May 20, 2015
by
rma4ok
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] ListField validation
parent
36d16974
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
6 deletions
+47
-6
form.py
flask_admin/contrib/mongoengine/form.py
+2
-2
helpers.py
flask_admin/helpers.py
+4
-3
lib.html
flask_admin/templates/bootstrap2/admin/lib.html
+1
-1
inline_field_list.html
...n/templates/bootstrap2/admin/model/inline_field_list.html
+8
-0
inline_field_list.html
...n/templates/bootstrap3/admin/model/inline_field_list.html
+8
-0
test_basic.py
flask_admin/tests/mongoengine/test_basic.py
+24
-0
No files found.
flask_admin/contrib/mongoengine/form.py
View file @
65937041
from
mongoengine
import
ReferenceField
from
mongoengine
import
ReferenceField
,
ListField
from
mongoengine.base
import
BaseDocument
,
DocumentMetaclass
,
get_document
from
mongoengine.base
import
BaseDocument
,
DocumentMetaclass
,
get_document
from
wtforms
import
fields
,
validators
from
wtforms
import
fields
,
validators
...
@@ -72,7 +72,7 @@ class CustomModelConverter(orm.ModelConverter):
...
@@ -72,7 +72,7 @@ class CustomModelConverter(orm.ModelConverter):
if
field
.
required
:
if
field
.
required
:
kwargs
[
'validators'
]
.
append
(
validators
.
Required
())
kwargs
[
'validators'
]
.
append
(
validators
.
Required
())
el
se
:
el
if
not
isinstance
(
field
,
ListField
)
:
kwargs
[
'validators'
]
.
append
(
validators
.
Optional
())
kwargs
[
'validators'
]
.
append
(
validators
.
Optional
())
ftype
=
type
(
field
)
.
__name__
ftype
=
type
(
field
)
.
__name__
...
...
flask_admin/helpers.py
View file @
65937041
...
@@ -87,9 +87,10 @@ def is_field_error(errors):
...
@@ -87,9 +87,10 @@ def is_field_error(errors):
:param errors:
:param errors:
Errors list.
Errors list.
"""
"""
for
e
in
errors
:
if
isinstance
(
errors
,
(
list
,
tuple
)):
if
isinstance
(
e
,
string_types
):
for
e
in
errors
:
return
True
if
isinstance
(
e
,
string_types
):
return
True
return
False
return
False
...
...
flask_admin/templates/bootstrap2/admin/lib.html
View file @
65937041
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
<p
class=
"help-block"
>
{{ field.description }}
</p>
<p
class=
"help-block"
>
{{ field.description }}
</p>
{% endif %}
{% endif %}
{% if direct_error %}
{% if direct_error %}
<ul
{%
if
direct_error
%}
class=
"input-errors"
{%
endif
%}
>
<ul
class=
"input-errors"
>
{% for e in field.errors if e is string %}
{% for e in field.errors if e is string %}
<li>
{{ e }}
</li>
<li>
{{ e }}
</li>
{% endfor %}
{% endfor %}
...
...
flask_admin/templates/bootstrap2/admin/model/inline_field_list.html
View file @
65937041
...
@@ -2,6 +2,14 @@
...
@@ -2,6 +2,14 @@
{% macro render_field(field) %}
{% macro render_field(field) %}
{{ field }}
{{ field }}
{% if h.is_field_error(field.errors) %}
<ul
class=
"input-errors"
>
{% for e in field.errors if e is string %}
<li>
{{ e }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
{% endmacro %}
{{ base.render_inline_fields(field, template, render_field, check) }}
{{ base.render_inline_fields(field, template, render_field, check) }}
flask_admin/templates/bootstrap3/admin/model/inline_field_list.html
View file @
65937041
...
@@ -2,6 +2,14 @@
...
@@ -2,6 +2,14 @@
{% macro render_field(field) %}
{% macro render_field(field) %}
{{ field }}
{{ field }}
{% if h.is_field_error(field.errors) %}
<ul
class=
"help-block input-errors"
>
{% for e in field.errors if e is string %}
<li>
{{ e }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
{% endmacro %}
{{ base.render_inline_fields(field, template, render_field, check) }}
{{ base.render_inline_fields(field, template, render_field, check) }}
flask_admin/tests/mongoengine/test_basic.py
View file @
65937041
...
@@ -791,6 +791,30 @@ def test_nested_list_subdocument():
...
@@ -791,6 +791,30 @@ def test_nested_list_subdocument():
ok_
(
'value'
not
in
dir
(
inline_form
))
ok_
(
'value'
not
in
dir
(
inline_form
))
def
test_list_subdocument_validation
():
app
,
db
,
admin
=
setup
()
class
Comment
(
db
.
EmbeddedDocument
):
name
=
db
.
StringField
(
max_length
=
20
,
required
=
True
)
value
=
db
.
StringField
(
max_length
=
20
)
class
Model1
(
db
.
Document
):
test1
=
db
.
StringField
(
max_length
=
20
)
subdoc
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
Comment
))
view
=
CustomModelView
(
Model1
)
admin
.
add_view
(
view
)
client
=
app
.
test_client
()
rv
=
client
.
post
(
'/admin/model1/new/'
,
data
=
{
'test1'
:
'test1large'
,
'subdoc-0-name'
:
'comment'
,
'subdoc-0-value'
:
'test'
})
eq_
(
rv
.
status_code
,
302
)
rv
=
client
.
post
(
'/admin/model1/new/'
,
data
=
{
'test1'
:
'test1large'
,
'subdoc-0-name'
:
''
,
'subdoc-0-value'
:
'test'
})
eq_
(
rv
.
status_code
,
200
)
ok_
(
'This field is required'
in
rv
.
data
)
def
test_ajax_fk
():
def
test_ajax_fk
():
app
,
db
,
admin
=
setup
()
app
,
db
,
admin
=
setup
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment