Merge branch 'feature/error_pages' into 'master'

Added customization for error pages

See merge request caimira/caimira!438
This commit is contained in:
Andre Henriques 2023-04-14 09:35:50 +02:00
commit 249ecff5cc
7 changed files with 44 additions and 15 deletions

View file

@ -57,16 +57,9 @@ class BaseRequestHandler(RequestHandler):
def write_error(self, status_code: int, **kwargs) -> None:
template = self.settings["template_environment"].get_template(
"page.html.j2")
"error.html.j2")
error_id = uuid.uuid4()
contents = (
f'Unfortunately an error occurred when processing your request. '
f'Please let us know about this issue with as much detail as possible at '
f'<a href="mailto:CAiMIRA-dev@cern.ch">CAiMIRA-dev@cern.ch</a>, reporting status '
f'code {status_code}, the error id of "{error_id}" and the time of the '
f'request ({datetime.datetime.utcnow()}).<br><br><br><br>'
)
# Print the error to the log (and not to the browser!)
if "exc_info" in kwargs:
print(f"ERROR UUID {error_id}")
@ -76,7 +69,9 @@ class BaseRequestHandler(RequestHandler):
get_url = template.globals['get_url'],
get_calculator_url = template.globals["get_calculator_url"],
active_page='Error',
contents=contents
error_id=error_id,
status_code=status_code,
datetime=datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"),
))
@ -85,13 +80,13 @@ class Missing404Handler(BaseRequestHandler):
await super().prepare()
self.set_status(404)
template = self.settings["template_environment"].get_template(
"page.html.j2")
"error.html.j2")
self.finish(template.render(
user=self.current_user,
get_url = template.globals['get_url'],
get_calculator_url = template.globals["get_calculator_url"],
active_page='Error',
contents='Unfortunately the page you were looking for does not exist.<br><br><br><br>'
status_code=404,
))

View file

@ -15,10 +15,13 @@ p {
}
/*-- Body Reset --*/
body {
html, body {
/* overflow-x: hidden */
font-family: 'Montserrat', sans-serif;
color: rgb(47, 72, 88);
display: flex;
flex-direction: column;
height: 100%;
}
/*============= TOP BAR HEADER =============*/
@ -186,6 +189,17 @@ body {
margin-right: 10px;
}
.btn-caimira-color{
color: rgb(42, 52, 66);
border-color: rgb(42, 52, 66);
}
.btn-caimira-color:hover{
color: white;
background-color: rgb(42, 52, 66);
}
/*===== FIXED BACKGROUND IMG =====*/
.fixed-background {

View file

@ -63,5 +63,5 @@ Although the user is able to calculate the infection probability of a stand-alon
<div class="text-component text-component-page clearfix"></div>
<br>
</div>
</div>
{% endblock main %}

View file

@ -651,6 +651,7 @@
{{ text_blocks['Disclaimer'] }}
{% endblock disclaimer %}
</div>
<br>
{% endblock disclaimer_container %}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

View file

@ -81,7 +81,7 @@
{% endblock main %}
</main>
<footer>
<footer style="margin-top: auto">
<div class="container">
<div class="row text-light text-center py-4 justify-content-center">

View file

@ -0,0 +1,19 @@
{% extends "base/layout.html.j2" %}
{% block main %}
<div class="container container--padding" style="word-wrap:break-word" ;>
<h1>Error {{ status_code }}.</h1><br>
{% if status_code == 404 %}
<h2>Unfortunately the page you are looking for does not exist.</h2>
{% else %}
<br><h2>Unfortunately an error occurred when processing your request.</h2><br>
<p>
Please let us know about this issue with as much detail as possible at <a href="mailto:CAiMIRA-dev@cern.ch">CAiMIRA-dev@cern.ch</a>,
reporting status code <b>{{ status_code }}</b>, the error id of "<b>{{ error_id }}</b>" and the time of the request (<b>{{ datetime }}</b>).
</p>
{% endif %}
<br><br><br>
<div class="text-center"><a href="{{ get_url() }}/" class="btn btn-lg btn-caimira-color" role="button">HOME PAGE</a></div><br><br><br>
</div>
{% endblock main %}

View file

@ -43,7 +43,7 @@ REQUIREMENTS: dict = {
'test': [
'pytest',
'pytest-mypy != v0.10.1',
'mypy != 1.1.1',
'mypy < 1.1.1',
'pytest-tornasync',
'numpy-stubs @ git+https://github.com/numpy/numpy-stubs.git',
'types-dataclasses',