diff options
Diffstat (limited to 'uploader/route_utils.py')
| -rw-r--r-- | uploader/route_utils.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/uploader/route_utils.py b/uploader/route_utils.py index 53247e6..426d7eb 100644 --- a/uploader/route_utils.py +++ b/uploader/route_utils.py @@ -3,7 +3,6 @@ import logging from json.decoder import JSONDecodeError from flask import (flash, - url_for, request, redirect, render_template, @@ -11,6 +10,7 @@ from flask import (flash, from gn_libs.mysqldb import database_connection +from uploader.flask_extensions import url_for from uploader.datautils import base64_encode_dict, base64_decode_to_dict from uploader.population.models import (populations_by_species, population_by_species_and_id) @@ -56,22 +56,24 @@ def generic_select_population( def redirect_to_next(default: dict): """Redirect to the next uri if specified, else redirect to default.""" assert "uri" in default, "You must provide at least the 'uri' value." - try: - next_page = base64_decode_to_dict(request.args.get("next")) - _uri = next_page["uri"] - next_page.pop("uri") - return redirect(url_for(_uri, **next_page)) - except (TypeError, JSONDecodeError) as _err: - logger.debug("We could not decode the next value '%s'", - next_page, - exc_info=True) + _next = request.args.get("next") or "" + if bool(_next): + try: + next_page = base64_decode_to_dict(_next) + _uri = next_page["uri"] + next_page.pop("uri") + return redirect(url_for(_uri, **next_page)) + except (TypeError, JSONDecodeError) as _err: + logger.debug("We could not decode the next value '%s'", + next_page, + exc_info=True) return redirect(url_for( default["uri"], **{key:value for key,value in default.items() if key != "uri"})) -def build_next_argument(uri: str, **kwargs) -> str: +def build_next_argument(uri: str, **kwargs) -> bytes: """Build the `next` URI argument from provided details.""" dumps_keywords = ( "skipkeys", "ensure_ascii", "check_circular", "allow_nan", "cls", |
