Commit 44560e76 authored by Robin Sonnabend's avatar Robin Sonnabend
Browse files

Replace request.args.get("next") by redirect back

More or less directly taken from http://flask.pocoo.org/snippets/120/
parent bf4c10f4
# This snippet is in public domain.
# However, please retain this link in your sources:
# http://flask.pocoo.org/snippets/120/
# Danya Alexeyevsky
import functools
from flask import session, request, redirect as flask_redirect, url_for
import config
cookie = getattr(config, "REDIRECT_BACK_COOKIE", "back")
default_view = getattr(config, "REDIRECT_BACK_DEFAULT", "index")
def anchor(func, cookie=cookie):
@functools.wraps(func)
def result(*args, **kwargs):
session[cookie] = request.url
return func(*args, **kwargs)
return result
def url(default=default_view, cookie=cookie, **url_args):
return session.get(cookie, url_for(default, **url_args))
def redirect(default=default_view, cookie=cookie, **url_args):
return flask_redirect(url(default, cookie, **url_args))
......@@ -4,6 +4,7 @@ from functools import wraps
from models.database import ALL_MODELS
from shared import db, current_user
import back
ID_KEY = "id"
KEY_NOT_PRESENT_MESSAGE = "Missing {}_id."
......@@ -12,10 +13,10 @@ OBJECT_DOES_NOT_EXIST_MESSAGE = "There is no {} with id {}."
MISSING_VIEW_RIGHT = "Dir fehlenden die nötigen Zugriffsrechte."
def default_redirect():
return redirect(request.args.get("next") or url_for("index"))
return back.redirect()
def login_redirect():
return redirect(request.args.get("next") or url_for("login"))
return back.redirect("login")
def db_lookup(*models, check_exists=True):
def _decorator(function):
......
This diff is collapsed.
......@@ -5,6 +5,8 @@ import re
from functools import wraps
from enum import Enum
import back
import config
db = SQLAlchemy()
......@@ -110,7 +112,7 @@ def login_required(function):
if check_login():
return function(*args, **kwargs)
else:
return redirect(url_for("login", next=request.url))
return redirect(url_for("login"))
return decorated_function
def group_required(group):
......@@ -121,7 +123,7 @@ def group_required(group):
return function(*args, **kwargs)
else:
flash("You do not have the necessary permissions to view this page.")
return redirect(request.args.get("next") or url_for("index"))
return back.redirect()
return decorated_function
return decorator
......
......@@ -4,6 +4,6 @@
{% block content %}
<div class="container">
{{render_form(form, action_url=url_for("edit_document", document_id=document.id, next=request.args.get("next") or url_for("show_protocol", protocol_id=document.protocol.id)), action_text="Ändern")}}
{{render_form(form, action_url=url_for("edit_document", document_id=document.id), action_text="Ändern")}}
</div>
{% endblock %}
......@@ -5,6 +5,6 @@
{% block content %}
<div class="container">
<h3>{{localtop.defaulttop.name}}</h3>
{{render_form(form, action_url=url_for("edit_localtop", localtop_id=localtop.id, next=request.args.get("next") or url_for("show_protocol", protocol_id=localtop.protocol.id)), action_text="Ändern", textarea_rows=5)}}
{{render_form(form, action_url=url_for("edit_localtop", localtop_id=localtop.id), action_text="Ändern", textarea_rows=5)}}
</div>
{% endblock %}
......@@ -4,6 +4,6 @@
{% block content %}
<div class="container">
{{render_form(form, action_url=url_for("edit_top", top_id=top.id, next=request.args.get("next") or url_for("show_protocol", protocol_id=top.protocol.id)), action_text="Ändern", textarea_rows=5)}}
{{render_form(form, action_url=url_for("edit_top", top_id=top.id), action_text="Ändern", textarea_rows=5)}}
</div>
{% 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