From 905c6e8e02a93d32b8a59c0922f955d766171e36 Mon Sep 17 00:00:00 2001
From: Krateng
Date: Wed, 11 Dec 2019 15:49:03 +0100
Subject: [PATCH] Switched error page to pyhp
---
maloja/server.py | 21 +++++--------------
maloja/web/admin.pyhp | 2 +-
.../web/errors/{generic.html => generic.pyhp} | 5 +++--
3 files changed, 9 insertions(+), 19 deletions(-)
rename maloja/web/errors/{generic.html => generic.pyhp} (68%)
diff --git a/maloja/server.py b/maloja/server.py
index 5ca6c58..f97ea9d 100755
--- a/maloja/server.py
+++ b/maloja/server.py
@@ -22,6 +22,7 @@ from . import urihandler
from doreah import settings
from doreah.logging import log
from doreah.timing import Clock
+from doreah.pyhp import file as pyhpfile
# technical
#from importlib.machinery import SourceFileLoader
import importlib
@@ -88,21 +89,10 @@ def customerror(error):
code = int(str(error).split(",")[0][1:])
log("HTTP Error: " + str(code),module="error")
- if os.path.exists(pthjoin(WEBFOLDER,"errors",str(code) + ".html")):
- return static_file(pthjoin(WEBFOLDER,"errors",str(code) + ".html"),root="")
+ if os.path.exists(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp")):
+ return pyhpfile(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp"),{"errorcode":code})
else:
- with open(pthjoin(WEBFOLDER,"errors/generic.html")) as htmlfile:
- html = htmlfile.read()
-
- # apply global substitutions
- with open(pthjoin(WEBFOLDER,"common/footer.html")) as footerfile:
- footerhtml = footerfile.read()
- with open(pthjoin(WEBFOLDER,"common/header.html")) as headerfile:
- headerhtml = headerfile.read()
- html = html.replace("
@@ -13,7 +14,7 @@
- Error ERROR_CODE
+ Error
That did not work. Don't ask me why.
| ",footerhtml + "").replace("",headerhtml + "")
-
- html = html.replace("ERROR_CODE",str(code))
- return html
+ return pyhpfile(pthjoin(WEBFOLDER,"errors","generic.pyhp"),{"errorcode":code})
@@ -191,7 +181,6 @@ def static_html(name):
# if a pyhp file exists, use this
if (pyhp_file and pyhp_pref) or (pyhp_file and not html_file):
- from doreah.pyhp import file
environ = {} #things we expose to the pyhp pages
environ["adminmode"] = adminmode
@@ -211,7 +200,7 @@ def static_html(name):
environ["filterkeys"], environ["limitkeys"], environ["delimitkeys"], environ["amountkeys"] = uri_to_internal(keys)
#response.set_header("Content-Type","application/xhtml+xml")
- res = file(pthjoin(WEBFOLDER,name + ".pyhp"),environ)
+ res = pyhpfile(pthjoin(WEBFOLDER,name + ".pyhp"),environ)
log("Generated page " + name + " in " + str(clock.stop()) + "s (PYHP)",module="debug")
return res
diff --git a/maloja/web/admin.pyhp b/maloja/web/admin.pyhp
index 15a359f..a1351f2 100644
--- a/maloja/web/admin.pyhp
+++ b/maloja/web/admin.pyhp
@@ -96,7 +96,7 @@
Links
Server Setup
- Manual Scrobbling
+ Manual Scrobbling
Database Maintenance
diff --git a/maloja/web/errors/generic.html b/maloja/web/errors/generic.pyhp
similarity index 68%
rename from maloja/web/errors/generic.html
rename to maloja/web/errors/generic.pyhp
index 5ade08e..aafa2e1 100644
--- a/maloja/web/errors/generic.html
+++ b/maloja/web/errors/generic.pyhp
@@ -3,7 +3,8 @@
-
Maloja - Error ERROR_CODE
+
Maloja - Error
+