From 8dc5aee8aab271ec98151792c6e3f8626a91078c Mon Sep 17 00:00:00 2001 From: Tamas Kocsis Date: Tue, 8 Sep 2020 19:32:10 +0200 Subject: [PATCH] Js based redirecting template formatting --- src/Ui/UiRequest.py | 15 ++++++++++++++- src/util/helper.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Ui/UiRequest.py b/src/Ui/UiRequest.py index 66d53463..efac19be 100644 --- a/src/Ui/UiRequest.py +++ b/src/Ui/UiRequest.py @@ -350,12 +350,25 @@ class UiRequest(object): return is_html_file + @helper.encodeResponse + def formatRedirect(self, url): + return """ + + + Redirecting to {0} + + + + """.format(html.escape(url)) + # - Actions - # Redirect to an url def actionRedirect(self, url): self.start_response('301 Redirect', [('Location', str(url))]) - yield b"Location changed: " + url.encode("utf8") + yield self.formatRedirect(url) def actionIndex(self): return self.actionRedirect("/" + config.homepage) diff --git a/src/util/helper.py b/src/util/helper.py index 5383e5a3..61455b08 100644 --- a/src/util/helper.py +++ b/src/util/helper.py @@ -338,7 +338,7 @@ def cmp(a, b): return (a > b) - (a < b) -def encodeResponse(func): +def encodeResponse(func): # Encode returned data from utf8 to bytes def wrapper(*args, **kwargs): back = func(*args, **kwargs) if "__next__" in dir(back):