From c03ecd1afcb805ca87b7029b95db882dd92d669a Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Wed, 24 Jul 2013 20:45:28 -0400 Subject: [PATCH] New 404 page. Hooray, no more boring ones! --- xonstat/__init__.py | 7 +++++- xonstat/templates/404.mako | 48 +++++++++++++++++++++++++++++++++++++ xonstat/views/__init__.py | 2 ++ xonstat/views/exceptions.py | 5 ++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 xonstat/templates/404.mako create mode 100644 xonstat/views/exceptions.py diff --git a/xonstat/__init__.py b/xonstat/__init__.py index 728426d..7cdbe29 100644 --- a/xonstat/__init__.py +++ b/xonstat/__init__.py @@ -1,6 +1,7 @@ import sqlahelper from pyramid_beaker import set_cache_regions_from_settings from pyramid.config import Configurator +from pyramid.httpexceptions import HTTPNotFound from pyramid.renderers import JSONP from sqlalchemy import engine_from_config from xonstat.models import initialize_db @@ -21,9 +22,13 @@ def main(global_config, **settings): config = Configurator(settings=settings) + config.add_renderer('jsonp', JSONP(param_name='callback')) + + # for static assets config.add_static_view('static', 'xonstat:static') - config.add_renderer('jsonp', JSONP(param_name='callback')) + # for 404s + config.add_view(notfound, context=HTTPNotFound, renderer="404.mako") # ROOT ROUTE config.add_route("main_index", "/") diff --git a/xonstat/templates/404.mako b/xonstat/templates/404.mako new file mode 100644 index 0000000..9e1b150 --- /dev/null +++ b/xonstat/templates/404.mako @@ -0,0 +1,48 @@ +<%inherit file="base.mako"/> +<%namespace name="nav" file="nav.mako" /> + +<%block name="navigation"> +${nav.nav('games')} + + +

HTTP 404

+ +% if 0 <= rand < 30: +

Well this is awkward...I couldn't find what you were looking for!

+

(better get back to playing then, hm?)

+% endif + +% if 30 <= rand < 40: +

Whoa there! Looks like you've taken a wrong turn.

+

(no one tries to get on highway 404, no one.)

+% endif + +% if 40 <= rand < 50: +

There's nothing to see here. *waves hand*

+

(did Mirio put you up to this?)

+% endif + +% if 50 <= rand < 60: +

Hey, you! Watch out - kojn's behind you!

+

(he killed this page, apparently)

+% endif + +% if 60 <= rand < 70: +

Samual must have destroyed this page.

+

(it wasn't pulling its own weight anyway)

+% endif + +% if 70 <= rand < 80: +

divVerent has encrypted this page so hard you'll never decipher it.

+

(either that or you've hit the wrong page or something)

+% endif + +% if 80 <= rand < 90: +

merlijn was unhappy with this page, so he removed it from the server.

+

(after yelling at me about it, of course)

+% endif + +% if 90 <= rand <= 100: +

Morphed is modeling this page. It's gonna be awesome.

+

(until then, you'll probably want to get in a game or two)

+% endif diff --git a/xonstat/views/__init__.py b/xonstat/views/__init__.py index f238d7a..d88a139 100644 --- a/xonstat/views/__init__.py +++ b/xonstat/views/__init__.py @@ -22,4 +22,6 @@ from xonstat.views.server import server_index_json from xonstat.views.search import search_q, search from xonstat.views.search import search_json +from xonstat.views.exceptions import notfound + from xonstat.views.main import main_index diff --git a/xonstat/views/exceptions.py b/xonstat/views/exceptions.py new file mode 100644 index 0000000..0cc9148 --- /dev/null +++ b/xonstat/views/exceptions.py @@ -0,0 +1,5 @@ +import logging +import random + +def notfound(request): + return {'rand': int(random.random() * 100)} -- 2.39.2