From fd49599cc76de69e81f645257845778571d4d964 Mon Sep 17 00:00:00 2001 From: Brice Maron Date: Mon, 29 Jul 2019 22:10:58 +0200 Subject: Arrange navbar items by functions --- ihatemoney/default_settings.py | 1 + ihatemoney/run.py | 10 ++- ihatemoney/static/css/main.css | 13 ++++ ihatemoney/static/images/globe.svg | 1 + .../static/images/glyphicons-halflings-white.png | Bin 4352 -> 0 bytes ihatemoney/static/images/glyphicons-halflings.png | Bin 4352 -> 0 bytes ihatemoney/templates/layout.html | 86 ++++++++++++--------- ihatemoney/utils.py | 14 +++- ihatemoney/web.py | 7 +- 9 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 ihatemoney/static/images/globe.svg delete mode 100644 ihatemoney/static/images/glyphicons-halflings-white.png delete mode 100644 ihatemoney/static/images/glyphicons-halflings.png diff --git a/ihatemoney/default_settings.py b/ihatemoney/default_settings.py index 6033d0a..82e6a43 100644 --- a/ihatemoney/default_settings.py +++ b/ihatemoney/default_settings.py @@ -8,3 +8,4 @@ ACTIVATE_DEMO_PROJECT = True ADMIN_PASSWORD = "" ALLOW_PUBLIC_PROJECT_CREATION = True ACTIVATE_ADMIN_DASHBOARD = False +SUPPORTED_LANGUAGES = ['en', 'fr', 'nl'] diff --git a/ihatemoney/run.py b/ihatemoney/run.py index e9b3ce1..41598ce 100644 --- a/ihatemoney/run.py +++ b/ihatemoney/run.py @@ -10,7 +10,8 @@ from werkzeug.contrib.fixers import ProxyFix from ihatemoney.api import api from ihatemoney.models import db -from ihatemoney.utils import PrefixedWSGI, minimal_round, IhmJSONEncoder +from ihatemoney.utils import (IhmJSONEncoder, PrefixedWSGI, locale_from_iso, + minimal_round, static_include) from ihatemoney.web import main as web_interface from ihatemoney import default_settings @@ -135,6 +136,8 @@ def create_app(configuration=None, instance_path='/etc/ihatemoney', app.mail = mail # Jinja filters + app.jinja_env.globals['static_include'] = static_include + app.jinja_env.globals['locale_from_iso'] = locale_from_iso app.jinja_env.filters['minimal_round'] = minimal_round # Translations @@ -144,7 +147,10 @@ def create_app(configuration=None, instance_path='/etc/ihatemoney', def get_locale(): # get the lang from the session if defined, fallback on the browser "accept # languages" header. - lang = session.get('lang', request.accept_languages.best_match(['fr', 'en'])) + lang = session.get( + 'lang', + request.accept_languages.best_match(app.config['SUPPORTED_LANGUAGES']) + ) setattr(g, 'lang', lang) return lang diff --git a/ihatemoney/static/css/main.css b/ihatemoney/static/css/main.css index ae056c8..47ede77 100644 --- a/ihatemoney/static/css/main.css +++ b/ihatemoney/static/css/main.css @@ -328,3 +328,16 @@ tr:hover .extra-info { .row-fluid > .offset1 { margin-left: 8.5%; } + +.globe-europe svg { + display: inline-block; + border-bottom: 0.2em solid transparent; + height: 1.2em; + fill: rgba(255,255,255,.5) +} +.navbar-nav .dropdown-toggle:hover .globe-europe svg { + fill: rgba(255,255,255,.75); +} +.navbar-dark .navbar-nav .show > .nav-link svg { + fill: white; +} \ No newline at end of file diff --git a/ihatemoney/static/images/globe.svg b/ihatemoney/static/images/globe.svg new file mode 100644 index 0000000..5982330 --- /dev/null +++ b/ihatemoney/static/images/globe.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ihatemoney/static/images/glyphicons-halflings-white.png b/ihatemoney/static/images/glyphicons-halflings-white.png deleted file mode 100644 index a20760b..0000000 Binary files a/ihatemoney/static/images/glyphicons-halflings-white.png and /dev/null differ diff --git a/ihatemoney/static/images/glyphicons-halflings.png b/ihatemoney/static/images/glyphicons-halflings.png deleted file mode 100644 index 92d4445..0000000 Binary files a/ihatemoney/static/images/glyphicons-halflings.png and /dev/null differ diff --git a/ihatemoney/templates/layout.html b/ihatemoney/templates/layout.html index 84e75b4..10bb628 100644 --- a/ihatemoney/templates/layout.html +++ b/ihatemoney/templates/layout.html @@ -28,56 +28,72 @@
-
diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index 2fac4ef..393667e 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -1,13 +1,15 @@ from __future__ import division import base64 import re +import os import ast import operator from io import BytesIO, StringIO import jinja2 from json import dumps, JSONEncoder -from flask import redirect +from flask import redirect, current_app +from babel import Locale from werkzeug.routing import HTTPException, RoutingException import six from datetime import datetime, timedelta @@ -93,6 +95,16 @@ def minimal_round(*args, **kw): return (res if res != ires else ires) +def static_include(filename): + fullpath = os.path.join(current_app.static_folder, filename) + with open(fullpath, 'r') as f: + return f.read() + + +def locale_from_iso(iso_code): + return Locale(iso_code) + + def list_of_dicts2json(dict_to_convert): """Take a list of dictionnaries and turns it into a json in-memory file diff --git a/ihatemoney/web.py b/ihatemoney/web.py index f6f04af..b70bc5f 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -343,7 +343,12 @@ def edit_project(): edit_form.name.data = g.project.name edit_form.contact_email.data = g.project.contact_email - return render_template("edit_project.html", edit_form=edit_form, export_form=export_form) + return render_template( + "edit_project.html", + edit_form=edit_form, + export_form=export_form, + current_view="edit_project" + ) @main.route("//delete") -- cgit v1.1