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
10a0030c
Commit
10a0030c
authored
Dec 08, 2012
by
jadkik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error reporting and translation
parent
19066d73
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
+31
-7
fileadmin.py
flask_admin/contrib/fileadmin.py
+27
-7
edit.html
flask_admin/templates/admin/file/edit.html
+4
-0
No files found.
flask_admin/contrib/fileadmin.py
View file @
10a0030c
...
...
@@ -561,6 +561,7 @@ class FileAdmin(BaseView, ActionsMixin):
next_url
=
next_url
or
dir_url
form
=
EditForm
()
error
=
False
if
request
.
method
==
'POST'
:
form
.
process
(
request
.
form
,
content
=
''
)
if
form
.
validate
():
...
...
@@ -568,16 +569,35 @@ class FileAdmin(BaseView, ActionsMixin):
with
open
(
full_path
,
'w'
)
as
f
:
f
.
write
(
request
.
form
[
'content'
])
except
IOError
:
flash
(
lazy_gettext
(
"Error saving changes to file!"
),
'error'
)
flash
(
gettext
(
"Error saving changes to
%(name)
s."
,
name
=
path
),
'error'
)
error
=
True
else
:
flash
(
lazy_gettext
(
"Changes saved successfully!"
))
flash
(
gettext
(
"Changes to
%(name)
s saved successfully."
,
name
=
path
))
return
redirect
(
next_url
)
else
:
with
open
(
full_path
,
'r'
)
as
f
:
form
.
content
.
data
=
f
.
read
()
return
self
.
render
(
self
.
edit_template
,
dir_url
=
dir_url
,
form
=
form
,
path
=
path
)
try
:
with
open
(
full_path
,
'r'
)
as
f
:
content
=
f
.
read
()
except
IOError
:
flash
(
gettext
(
"Error reading
%(name)
s."
,
name
=
path
),
'error'
)
error
=
True
except
:
flash
(
gettext
(
"Unexpected error while reading from
%(name)
s"
,
name
=
path
),
'error'
)
error
=
True
else
:
try
:
content
.
decode
(
'utf8'
)
except
UnicodeDecodeError
:
flash
(
gettext
(
"Cannot edit
%(name)
s."
,
name
=
path
),
'error'
)
error
=
True
except
:
flash
(
gettext
(
"Unexpected error while reading from
%(name)
s"
,
name
=
path
),
'error'
)
error
=
True
else
:
form
.
content
.
data
=
content
return
self
.
render
(
self
.
edit_template
,
dir_url
=
dir_url
,
path
=
path
,
form
=
form
,
error
=
error
)
@
expose
(
'/action/'
,
methods
=
(
'POST'
,))
def
action_view
(
self
):
...
...
flask_admin/templates/admin/file/edit.html
View file @
10a0030c
...
...
@@ -3,5 +3,9 @@
{% block body %}
<h3>
{{ _gettext('You are editing %(path)s', path=path) }}
</h3>
{% if error %}
<span>
This file cannot be edited for now.
</span>
{% else %}
{{ lib.render_form(form, dir_url) }}
{% endif %}
{% endblock %}
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