Commit 10a0030c authored by jadkik's avatar jadkik

Error reporting and translation

parent 19066d73
......@@ -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):
......
......@@ -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 %}
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