Skip to content

Commit

Permalink
ietf-tools#96 Keeps top level menu and makes new editing features for…
Browse files Browse the repository at this point in the history
… secondary menu only
  • Loading branch information
edward-springload committed Nov 5, 2021
1 parent 9a61df1 commit a72b41b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 29 deletions.
12 changes: 12 additions & 0 deletions ietf/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@
def home_page():
return HomePage.objects.filter(depth=2).first()

def children(item):
return item and item.get_children().live().in_menu()

def menu():
items = children(home_page())
if items:
for item in items:
item.subitems = children(item)
return items

def secondary_menu():
items = MenuItem.objects.order_by('sort_order').all().select_related('page').prefetch_related('sub_menu_items')
return items


def global_pages(request):
return {
'HOME': home_page(),
'BLOG_INDEX': BlogIndexPage.objects.first(),
'MENU': menu(),
'SECONDARY_MENU': secondary_menu,
'BASE_URL': getattr(settings, 'BASE_URL', ""),
'DEBUG': getattr(settings, 'DEBUG', ""),
'FB_APP_ID': getattr(settings, 'FB_APP_ID', ""),
Expand Down
88 changes: 60 additions & 28 deletions ietf/templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,66 @@
<ul
class="navbar-nav col-12 col-xl-auto justify-content-xl-center flex-grow"
>
{% for item in MENU %}
<li class="nav-item btn-group {% if item.pk == self.pk %} active{% endif %}">
<a
href="{% pageurl item.page %}"
class="nav-link btn btn-dark text-white text-uppercase{% if item.sub_menu_items %} pe-1{% endif %}"
>
{{ item.title }}
</a>
{% if item.is_dropdown %}
<button
class="btn btn-dark text-light dropdown-toggle dropdown-toggle-split d-none d-lg-block ps-1 no-js-hide"
id="{{ item.pk }}Dropdown"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
aria-label="Toggle dropdown for {{ item.title }}"
title="Toggle dropdown for {{ item.title }}"
>
</button>
<ul class="dropdown-menu bg-dark" aria-labelledby="{{ item.pk }}Dropdown">
{% for subitem in item.sub_menu_items.all %}
<li class="dropdown-item position-relative{% if subitem.pk == self.pk %} active{% endif %}">
<a class="text-white stretched-link" href="{% if subitem.page %}{% pageurl subitem.page %}{% else %}{{ subitem.url }}{% endif %}">{{ subitem.title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% for item in MENU %}
<li class="nav-item btn-group {% if item.pk == self.pk %} active{% endif %}">
<a
href="{{ item.url }}"
class="nav-link btn btn-dark text-white text-uppercase{% if item.subitems %} pe-1{% endif %}"
>
{{ item.title }}
</a>
{% if item.subitems %}
<button
class="btn btn-dark text-light dropdown-toggle dropdown-toggle-split d-none d-lg-block ps-1 no-js-hide"
id="{{ item.pk }}Dropdown"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
aria-label="Toggle dropdown for {{ item.title }}"
title="Toggle dropdown for {{ item.title }}"
>
</button>
<ul class="dropdown-menu bg-dark" aria-labelledby="{{ item.pk }}Dropdown">
{% for subitem in item.subitems %}
<li class="dropdown-item position-relative{% if subitem.pk == self.pk %} active{% endif %}">
<a class="text-white stretched-link" href="{{ subitem.url }}">{{ subitem.title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>

{% endfor %}
</ul>

<ul class="navbar-nav col-12 col-xl-auto">
{% for item in SECONDARY_MENU %}
{% if item.is_dropdown %}
<li class="nav-item btn-group">
{% else %}
<li class="nav-item">
{% endif %}
<a class="nav-link btn btn-dark text-white {% if item.is_dropdown %}pe-1{% endif %}" href="{% pageurl item.page %}">{{item.title}}</a>
{% if item.is_dropdown %}
<button
class="nav-link btn btn-dark text-white dropdown-toggle dropdown-toggle-split d-none d-lg-block ps-1 no-js-hide"
id="{{ item.pk }} Dropdown"
data-bs-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
aria-label="Toggle dropdown for tools"
title="Toggle dropdown for tools"
{{ item.pk }}
></button>
<ul class="dropdown-menu dropdown-menu-right bg-dark">
{% for sub_menu in item.sub_menu_items.all %}
<li class="dropdown-item position-relative">
<a class="text-white stretched-link" href="{{ sub_menu.url}}">{{ sub_menu.title }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
<li class="nav-item d-none d-lg-inline-block">
<a
Expand Down
20 changes: 20 additions & 0 deletions ietf/utils/migrations/0003_auto_20211105_0019.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.19 on 2021-11-05 00:19

from django.db import migrations, models

def add_missing_menu(apps, schema_editor):
MenuItem = apps.get_model('utils', 'MenuItem')
Page = apps.get_model('wagtailcore', 'Page')
page = Page.objects.filter(pk=42).first()
if page:
MenuItem.objects.create(page=page, sort_order=0, text='News & blog')

class Migration(migrations.Migration):

dependencies = [
('utils', '0002_auto_20211101_0113'),
]

operations = [
migrations.RunPython(add_missing_menu)
]
3 changes: 3 additions & 0 deletions ietf/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def is_dropdown(self):
@property
def title(self):
return self.text or getattr(self.page, "title", "")

class Meta:
verbose_name_plural = "Secondary Menu"


@register_setting
Expand Down
2 changes: 1 addition & 1 deletion ietf/utils/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def editor_css():
class MenuItemAdmin(OrderableMixin, ModelAdmin):
model = MenuItem
menu_order = 900
menu_label = "Menu"
menu_label = "Secondary Menu"
menu_icon = "list-ul"
add_to_settings_menu = True
list_display = ("title",)
Expand Down

0 comments on commit a72b41b

Please sign in to comment.