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
84e00216
Commit
84e00216
authored
Jul 15, 2014
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More logical unhandled exception handling
parent
d0b60696
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
43 deletions
+32
-43
view.py
flask_admin/contrib/mongoengine/view.py
+14
-19
view.py
flask_admin/contrib/peewee/view.py
+7
-12
view.py
flask_admin/contrib/sqla/view.py
+8
-9
base.py
flask_admin/model/base.py
+3
-3
No files found.
flask_admin/contrib/mongoengine/view.py
View file @
84e00216
...
...
@@ -493,12 +493,11 @@ class ModelView(BaseModelView):
model
.
save
()
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
format_error
(
ex
)),
'error'
)
log
.
exception
(
'Failed to create model'
)
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
format_error
(
ex
)),
'error'
)
log
.
exception
(
'Failed to create model'
)
return
False
else
:
self
.
after_model_change
(
form
,
model
,
True
)
...
...
@@ -520,12 +519,11 @@ class ModelView(BaseModelView):
model
.
save
()
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
format_error
(
ex
)),
'error'
)
log
.
exception
(
'Failed to update model'
)
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
format_error
(
ex
)),
'error'
)
log
.
exception
(
'Failed to update model'
)
return
False
else
:
self
.
after_model_change
(
form
,
model
,
False
)
...
...
@@ -545,12 +543,11 @@ class ModelView(BaseModelView):
return
True
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
format_error
(
ex
)),
'error'
)
log
.
exception
(
'Failed to delete model'
)
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
format_error
(
ex
)),
'error'
)
log
.
exception
(
'Failed to delete model'
)
return
False
# FileField access API
...
...
@@ -600,7 +597,5 @@ class ModelView(BaseModelView):
count
=
count
))
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to delete models.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
flash
(
gettext
(
'Failed to delete models.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
flask_admin/contrib/peewee/view.py
View file @
84e00216
...
...
@@ -350,10 +350,9 @@ class ModelView(BaseModelView):
save_inline
(
form
,
model
)
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to create model'
)
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to create model'
)
return
False
else
:
self
.
after_model_change
(
form
,
model
,
True
)
...
...
@@ -370,10 +369,9 @@ class ModelView(BaseModelView):
save_inline
(
form
,
model
)
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to update model'
)
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to update model'
)
return
False
else
:
self
.
after_model_change
(
form
,
model
,
False
)
...
...
@@ -387,10 +385,9 @@ class ModelView(BaseModelView):
return
True
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to delete model'
)
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to delete model'
)
return
False
# Default model actions
...
...
@@ -425,6 +422,4 @@ class ModelView(BaseModelView):
count
=
count
))
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to delete models.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
flash
(
gettext
(
'Failed to delete models.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
flask_admin/contrib/sqla/view.py
View file @
84e00216
...
...
@@ -831,11 +831,11 @@ class ModelView(BaseModelView):
self
.
session
.
commit
()
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to create model'
)
flash
(
gettext
(
'Failed to create model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to create model'
)
self
.
session
.
rollback
()
return
False
else
:
self
.
after_model_change
(
form
,
model
,
True
)
...
...
@@ -857,10 +857,9 @@ class ModelView(BaseModelView):
self
.
session
.
commit
()
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to update model'
)
flash
(
gettext
(
'Failed to update model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to update model'
)
self
.
session
.
rollback
()
return
False
...
...
@@ -884,11 +883,11 @@ class ModelView(BaseModelView):
return
True
except
Exception
as
ex
:
if
not
self
.
handle_view_exception
(
ex
):
raise
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to delete model'
)
flash
(
gettext
(
'Failed to delete model.
%(error)
s'
,
error
=
str
(
ex
)),
'error'
)
log
.
exception
(
'Failed to delete model'
)
self
.
session
.
rollback
()
return
False
# Default model actions
...
...
flask_admin/model/base.py
View file @
84e00216
...
...
@@ -365,7 +365,7 @@ class BaseModelView(BaseView, ActionsMixin):
'style': 'color: black'
}
}
Note, changing the format of a DateTimeField will require changes to both form_widget_args and form_args::
form_args = dict(
...
...
@@ -890,9 +890,9 @@ class BaseModelView(BaseView, ActionsMixin):
# Exception handler
def
handle_view_exception
(
self
,
exc
):
if
self
.
_debug
:
r
eturn
Fal
se
r
ai
se
return
Tru
e
return
Fals
e
# Model event handlers
def
on_model_change
(
self
,
form
,
model
,
is_created
):
...
...
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