mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Fixed error page
This commit is contained in:
parent
a88afe40ec
commit
9a1bc8be03
@ -4,7 +4,7 @@ from .globalconf import datadir, DATA_DIR
|
|||||||
|
|
||||||
|
|
||||||
# server stuff
|
# server stuff
|
||||||
from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict, redirect, template, HTTPResponse, BaseRequest
|
from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict, redirect, template, HTTPResponse, BaseRequest, abort
|
||||||
import waitress
|
import waitress
|
||||||
# templating
|
# templating
|
||||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
@ -94,10 +94,9 @@ def mainpage():
|
|||||||
def customerror(error):
|
def customerror(error):
|
||||||
code = int(str(error).split(",")[0][1:])
|
code = int(str(error).split(",")[0][1:])
|
||||||
|
|
||||||
if os.path.exists(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp")):
|
template = jinjaenv.get_template('error.jinja')
|
||||||
return pyhpfile(pthjoin(WEBFOLDER,"errors",str(code) + ".pyhp"),{"errorcode":code})
|
res = template.render(errorcode=code)
|
||||||
else:
|
return res
|
||||||
return pyhpfile(pthjoin(WEBFOLDER,"errors","generic.pyhp"),{"errorcode":code})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -222,7 +221,7 @@ jinjaenv = Environment(
|
|||||||
jinjaenv.globals.update(JINJA_CONTEXT)
|
jinjaenv.globals.update(JINJA_CONTEXT)
|
||||||
|
|
||||||
|
|
||||||
@webserver.route("/<name:re:(issues|manual|setup|admin)>")
|
@webserver.route("/<name:re:(admin.*)>")
|
||||||
@auth.authenticated
|
@auth.authenticated
|
||||||
def static_html_private(name):
|
def static_html_private(name):
|
||||||
return static_html(name)
|
return static_html(name)
|
||||||
@ -291,48 +290,50 @@ def static_html(name):
|
|||||||
|
|
||||||
# if not, use the old way
|
# if not, use the old way
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
with open(pthjoin(WEBFOLDER,name + ".html")) as htmlfile:
|
||||||
|
html = htmlfile.read()
|
||||||
|
|
||||||
with open(pthjoin(WEBFOLDER,name + ".html")) as htmlfile:
|
# apply global substitutions
|
||||||
html = htmlfile.read()
|
with open(pthjoin(WEBFOLDER,"common/footer.html")) as footerfile:
|
||||||
|
footerhtml = footerfile.read()
|
||||||
# apply global substitutions
|
with open(pthjoin(WEBFOLDER,"common/header.html")) as headerfile:
|
||||||
with open(pthjoin(WEBFOLDER,"common/footer.html")) as footerfile:
|
headerhtml = headerfile.read()
|
||||||
footerhtml = footerfile.read()
|
html = html.replace("</body>",footerhtml + "</body>").replace("</head>",headerhtml + "</head>")
|
||||||
with open(pthjoin(WEBFOLDER,"common/header.html")) as headerfile:
|
|
||||||
headerhtml = headerfile.read()
|
|
||||||
html = html.replace("</body>",footerhtml + "</body>").replace("</head>",headerhtml + "</head>")
|
|
||||||
|
|
||||||
|
|
||||||
# If a python file exists, it provides the replacement dict for the html file
|
# If a python file exists, it provides the replacement dict for the html file
|
||||||
if os.path.exists(pthjoin(WEBFOLDER,name + ".py")):
|
if os.path.exists(pthjoin(WEBFOLDER,name + ".py")):
|
||||||
#txt_keys = SourceFileLoader(name,"web/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT)
|
#txt_keys = SourceFileLoader(name,"web/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT)
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(".web." + name,package="maloja")
|
module = importlib.import_module(".web." + name,package="maloja")
|
||||||
txt_keys,resources = module.instructions(keys)
|
txt_keys,resources = module.instructions(keys)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log("Error in website generation: " + str(sys.exc_info()),module="error")
|
log("Error in website generation: " + str(sys.exc_info()),module="error")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# add headers for server push
|
# add headers for server push
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
if all(ord(c) < 128 for c in resource["file"]):
|
if all(ord(c) < 128 for c in resource["file"]):
|
||||||
# we can only put ascii stuff in the http header
|
# we can only put ascii stuff in the http header
|
||||||
linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"])
|
linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"])
|
||||||
|
|
||||||
# apply key substitutions
|
# apply key substitutions
|
||||||
for k in txt_keys:
|
for k in txt_keys:
|
||||||
if isinstance(txt_keys[k],list):
|
if isinstance(txt_keys[k],list):
|
||||||
# if list, we replace each occurence with the next item
|
# if list, we replace each occurence with the next item
|
||||||
for element in txt_keys[k]:
|
for element in txt_keys[k]:
|
||||||
html = html.replace(k,element,1)
|
html = html.replace(k,element,1)
|
||||||
else:
|
else:
|
||||||
html = html.replace(k,txt_keys[k])
|
html = html.replace(k,txt_keys[k])
|
||||||
|
|
||||||
|
|
||||||
response.set_header("Link",",".join(linkheaders))
|
response.set_header("Link",",".join(linkheaders))
|
||||||
log("Generated page {name} in {time:.5f}s (Python+HTML)".format(name=name,time=clock.stop()),module="debug")
|
log("Generated page {name} in {time:.5f}s (Python+HTML)".format(name=name,time=clock.stop()),module="debug")
|
||||||
return html
|
return html
|
||||||
#return static_file("web/" + name + ".html",root="")
|
|
||||||
|
except:
|
||||||
|
abort(404, "Page does not exist")
|
||||||
|
|
||||||
|
|
||||||
# Shortlinks
|
# Shortlinks
|
||||||
|
18
maloja/web/jinja/error.jinja
Normal file
18
maloja/web/jinja/error.jinja
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{% extends "admin.jinja" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<table class="top_info">
|
||||||
|
<tr>
|
||||||
|
<td class="image">
|
||||||
|
<div style="background-image:url('/favicon.png')"></div>
|
||||||
|
</td>
|
||||||
|
<td class="text">
|
||||||
|
<h1>Error {{ errorcode }}</h1><br/>
|
||||||
|
|
||||||
|
|
||||||
|
<p>That did not work. Don't ask me why.</p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -1,28 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<title>Maloja - Error <pyhp echo="errorcode" /></title>
|
|
||||||
<pyhp include="../common/header.html" />
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<table class="top_info">
|
|
||||||
<tr>
|
|
||||||
<td class="image">
|
|
||||||
<div style="background-image:url('/favicon.png')"></div>
|
|
||||||
</td>
|
|
||||||
<td class="text">
|
|
||||||
<h1>Error <pyhp echo="errorcode" /></h1><br/>
|
|
||||||
|
|
||||||
|
|
||||||
<p>That did not work. Don't ask me why.</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user