Aug 17 - Update bulk actions for inspection/issue list
This commit is contained in:
@@ -28,6 +28,29 @@ def safe_redirect_url(url: str | None, fallback: str | None = None) -> str:
|
||||
return fallback
|
||||
return url
|
||||
|
||||
|
||||
def return_url(fallback: str) -> str:
|
||||
"""Where to go back to after a list-page action, preserving its filters.
|
||||
|
||||
Reads the `next` value the page carried through the action — POST body
|
||||
first (forms), then query string (links) — and validates it with
|
||||
safe_redirect_url, so a crafted `next` can never redirect off-site.
|
||||
|
||||
The problem this solves: a delete or an edit launched from a filtered list
|
||||
used to redirect to the bare index, throwing away the filters the user had
|
||||
set. Every list-page action now round-trips the list URL instead.
|
||||
|
||||
`next` is deliberately the FULL list URL (page number and all), not a
|
||||
reconstructed set of arguments — that keeps this helper working when a new
|
||||
filter is added to either list page without anyone having to remember to
|
||||
thread it through here.
|
||||
"""
|
||||
from flask import request
|
||||
return safe_redirect_url(
|
||||
request.form.get('next') or request.args.get('next'),
|
||||
fallback=fallback,
|
||||
)
|
||||
|
||||
def admin_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user