Commit 273c61ee authored by Paul Brown's avatar Paul Brown

add missing success/error to flashes

parent 0e0f0685
...@@ -789,7 +789,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -789,7 +789,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
try: try:
self._save_form_files(directory, path, form) self._save_form_files(directory, path, form)
flash(gettext('Successfully saved file: %(name)s', flash(gettext('Successfully saved file: %(name)s',
name=form.upload.data.filename)) name=form.upload.data.filename), 'success')
return redirect(self._get_dir_url('.index_view', path)) return redirect(self._get_dir_url('.index_view', path))
except Exception as ex: except Exception as ex:
flash(gettext('Failed to save file: %(error)s', error=ex), 'error') flash(gettext('Failed to save file: %(error)s', error=ex), 'error')
...@@ -853,7 +853,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -853,7 +853,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
self.storage.make_dir(directory, form.name.data) self.storage.make_dir(directory, form.name.data)
self.on_mkdir(directory, form.name.data) self.on_mkdir(directory, form.name.data)
flash(gettext('Successfully created directory: %(directory)s', flash(gettext('Successfully created directory: %(directory)s',
directory=form.name.data)) directory=form.name.data), 'success')
return redirect(dir_url) return redirect(dir_url)
except Exception as ex: except Exception as ex:
flash(gettext('Failed to create directory: %(error)s', error=ex), 'error') flash(gettext('Failed to create directory: %(error)s', error=ex), 'error')
...@@ -907,7 +907,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -907,7 +907,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
self.before_directory_delete(full_path, path) self.before_directory_delete(full_path, path)
self.storage.delete_tree(full_path) self.storage.delete_tree(full_path)
self.on_directory_delete(full_path, path) self.on_directory_delete(full_path, path)
flash(gettext('Directory "%(path)s" was successfully deleted.', path=path)) flash(gettext('Directory "%(path)s" was successfully deleted.', path=path), 'success')
except Exception as ex: except Exception as ex:
flash(gettext('Failed to delete directory: %(error)s', error=ex), 'error') flash(gettext('Failed to delete directory: %(error)s', error=ex), 'error')
else: else:
...@@ -915,7 +915,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -915,7 +915,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
self.before_file_delete(full_path, path) self.before_file_delete(full_path, path)
self.delete_file(full_path) self.delete_file(full_path)
self.on_file_delete(full_path, path) self.on_file_delete(full_path, path)
flash(gettext('File "%(name)s" was successfully deleted.', name=path)) flash(gettext('File "%(name)s" was successfully deleted.', name=path), 'success')
except Exception as ex: except Exception as ex:
flash(gettext('Failed to delete file: %(name)s', name=ex), 'error') flash(gettext('Failed to delete file: %(name)s', name=ex), 'error')
else: else:
...@@ -958,7 +958,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -958,7 +958,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
self.on_rename(full_path, dir_base, filename) self.on_rename(full_path, dir_base, filename)
flash(gettext('Successfully renamed "%(src)s" to "%(dst)s"', flash(gettext('Successfully renamed "%(src)s" to "%(dst)s"',
src=op.basename(path), src=op.basename(path),
dst=filename)) dst=filename), 'success')
except Exception as ex: except Exception as ex:
flash(gettext('Failed to rename: %(error)s', error=ex), 'error') flash(gettext('Failed to rename: %(error)s', error=ex), 'error')
...@@ -1015,7 +1015,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -1015,7 +1015,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
error = True error = True
else: else:
self.on_edit_file(full_path, path) self.on_edit_file(full_path, path)
flash(gettext("Changes to %(name)s saved successfully.", name=path)) flash(gettext("Changes to %(name)s saved successfully.", name=path), 'success')
return redirect(next_url) return redirect(next_url)
else: else:
helpers.flash_errors(form, message='Failed to edit file. %(error)s') helpers.flash_errors(form, message='Failed to edit file. %(error)s')
...@@ -1072,7 +1072,7 @@ class BaseFileAdmin(BaseView, ActionsMixin): ...@@ -1072,7 +1072,7 @@ class BaseFileAdmin(BaseView, ActionsMixin):
if self.is_accessible_path(path): if self.is_accessible_path(path):
try: try:
self.delete_file(full_path) self.delete_file(full_path)
flash(gettext('File "%(name)s" was successfully deleted.', name=path)) flash(gettext('File "%(name)s" was successfully deleted.', name=path), 'success')
except Exception as ex: except Exception as ex:
flash(gettext('Failed to delete file: %(name)s', name=ex), 'error') flash(gettext('Failed to delete file: %(name)s', name=ex), 'error')
......
...@@ -671,7 +671,7 @@ class ModelView(BaseModelView): ...@@ -671,7 +671,7 @@ class ModelView(BaseModelView):
flash(ngettext('Record was successfully deleted.', flash(ngettext('Record was successfully deleted.',
'%(count)s records were successfully deleted.', '%(count)s records were successfully deleted.',
count, count,
count=count)) count=count), 'error')
except Exception as ex: except Exception as ex:
if not self.handle_view_exception(ex): if not self.handle_view_exception(ex):
flash(gettext('Failed to delete records. %(error)s', error=str(ex)), flash(gettext('Failed to delete records. %(error)s', error=str(ex)),
......
...@@ -498,7 +498,7 @@ class ModelView(BaseModelView): ...@@ -498,7 +498,7 @@ class ModelView(BaseModelView):
flash(ngettext('Record was successfully deleted.', flash(ngettext('Record was successfully deleted.',
'%(count)s records were successfully deleted.', '%(count)s records were successfully deleted.',
count, count,
count=count)) count=count), 'error')
except Exception as ex: except Exception as ex:
if not self.handle_view_exception(ex): if not self.handle_view_exception(ex):
flash(gettext('Failed to delete records. %(error)s', error=str(ex)), 'error') flash(gettext('Failed to delete records. %(error)s', error=str(ex)), 'error')
...@@ -1106,7 +1106,7 @@ class ModelView(BaseModelView): ...@@ -1106,7 +1106,7 @@ class ModelView(BaseModelView):
flash(ngettext('Record was successfully deleted.', flash(ngettext('Record was successfully deleted.',
'%(count)s records were successfully deleted.', '%(count)s records were successfully deleted.',
count, count,
count=count)) count=count), 'error')
except Exception as ex: except Exception as ex:
if not self.handle_view_exception(ex): if not self.handle_view_exception(ex):
raise raise
......
...@@ -1438,7 +1438,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1438,7 +1438,7 @@ class BaseModelView(BaseView, ActionsMixin):
# Exception handler # Exception handler
def handle_view_exception(self, exc): def handle_view_exception(self, exc):
if isinstance(exc, ValidationError): if isinstance(exc, ValidationError):
flash(as_unicode(exc)) flash(as_unicode(exc), 'error')
return True return True
if self._debug: if self._debug:
...@@ -1623,7 +1623,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1623,7 +1623,7 @@ class BaseModelView(BaseView, ActionsMixin):
if flt.validate(value): if flt.validate(value):
filters.append((pos, (idx, as_unicode(flt.name), value))) filters.append((pos, (idx, as_unicode(flt.name), value)))
else: else:
flash(gettext('Invalid Filter Value: %(value)s', value=value)) flash(gettext('Invalid Filter Value: %(value)s', value=value), 'error')
# Sort filters # Sort filters
return [v[1] for v in sorted(filters, key=lambda n: n[0])] return [v[1] for v in sorted(filters, key=lambda n: n[0])]
...@@ -1916,7 +1916,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1916,7 +1916,7 @@ class BaseModelView(BaseView, ActionsMixin):
# in later versions, this is the model itself # in later versions, this is the model itself
model = self.create_model(form) model = self.create_model(form)
if model: if model:
flash(gettext('Record was successfully created.')) flash(gettext('Record was successfully created.'), 'success')
if '_add_another' in request.form: if '_add_another' in request.form:
return redirect(request.url) return redirect(request.url)
elif '_continue_editing' in request.form: elif '_continue_editing' in request.form:
...@@ -1960,7 +1960,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1960,7 +1960,7 @@ class BaseModelView(BaseView, ActionsMixin):
model = self.get_one(id) model = self.get_one(id)
if model is None: if model is None:
flash(gettext('Record does not exist.')) flash(gettext('Record does not exist.'), 'error')
return redirect(return_url) return redirect(return_url)
form = self.edit_form(obj=model) form = self.edit_form(obj=model)
...@@ -1969,7 +1969,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -1969,7 +1969,7 @@ class BaseModelView(BaseView, ActionsMixin):
if self.validate_form(form): if self.validate_form(form):
if self.update_model(form, model): if self.update_model(form, model):
flash(gettext('Record was successfully saved.')) flash(gettext('Record was successfully saved.'), 'success')
if '_add_another' in request.form: if '_add_another' in request.form:
return redirect(self.get_url('.create_view', url=return_url)) return redirect(self.get_url('.create_view', url=return_url))
elif '_continue_editing' in request.form: elif '_continue_editing' in request.form:
...@@ -2012,7 +2012,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -2012,7 +2012,7 @@ class BaseModelView(BaseView, ActionsMixin):
model = self.get_one(id) model = self.get_one(id)
if model is None: if model is None:
flash(gettext('Record does not exist.')) flash(gettext('Record does not exist.'), 'error')
return redirect(return_url) return redirect(return_url)
if self.details_modal and request.args.get('modal'): if self.details_modal and request.args.get('modal'):
...@@ -2045,12 +2045,12 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -2045,12 +2045,12 @@ class BaseModelView(BaseView, ActionsMixin):
model = self.get_one(id) model = self.get_one(id)
if model is None: if model is None:
flash(gettext('Record does not exist.')) flash(gettext('Record does not exist.'), 'error')
return redirect(return_url) return redirect(return_url)
# message is flashed from within delete_model if it fails # message is flashed from within delete_model if it fails
if self.delete_model(model): if self.delete_model(model):
flash(gettext('Record was successfully deleted.')) flash(gettext('Record was successfully deleted.'), 'success')
return redirect(return_url) return redirect(return_url)
else: else:
flash_errors(form, message='Failed to delete record. %(error)s') flash_errors(form, message='Failed to delete record. %(error)s')
...@@ -2100,7 +2100,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -2100,7 +2100,7 @@ class BaseModelView(BaseView, ActionsMixin):
return_url = get_redirect_target() or self.get_url('.index_view') return_url = get_redirect_target() or self.get_url('.index_view')
if not self.can_export or (export_type not in self.export_types): if not self.can_export or (export_type not in self.export_types):
flash(gettext('Permission denied.')) flash(gettext('Permission denied.'), 'error')
return redirect(return_url) return redirect(return_url)
if export_type == 'csv': if export_type == 'csv':
...@@ -2154,7 +2154,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -2154,7 +2154,7 @@ class BaseModelView(BaseView, ActionsMixin):
Exports a variety of formats using the tablib library. Exports a variety of formats using the tablib library.
""" """
if tablib is None: if tablib is None:
flash(gettext('Tablib dependency not installed.')) flash(gettext('Tablib dependency not installed.'), 'error')
return redirect(return_url) return redirect(return_url)
filename = self.get_export_name(export_type) filename = self.get_export_name(export_type)
...@@ -2182,7 +2182,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -2182,7 +2182,7 @@ class BaseModelView(BaseView, ActionsMixin):
response_data = getattr(ds, export_type) response_data = getattr(ds, export_type)
except (AttributeError, tablib.UnsupportedFormat): except (AttributeError, tablib.UnsupportedFormat):
flash(gettext('Export type "%(type)s not supported.', flash(gettext('Export type "%(type)s not supported.',
type=export_type)) type=export_type), 'error')
return redirect(return_url) return redirect(return_url)
return Response( return Response(
......
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