aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat_covid19
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-04-03 18:28:24 -0700
committerBryan Newbold <bnewbold@archive.org>2020-04-03 18:28:26 -0700
commitc5f018e734def3ee274f64cd8bbe2f8974810ffb (patch)
tree33693938c772b90fa36342ec8c4a12538697ee0b /fatcat_covid19
parent61e78f658bda90ff135029b1e864f6f49d9cd8f8 (diff)
downloadfatcat-covid19-c5f018e734def3ee274f64cd8bbe2f8974810ffb.tar.gz
fatcat-covid19-c5f018e734def3ee274f64cd8bbe2f8974810ffb.zip
wrangle lang_code / error templates a bit more
Still not perfect: a 404 is always in 'en' and all links are then not in the local lang.
Diffstat (limited to 'fatcat_covid19')
-rw-r--r--fatcat_covid19/templates/base.html2
-rw-r--r--fatcat_covid19/webface.py21
2 files changed, 15 insertions, 8 deletions
diff --git a/fatcat_covid19/templates/base.html b/fatcat_covid19/templates/base.html
index 37c5cab..5d57a89 100644
--- a/fatcat_covid19/templates/base.html
+++ b/fatcat_covid19/templates/base.html
@@ -50,7 +50,7 @@
<i class="dropdown icon" style="margin-left: 0.2em;"></i>
<div class="menu">
{% for lang_code, lang_name in config.SUPPORTED_LANGUAGES.items() %}
- <a class="item" href="{{ url_for(request.endpoint, lang_code=lang_code) }}">{{ lang_name }}</a>
+ <a class="item" href="{{ url_for(request.endpoint or "search.page_home", lang_code=lang_code) }}">{{ lang_name }}</a>
{% endfor %}
</div>
</div>
diff --git a/fatcat_covid19/webface.py b/fatcat_covid19/webface.py
index d645cb5..7c02301 100644
--- a/fatcat_covid19/webface.py
+++ b/fatcat_covid19/webface.py
@@ -56,8 +56,11 @@ bp = Blueprint('search', __name__)
@bp.url_defaults
def add_language_code(endpoint, values):
- if g.lang_code_set:
+ if hasattr(g, "lang_code_set") and g.lang_code_set:
values.setdefault('lang_code', g.lang_code)
+ else:
+ values.setdefault('lang_code', 'en')
+ g.lang_code = 'en'
@bp.url_value_preprocessor
def pull_lang_code(endpoint, values):
@@ -66,6 +69,10 @@ def pull_lang_code(endpoint, values):
if g.lang_code not in app.config['SUPPORTED_LANGUAGES']:
abort(404)
+@babel.localeselector
+def get_locale():
+ return g.lang_code
+
@bp.route('/', methods=['GET'])
def page_home():
return render_template('home.html')
@@ -93,18 +100,18 @@ def page_sources():
return render_template('sources_{}.html'.format(g.lang_code))
-@bp.errorhandler(404)
+@bp.app_errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
-@bp.errorhandler(400)
+@bp.app_errorhandler(400)
def page_bad_request(e):
return render_template('400.html'), 400
-@bp.errorhandler(502)
-@bp.errorhandler(503)
-@bp.errorhandler(504)
-@bp.errorhandler(500)
+@bp.app_errorhandler(502)
+@bp.app_errorhandler(503)
+@bp.app_errorhandler(504)
+@bp.app_errorhandler(500)
def page_server_error(e):
return render_template('500.html'), 500