Optimized navigation site_root
This commit is contained in:
parent
c2e209f17d
commit
eecb2a3446
5 changed files with 27 additions and 22 deletions
|
@ -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 }
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{% load compress static wagtailuserbar navigation information %}
|
||||
{% get_site_root as site_root %}
|
||||
{% get_site as the_site %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{% language_cur %}">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>{% 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 %}</title>
|
||||
<title>{% 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 %}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="{% block description %}{% endblock %}">
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{% load static wagtailcore_tags navigation information %}
|
||||
{% get_site_root as site_root %}
|
||||
{% get_site as the_site %}
|
||||
|
||||
<!-- Footer -->
|
||||
<footer id="footer">
|
||||
|
@ -20,18 +20,18 @@
|
|||
|
||||
<a name="contact-info"></a>
|
||||
<div class="col-md-4" id="contact-info">
|
||||
{% contact_info site_root=site_root %}
|
||||
{% contact_info the_site=the_site %}
|
||||
</div>
|
||||
<div class="col-md-4" id="contact-form">
|
||||
{% footer_form site_root=site_root %}
|
||||
{% footer_form the_site=the_site %}
|
||||
</div>
|
||||
</div><!-- /row -->
|
||||
</div><!-- /container -->
|
||||
</footer>
|
||||
|
||||
<div class="copyright">
|
||||
{% contact_name site_root=site_root %}
|
||||
© 2019
|
||||
{% contact_name the_site=the_site %}
|
||||
© 2020
|
||||
• <a href="/privacy/">Privacy</a>
|
||||
• <a href="/impressum/">Impressum</a>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% load static wagtailcore_tags navigation information %}
|
||||
{% get_site_root as site_root %}
|
||||
{% get_site as the_site %}
|
||||
|
||||
<nav class="navbar-pre navbar-fixed-top">
|
||||
<div class="container">
|
||||
|
@ -9,7 +10,7 @@
|
|||
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
|
||||
<span class="sr-only">Contact</span>
|
||||
</a>
|
||||
{% contact_links site_root=site_root %}
|
||||
{% contact_links the_site=the_site %}
|
||||
</span>
|
||||
<span class="language-nav">
|
||||
{% language_switcher %}
|
||||
|
@ -28,7 +29,7 @@
|
|||
</button>
|
||||
<a class="navbar-brand" href="{% pageurl site_root %}">
|
||||
<img src="{% static 'images/public-health-logo-sign.png' %}" alt="[logo]">
|
||||
<span class="hidden-xs">{% contact_name site_root=site_root %}</span></a>
|
||||
<span class="hidden-xs">{% contact_name the_site=the_site %}</span></a>
|
||||
</div>
|
||||
|
||||
{% block menu %}
|
||||
|
|
Loading…
Add table
Reference in a new issue