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
def2626f
Commit
def2626f
authored
Oct 06, 2014
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Customizable form validation
parent
a8495930
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
3 deletions
+16
-3
base.py
flask_admin/model/base.py
+16
-3
No files found.
flask_admin/model/base.py
View file @
def2626f
...
...
@@ -2,8 +2,8 @@ import warnings
import
re
from
flask
import
request
,
redirect
,
flash
,
abort
,
json
,
Response
from
jinja2
import
contextfunction
from
wtforms.validators
import
ValidationError
from
flask.ext.admin.babel
import
gettext
...
...
@@ -868,6 +868,15 @@ class BaseModelView(BaseView, ActionsMixin):
"""
return
self
.
_edit_form_class
(
get_form_data
(),
obj
=
obj
)
def
validate_form
(
self
,
form
):
"""
Validate the form on submit.
:param form:
Form to validate
"""
return
validate_form_on_submit
(
form
)
# Helpers
def
is_sortable
(
self
,
name
):
"""
...
...
@@ -933,6 +942,10 @@ class BaseModelView(BaseView, ActionsMixin):
# Exception handler
def
handle_view_exception
(
self
,
exc
):
if
isinstance
(
exc
,
ValidationError
):
flash
(
unicode
(
exc
))
return
True
if
self
.
_debug
:
raise
...
...
@@ -1303,7 +1316,7 @@ class BaseModelView(BaseView, ActionsMixin):
form
=
self
.
create_form
()
if
validate_form_on_submit
(
form
):
if
self
.
validate_form
(
form
):
if
self
.
create_model
(
form
):
if
'_add_another'
in
request
.
form
:
flash
(
gettext
(
'Model was successfully created.'
))
...
...
@@ -1340,7 +1353,7 @@ class BaseModelView(BaseView, ActionsMixin):
form
=
self
.
edit_form
(
obj
=
model
)
if
validate_form_on_submit
(
form
):
if
self
.
validate_form
(
form
):
if
self
.
update_model
(
form
,
model
):
if
'_continue_editing'
in
request
.
form
:
flash
(
gettext
(
'Model was successfully saved.'
))
...
...
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