Js based redirecting template formatting

This commit is contained in:
Tamas Kocsis 2020-09-08 19:32:10 +02:00
parent 94765af0f3
commit 8dc5aee8aa
2 changed files with 15 additions and 2 deletions

View File

@ -350,12 +350,25 @@ class UiRequest(object):
return is_html_file
@helper.encodeResponse
def formatRedirect(self, url):
return """
<html>
<body>
Redirecting to <a href="{0}" target="_top">{0}</a>
<script>
window.top.location = "{0}"
</script>
</body>
</html>
""".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)

View File

@ -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):