diff --git a/publichealth/home/templatetags/information.py b/publichealth/home/templatetags/information.py index 76e6e61..133a7ea 100644 --- a/publichealth/home/templatetags/information.py +++ b/publichealth/home/templatetags/information.py @@ -6,12 +6,11 @@ from ..models.snippets import Contact, SocialContact register = template.Library() -def get_contacts(site_root): - if not site_root: return {} - site = site_root.get_site() +def get_contacts(the_site): + if not the_site: return {} # Selected or default contact snippet - top_contact = Contact.objects.filter(home_site=site) + top_contact = Contact.objects.filter(home_site=the_site) if top_contact.exists(): top_contact = top_contact.first() else: @@ -22,7 +21,7 @@ def get_contacts(site_root): top_contact = Contact.objects.first() # Selected or default social contact snippet - social_contacts = SocialContact.objects.filter(home_site=site) + social_contacts = SocialContact.objects.filter(home_site=the_site) if social_contacts.exists(): social_contacts = social_contacts.all() else: @@ -38,24 +37,24 @@ def get_contacts(site_root): # Contact information (footer) @register.inclusion_tag('tags/contact_info.html') -def contact_info(site_root): - return get_contacts(site_root) +def contact_info(the_site): + return get_contacts(the_site) # Contact form (footer) @register.inclusion_tag('tags/footer_form.html') -def footer_form(site_root): - cc = get_contacts(site_root) +def footer_form(the_site): + cc = get_contacts(the_site) if cc['contact']: return { 'form': cc['contact'].contact_form } return None # Contact links (header) @register.inclusion_tag('tags/contact_links.html') -def contact_links(site_root): - return get_contacts(site_root) +def contact_links(the_site): + return get_contacts(the_site) # Styled contact name (header) @register.inclusion_tag('tags/contact_name.html') -def contact_name(site_root, html=True): - contactname = get_contacts(site_root)['contact'] +def contact_name(the_site, html=True): + contactname = get_contacts(the_site)['contact'] return { 'contact': contactname, 'html': html } diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index be2ebce..b94c7df 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -33,11 +33,15 @@ def language_switcher(context): 'request': context['request'], } +@register.simple_tag(takes_context=True) +def get_site(context): + return context['request'].site + @register.simple_tag(takes_context=True) def get_site_root(context): # NB this returns a core.Page, not the implementation-specific model used # so object-comparison to self will return false as objects would differ - return context['request'].site.root_page + return get_site(context).root_page def has_menu_children(page): return page.get_children().live().in_menu().exists() diff --git a/publichealth/templates/base.html b/publichealth/templates/base.html index 2f85b72..f867fba 100644 --- a/publichealth/templates/base.html +++ b/publichealth/templates/base.html @@ -1,11 +1,12 @@ {% load compress static wagtailuserbar navigation information %} {% get_site_root as site_root %} +{% get_site as the_site %} - {% 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 %} + {% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{% if page.trans_title %}{{ page.trans_title }} - {% endif %}{% contact_name the_site=the_site html=False %}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %} diff --git a/publichealth/templates/footer.html b/publichealth/templates/footer.html index b899709..63adb4e 100644 --- a/publichealth/templates/footer.html +++ b/publichealth/templates/footer.html @@ -1,5 +1,5 @@ {% load static wagtailcore_tags navigation information %} -{% get_site_root as site_root %} +{% get_site as the_site %} diff --git a/publichealth/templates/header.html b/publichealth/templates/header.html index 2a95ba6..2f4033f 100644 --- a/publichealth/templates/header.html +++ b/publichealth/templates/header.html @@ -1,5 +1,6 @@ {% load static wagtailcore_tags navigation information %} {% get_site_root as site_root %} +{% get_site as the_site %}