Add a handler when pages aren't found. (#379)

Fixes #356
This commit is contained in:
Alexis Metaireau 2018-09-03 20:54:07 +02:00 committed by GitHub
parent 24e0d8348f
commit 6ab92ddbac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 16 deletions

View file

@ -182,6 +182,12 @@ msgstr ""
msgid "The bill has been modified"
msgstr ""
msgid "Sorry, we were unable to find the page you've asked for."
msgstr ""
msgid "The best thing to do is probably to get back to the main page."
msgstr ""
msgid "Back to the list"
msgstr ""

View file

@ -2,7 +2,7 @@ import os
import os.path
import warnings
from flask import Flask, g, request, session
from flask import Flask, g, request, session, render_template
from flask_babel import Babel
from flask_mail import Mail
from flask_migrate import Migrate, upgrade, stamp
@ -102,6 +102,10 @@ def validate_configuration(app):
)
def page_not_found(e):
return render_template('404.html', root="main"), 404
def create_app(configuration=None, instance_path='/etc/ihatemoney',
instance_relative_config=True):
app = Flask(
@ -121,8 +125,9 @@ def create_app(configuration=None, instance_path='/etc/ihatemoney',
validate_configuration(app)
app.register_blueprint(web_interface)
app.register_blueprint(api)
app.register_error_handler(404, page_not_found)
# Configure the application
# Configure the a, root="main"pplication
setup_database(app)
mail = Mail()

View file

@ -0,0 +1,13 @@
{% extends "layout.html" %}
{% block body %}
<header id="header" class="row">
<div class="col-xs-12 col-sm-5 offset-md-2">
<h2>{{ _("Sorry, we were unable to find the page you've asked for.") }}</h2>
</div>
</header>
<main class="row home">
<div class="col-xs-12 col-sm-5 col-md-4 offset-md-2">
<a href='{{ url_for("main.home") }}'>{{ _("The best thing to do is probably to get back to the main page.")}}</a>
</div>
{% endblock %}

View file

@ -32,13 +32,13 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggler">
<h1><a class="navbar-brand" href="{{ url_for(".home") }}">#! money?</a></h1>
<h1><a class="navbar-brand" href="{{ url_for("main.home") }}">#! money?</a></h1>
<ul class="navbar-nav ml-auto mr-auto">
{% if g.project %}
{% block navbar %}
<li class="nav-item{% if current_view == 'list_bills' %} active{% endif %}"><a class="nav-link" href="{{ url_for(".list_bills") }}">{{ _("Bills") }}</a></li>
<li class="nav-item{% if current_view == 'settle_bill' %} active{% endif %}"><a class="nav-link" href="{{ url_for(".settle_bill") }}">{{ _("Settle") }}</a></li>
<li class="nav-item{% if current_view == 'statistics' %} active{% endif %}"><a class="nav-link" href="{{ url_for(".statistics") }}">{{ _("Statistics") }}</a></li>
<li class="nav-item{% if current_view == 'list_bills' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.list_bills") }}">{{ _("Bills") }}</a></li>
<li class="nav-item{% if current_view == 'settle_bill' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.settle_bill") }}">{{ _("Settle") }}</a></li>
<li class="nav-item{% if current_view == 'statistics' %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.statistics") }}">{{ _("Statistics") }}</a></li>
{% endblock %}
{% endif %}
</ul>
@ -47,23 +47,23 @@
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><strong>{{ g.project.name }}</strong> {{ _("options") }} <b class="caret"></b></a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="{{ url_for(".edit_project") }}">{{ _("Project settings") }}</a></li>
<li><a class="dropdown-item" href="{{ url_for("main.edit_project") }}">{{ _("Project settings") }}</a></li>
<li class="dropdown-divider"></li>
{% for id, name in session['projects'] %}
{% if id != g.project.id %}
<li><a class="dropdown-item" href="{{ url_for(".list_bills", project_id=id) }}">{{ _("switch to") }} {{ name }}</a></li>
<li><a class="dropdown-item" href="{{ url_for("main.list_bills", project_id=id) }}">{{ _("switch to") }} {{ name }}</a></li>
{% endif %}
{% endfor %}
<li><a class="dropdown-item" href="{{ url_for(".create_project") }}">{{ _("Start a new project") }}</a></li>
<li><a class="dropdown-item" href="{{ url_for("main.create_project") }}">{{ _("Start a new project") }}</a></li>
<li class="dropdown-divider"></li>
<li><a class="dropdown-item" href="{{ url_for(".exit") }}">{{ _("Logout") }}</a></li>
<li><a class="dropdown-item" href="{{ url_for("main.exit") }}">{{ _("Logout") }}</a></li>
</ul>
</li>
{% endif %}
<li class="nav-item{% if g.lang == "fr" %} active{% endif %}"><a class="nav-link" href="{{ url_for(".change_lang", lang="fr") }}">fr</a></li>
<li class="nav-item{% if g.lang == "en" %} active{% endif %}"><a class="nav-link" href="{{ url_for(".change_lang", lang="en") }}">en</a></li>
<li class="nav-item{% if g.lang == "fr" %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.change_lang", lang="fr") }}">fr</a></li>
<li class="nav-item{% if g.lang == "en" %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.change_lang", lang="en") }}">en</a></li>
{% if g.show_admin_dashboard_link %}
<li class="nav-item{% if request.url_rule.endpoint == "main.dashboard" %} active{% endif %}"><a class="nav-link" href="{{ url_for(".dashboard") }}">{{ _("Dashboard") }}</a></li>
<li class="nav-item{% if request.url_rule.endpoint == "main.dashboard" %} active{% endif %}"><a class="nav-link" href="{{ url_for("main.dashboard") }}">{{ _("Dashboard") }}</a></li>
{% endif %}
</ul>
</div>

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-16 23:26+0200\n"
"POT-Creation-Date: 2018-08-05 23:41+0200\n"
"PO-Revision-Date: 2018-05-15 22:00+0200\n"
"Last-Translator: Adrien CLERC <>\n"
"Language: fr\n"
@ -16,7 +16,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.6.0\n"
msgid "Project name"
msgstr "Nom de projet"
@ -210,6 +210,12 @@ msgstr "La facture a été supprimée"
msgid "The bill has been modified"
msgstr "La facture a été modifiée"
msgid "Sorry, we were unable to find the page you've asked for."
msgstr "Navré, nous ne trouvons pas la page que vous avez demandé."
msgid "The best thing to do is probably to get back to the main page."
msgstr "Votre meilleure piste est probablement la page d'accueil."
msgid "Back to the list"
msgstr "Retourner à la liste"
@ -488,4 +494,3 @@ msgstr "Solde"
#~ msgid "Invite"
#~ msgstr "Invitez"