Commit 10a0030c authored by jadkik's avatar jadkik

Error reporting and translation

parent 19066d73
...@@ -561,6 +561,7 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -561,6 +561,7 @@ class FileAdmin(BaseView, ActionsMixin):
next_url = next_url or dir_url next_url = next_url or dir_url
form = EditForm() form = EditForm()
error = False
if request.method == 'POST': if request.method == 'POST':
form.process(request.form, content='') form.process(request.form, content='')
if form.validate(): if form.validate():
...@@ -568,16 +569,35 @@ class FileAdmin(BaseView, ActionsMixin): ...@@ -568,16 +569,35 @@ class FileAdmin(BaseView, ActionsMixin):
with open(full_path, 'w') as f: with open(full_path, 'w') as f:
f.write(request.form['content']) f.write(request.form['content'])
except IOError: except IOError:
flash(lazy_gettext("Error saving changes to file!"), flash(gettext("Error saving changes to %(name)s.", name=path), 'error')
'error') error = True
else: else:
flash(lazy_gettext("Changes saved successfully!")) flash(gettext("Changes to %(name)s saved successfully.", name=path))
return redirect(next_url) return redirect(next_url)
else: else:
with open(full_path, 'r') as f: try:
form.content.data = f.read() with open(full_path, 'r') as f:
return self.render(self.edit_template, dir_url=dir_url, form=form, content = f.read()
path=path) 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',)) @expose('/action/', methods=('POST',))
def action_view(self): def action_view(self):
......
...@@ -3,5 +3,9 @@ ...@@ -3,5 +3,9 @@
{% block body %} {% block body %}
<h3>{{ _gettext('You are editing %(path)s', path=path) }}</h3> <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) }} {{ lib.render_form(form, dir_url) }}
{% endif %}
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment