Skip to content

Commit

Permalink
This adds a 404 page
Browse files Browse the repository at this point in the history
I personally prefer a wide banner just like GitHub in https://github.com/ghost/dummy ,
but this is good enough to have as a placeholder, feel free to overwrite me with a design.
  • Loading branch information
peregrineshahin authored and ppigazzini committed May 22, 2024
1 parent 7be6f51 commit 9875a87
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
51 changes: 51 additions & 0 deletions server/fishtest/templates/notfound.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<%inherit file="base.mak"/>

<script>
document.title = "Page not found";
</script>

<style>
.error-container {
display: flex;
justify-content: center;
align-items: center;
height: 82vh;
}
.error-content {
text-align: center;
}
.error-heading {
font-size: 6rem;
color: #343a40;
margin-bottom: 1rem;
}
.error-message {
font-size: 1.5rem;
color: #6c757d;
margin-bottom: 2rem;
}
.error-button {
display: inline-block;
padding: 0.75rem 1.5rem;
background-color: #77828f;
color: #fff;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s;
border: none;
cursor: pointer;
outline: none;
}
.error-button:hover {
background-color: #0056b3;
}
</style>

<div class="error-container">
<div class="error-content">
<h1 class="error-heading">404</h1>
<h2 class="error-message">Oops! Page not found.</h2>
<p class="lead">The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.</p>
<a href="/" class="error-button">Go to Home</a>
</div>
</div>
25 changes: 17 additions & 8 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
password_strength,
update_residuals,
)
from pyramid.httpexceptions import HTTPFound, exception_response
from pyramid.httpexceptions import HTTPFound, HTTPNotFound, exception_response
from pyramid.security import forget, remember
from pyramid.view import forbidden_view_config, view_config
from pyramid.view import forbidden_view_config, notfound_view_config, view_config
from requests.exceptions import ConnectionError, HTTPError
from vtjson import ValidationError, union, validate

Expand Down Expand Up @@ -81,6 +81,12 @@ def pagination(page_idx, num, page_size, query_params):
return pages


@notfound_view_config(renderer="notfound.mak")
def notfound_view(request):
request.response.status = 404
return {}


@view_config(route_name="home")
def home(request):
return HTTPFound(location=request.route_url("tests"))
Expand Down Expand Up @@ -585,7 +591,7 @@ def user(request):

user_data = request.userdb.get_user(user_name)
if user_data is None:
raise exception_response(404)
raise HTTPNotFound("Resource not found")
if "user" in request.POST:
if profile:
old_password = request.params.get("old_password").strip()
Expand Down Expand Up @@ -1175,7 +1181,7 @@ def tests_run(request):
if "id" in request.params:
run = request.rundb.get_run(request.params["id"])
if run is None:
raise exception_response(404)
raise HTTPNotFound("Resource not found")
run_args = copy.deepcopy(run["args"])
if "spsa" in run_args:
# needs deepcopy
Expand Down Expand Up @@ -1405,23 +1411,23 @@ def get_page_title(run):
def tests_live_elo(request):
run = request.rundb.get_run(request.matchdict["id"])
if run is None:
raise exception_response(404)
raise HTTPNotFound("Resource not found")
return {"run": run, "page_title": get_page_title(run)}


@view_config(route_name="tests_stats", renderer="tests_stats.mak")
def tests_stats(request):
run = request.rundb.get_run(request.matchdict["id"])
if run is None:
raise exception_response(404)
raise HTTPNotFound("Resource not found")
return {"run": run, "page_title": get_page_title(run)}


@view_config(route_name="tests_tasks", renderer="tasks.mak")
def tests_tasks(request):
run = request.rundb.get_run(request.matchdict["id"])
if run is None:
raise exception_response(404)
raise HTTPNotFound("Resource not found")

try:
show_task = int(request.params.get("show_task", -1))
Expand All @@ -1446,7 +1452,7 @@ def tests_machines(request):
def tests_view(request):
run = request.rundb.get_run(request.matchdict["id"])
if run is None:
raise exception_response(404)
raise HTTPNotFound("Resource not found")
follow = 1 if "follow" in request.params else 0
results = run["results"]
run["results_info"] = format_results(results, run)
Expand Down Expand Up @@ -1652,6 +1658,9 @@ def tests_user(request):
)
)
username = request.matchdict.get("username", "")
user_data = request.userdb.get_user(username)
if user_data is None:
raise HTTPNotFound("Resource not found")
response = {**get_paginated_finished_runs(request), "username": username}
page_param = request.params.get("page", "")
if not page_param.isdigit() or int(page_param) <= 1:
Expand Down

0 comments on commit 9875a87

Please sign in to comment.