From 1d8d8d019dd784f7a638fbffaf442c1b7842eec6 Mon Sep 17 00:00:00 2001 From: Oleg Lavrovsky Date: Fri, 22 Jun 2018 15:06:59 +0200 Subject: [PATCH] Improved language handling --- publichealth/home/templates/tags/contact_name.html | 2 +- publichealth/home/templatetags/information.py | 5 +++-- publichealth/home/util.py | 7 +++++-- publichealth/templates/base.html | 5 +++-- publichealth/templates/footer.html | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/publichealth/home/templates/tags/contact_name.html b/publichealth/home/templates/tags/contact_name.html index 91b73c6..0ed2b54 100644 --- a/publichealth/home/templates/tags/contact_name.html +++ b/publichealth/home/templates/tags/contact_name.html @@ -1 +1 @@ -{{ contact.trans_title_styled|safe }} +{% if html %}{{ contact.trans_title_styled|safe }}{% else %}{{ contact.trans_title }}{% endif %} diff --git a/publichealth/home/templatetags/information.py b/publichealth/home/templatetags/information.py index 54151a9..91cd9e8 100644 --- a/publichealth/home/templatetags/information.py +++ b/publichealth/home/templatetags/information.py @@ -44,5 +44,6 @@ def contact_links(site_root): # Styled contact name (header) @register.inclusion_tag('tags/contact_name.html') -def contact_name(site_root): - return { 'contact': get_contacts(site_root)['contact'] } +def contact_name(site_root, html=True): + contactname = get_contacts(site_root)['contact'] + return { 'contact': contactname, 'html': html } diff --git a/publichealth/home/util.py b/publichealth/home/util.py index 4b03c5d..26c5f6f 100644 --- a/publichealth/home/util.py +++ b/publichealth/home/util.py @@ -8,8 +8,11 @@ class TranslatedField(object): def __get__(self, instance, owner): if translation.get_language() == 'fr': - return getattr(instance, self.fr_field) + val = getattr(instance, self.fr_field) elif translation.get_language() == 'en': - return getattr(instance, self.en_field) + val = getattr(instance, self.en_field) else: return getattr(instance, self.de_field) + if not val: + return getattr(instance, self.de_field) + return val diff --git a/publichealth/templates/base.html b/publichealth/templates/base.html index 0e2235a..1a8a3c1 100644 --- a/publichealth/templates/base.html +++ b/publichealth/templates/base.html @@ -1,10 +1,11 @@ -{% load compress static wagtailuserbar %} +{% load compress static wagtailuserbar navigation information %} +{% get_site_root as site_root %} - {% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %} + {% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{% if page.trans_title %}{{ page.trans_title }} - {% endif %}{% contact_name site_root=site_root html=False %}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %} diff --git a/publichealth/templates/footer.html b/publichealth/templates/footer.html index 43e7b0e..909cd92 100644 --- a/publichealth/templates/footer.html +++ b/publichealth/templates/footer.html @@ -30,8 +30,8 @@