Commit e87c4302 authored by Paul Brown's avatar Paul Brown

return user to previous list view after action

parent 45e2b81e
...@@ -3,6 +3,7 @@ from flask import request, redirect ...@@ -3,6 +3,7 @@ from flask import request, redirect
from flask_admin import tools from flask_admin import tools
from flask_admin._compat import text_type from flask_admin._compat import text_type
from flask_admin.helpers import get_redirect_target
def action(name, text, confirmation=None): def action(name, text, confirmation=None):
...@@ -100,7 +101,8 @@ class ActionsMixin(object): ...@@ -100,7 +101,8 @@ class ActionsMixin(object):
:param return_view: :param return_view:
Name of the view to return to after the request. Name of the view to return to after the request.
If not provided, will return user to the index view. If not provided, will return user to the return url in the form
or the list view.
""" """
action = request.form.get('action') action = request.form.get('action')
ids = request.form.getlist('rowid') ids = request.form.getlist('rowid')
...@@ -113,9 +115,9 @@ class ActionsMixin(object): ...@@ -113,9 +115,9 @@ class ActionsMixin(object):
if response is not None: if response is not None:
return response return response
if not return_view: if return_view:
url = self.get_url('.' + self._default_view)
else:
url = self.get_url('.' + return_view) url = self.get_url('.' + return_view)
else:
url = get_redirect_target() or self.get_url('.index_view')
return redirect(url) return redirect(url)
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
{% if csrf_token %} {% if csrf_token %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
{% endif %} {% endif %}
<input type="hidden" name="url" value="{{ return_url }}">
<input type="hidden" id="action" name="action" /> <input type="hidden" id="action" name="action" />
</form> </form>
{% endif %} {% endif %}
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
{% if csrf_token %} {% if csrf_token %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
{% endif %} {% endif %}
<input type="hidden" name="url" value="{{ return_url }}">
<input type="hidden" id="action" name="action" /> <input type="hidden" id="action" name="action" />
</form> </form>
{% endif %} {% endif %}
......
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