1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Switched error page to pyhp

This commit is contained in:
Krateng 2019-12-11 15:49:03 +01:00
parent b87379ed98
commit 905c6e8e02
3 changed files with 9 additions and 19 deletions

View File

@ -22,6 +22,7 @@ from . import urihandler
from doreah import settings from doreah import settings
from doreah.logging import log from doreah.logging import log
from doreah.timing import Clock from doreah.timing import Clock
from doreah.pyhp import file as pyhpfile
# technical # technical
#from importlib.machinery import SourceFileLoader #from importlib.machinery import SourceFileLoader
import importlib import importlib
@ -88,21 +89,10 @@ def customerror(error):
code = int(str(error).split(",")[0][1:]) code = int(str(error).split(",")[0][1:])
log("HTTP Error: " + str(code),module="error") log("HTTP Error: " + str(code),module="error")
if os.path.exists(pthjoin(WEBFOLDER,"errors",str(code) + ".html")): if os.path.exists(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp")):
return static_file(pthjoin(WEBFOLDER,"errors",str(code) + ".html"),root="") return pyhpfile(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp"),{"errorcode":code})
else: else:
with open(pthjoin(WEBFOLDER,"errors/generic.html")) as htmlfile: return pyhpfile(pthjoin(WEBFOLDER,"errors","generic.pyhp"),{"errorcode":code})
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("</body>",footerhtml + "</body>").replace("</head>",headerhtml + "</head>")
html = html.replace("ERROR_CODE",str(code))
return html
@ -191,7 +181,6 @@ def static_html(name):
# if a pyhp file exists, use this # if a pyhp file exists, use this
if (pyhp_file and pyhp_pref) or (pyhp_file and not html_file): 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 = {} #things we expose to the pyhp pages
environ["adminmode"] = adminmode environ["adminmode"] = adminmode
@ -211,7 +200,7 @@ def static_html(name):
environ["filterkeys"], environ["limitkeys"], environ["delimitkeys"], environ["amountkeys"] = uri_to_internal(keys) environ["filterkeys"], environ["limitkeys"], environ["delimitkeys"], environ["amountkeys"] = uri_to_internal(keys)
#response.set_header("Content-Type","application/xhtml+xml") #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") log("Generated page " + name + " in " + str(clock.stop()) + "s (PYHP)",module="debug")
return res return res

View File

@ -96,7 +96,7 @@
<h2>Links</h2> <h2>Links</h2>
<a class="textlink" href="/setup">Server Setup</a><br/> <a class="textlink" href="/setup">Server Setup</a><br/>
<a class="textlink" href="/manual">Manual Scrobbling</a> <a class="textlink" href="/manual">Manual Scrobbling</a><br/>
<a class="textlink" href="/issues">Database Maintenance</a> <a class="textlink" href="/issues">Database Maintenance</a>
<pyhp include="common/footer.html" /> <pyhp include="common/footer.html" />

View File

@ -3,7 +3,8 @@
<html> <html>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Maloja - Error ERROR_CODE</title> <title>Maloja - Error <pyhp echo="errorcode" /></title>
<pyhp include="../common/header.html" />
</head> </head>
<body> <body>
@ -13,7 +14,7 @@
<div style="background-image:url('/favicon.png')"></div> <div style="background-image:url('/favicon.png')"></div>
</td> </td>
<td class="text"> <td class="text">
<h1>Error ERROR_CODE</h1><br/> <h1>Error <pyhp echo="errorcode" /></h1><br/>
<p>That did not work. Don't ask me why.</p> <p>That did not work. Don't ask me why.</p>