From 92e2dc4e01e804503fbd7e4529f4bd7e3b8f3bcf Mon Sep 17 00:00:00 2001 From: Nico Picchio Date: Wed, 11 Dec 2024 10:40:53 +0000 Subject: [PATCH 1/7] adds nav prototype --- src/config/settings/base.py | 1 + src/core/templates/includes/header.html | 8 +- src/navigation_prototype/__init__.py | 0 .../migrations/0001_initial.py | 77 ++++++++++++++++++ ...alter_nav_options_remove_nav_sort_order.py | 21 +++++ .../0003_alter_navlink_navigation.py | 24 ++++++ ...navlink_secondarynavlink_delete_navlink.py | 81 +++++++++++++++++++ ...0005_alter_secondarynavlink_parent_link.py | 25 ++++++ ...ink_page_secondarynavlink_page_and_more.py | 47 +++++++++++ .../migrations/__init__.py | 0 src/navigation_prototype/models.py | 63 +++++++++++++++ .../navigation_prototype/navigation.html | 69 ++++++++++++++++ .../templatetags/nav_proto.py | 17 ++++ src/navigation_prototype/wagtail_hooks.py | 14 ++++ 14 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 src/navigation_prototype/__init__.py create mode 100644 src/navigation_prototype/migrations/0001_initial.py create mode 100644 src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py create mode 100644 src/navigation_prototype/migrations/0003_alter_navlink_navigation.py create mode 100644 src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py create mode 100644 src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py create mode 100644 src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py create mode 100644 src/navigation_prototype/migrations/__init__.py create mode 100644 src/navigation_prototype/models.py create mode 100644 src/navigation_prototype/templates/navigation_prototype/navigation.html create mode 100644 src/navigation_prototype/templatetags/nav_proto.py create mode 100644 src/navigation_prototype/wagtail_hooks.py diff --git a/src/config/settings/base.py b/src/config/settings/base.py index 0a38a39ea..6e006d6e6 100644 --- a/src/config/settings/base.py +++ b/src/config/settings/base.py @@ -139,6 +139,7 @@ def filter_transactions(event, hint): "peoplefinder.apps.PeoplefinderConfig", "countries.apps.CountriesConfig", "interactions.apps.InteractionsConfig", + "navigation_prototype", ] THIRD_PARTY_APPS = [ diff --git a/src/core/templates/includes/header.html b/src/core/templates/includes/header.html index 5fc184148..5ed5cc8a7 100644 --- a/src/core/templates/includes/header.html +++ b/src/core/templates/includes/header.html @@ -1,4 +1,4 @@ -{% load menu_tags waffle_tags %} +{% load menu_tags waffle_tags nav_proto %} {% load render_bundle webpack_static from webpack_loader %} {% load site_alert %} @@ -29,7 +29,11 @@ hidden>Menu {% if USER_IS_AUTHENTICATED %} {% endif %} diff --git a/src/navigation_prototype/__init__.py b/src/navigation_prototype/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/navigation_prototype/migrations/0001_initial.py b/src/navigation_prototype/migrations/0001_initial.py new file mode 100644 index 000000000..59b72314a --- /dev/null +++ b/src/navigation_prototype/migrations/0001_initial.py @@ -0,0 +1,77 @@ +# Generated by Django 4.2.16 on 2024-12-10 16:44 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="Nav", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "sort_order", + models.IntegerField(blank=True, editable=False, null=True), + ), + ], + options={ + "ordering": ["sort_order"], + "abstract": False, + }, + ), + migrations.CreateModel( + name="NavLink", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "sort_order", + models.IntegerField(blank=True, editable=False, null=True), + ), + ("label", models.CharField(max_length=255)), + ("url", models.CharField(max_length=255)), + ( + "navigation", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="links", + to="navigation_prototype.nav", + ), + ), + ( + "parent_link", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="child_links", + to="navigation_prototype.navlink", + ), + ), + ], + options={ + "ordering": ["sort_order"], + "abstract": False, + }, + ), + ] diff --git a/src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py b/src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py new file mode 100644 index 000000000..cedcb9a12 --- /dev/null +++ b/src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.16 on 2024-12-10 16:47 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("navigation_prototype", "0001_initial"), + ] + + operations = [ + migrations.AlterModelOptions( + name="nav", + options={}, + ), + migrations.RemoveField( + model_name="nav", + name="sort_order", + ), + ] diff --git a/src/navigation_prototype/migrations/0003_alter_navlink_navigation.py b/src/navigation_prototype/migrations/0003_alter_navlink_navigation.py new file mode 100644 index 000000000..2c58d8378 --- /dev/null +++ b/src/navigation_prototype/migrations/0003_alter_navlink_navigation.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.16 on 2024-12-10 16:49 + +from django.db import migrations +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ("navigation_prototype", "0002_alter_nav_options_remove_nav_sort_order"), + ] + + operations = [ + migrations.AlterField( + model_name="navlink", + name="navigation", + field=modelcluster.fields.ParentalKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="links", + to="navigation_prototype.nav", + ), + ), + ] diff --git a/src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py b/src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py new file mode 100644 index 000000000..c8caa3ab1 --- /dev/null +++ b/src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py @@ -0,0 +1,81 @@ +# Generated by Django 4.2.16 on 2024-12-10 16:52 + +from django.db import migrations, models +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ("navigation_prototype", "0003_alter_navlink_navigation"), + ] + + operations = [ + migrations.CreateModel( + name="PrimaryNavLink", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "sort_order", + models.IntegerField(blank=True, editable=False, null=True), + ), + ("label", models.CharField(max_length=255)), + ("url", models.CharField(max_length=255)), + ( + "navigation", + modelcluster.fields.ParentalKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="links", + to="navigation_prototype.nav", + ), + ), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="SecondaryNavLink", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "sort_order", + models.IntegerField(blank=True, editable=False, null=True), + ), + ("label", models.CharField(max_length=255)), + ("url", models.CharField(max_length=255)), + ( + "parent_link", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="child_links", + to="navigation_prototype.primarynavlink", + ), + ), + ], + options={ + "abstract": False, + }, + ), + migrations.DeleteModel( + name="NavLink", + ), + ] diff --git a/src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py b/src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py new file mode 100644 index 000000000..e0cd302e0 --- /dev/null +++ b/src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.16 on 2024-12-10 16:53 + +from django.db import migrations +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ("navigation_prototype", "0004_primarynavlink_secondarynavlink_delete_navlink"), + ] + + operations = [ + migrations.AlterField( + model_name="secondarynavlink", + name="parent_link", + field=modelcluster.fields.ParentalKey( + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="child_links", + to="navigation_prototype.primarynavlink", + ), + ), + ] diff --git a/src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py b/src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py new file mode 100644 index 000000000..d0a562f71 --- /dev/null +++ b/src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py @@ -0,0 +1,47 @@ +# Generated by Django 4.2.16 on 2024-12-10 17:06 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailcore", "0094_alter_page_locale"), + ("navigation_prototype", "0005_alter_secondarynavlink_parent_link"), + ] + + operations = [ + migrations.AddField( + model_name="primarynavlink", + name="page", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailcore.page", + ), + ), + migrations.AddField( + model_name="secondarynavlink", + name="page", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailcore.page", + ), + ), + migrations.AlterField( + model_name="primarynavlink", + name="url", + field=models.URLField(blank=True, null=True), + ), + migrations.AlterField( + model_name="secondarynavlink", + name="url", + field=models.URLField(blank=True, null=True), + ), + ] diff --git a/src/navigation_prototype/migrations/__init__.py b/src/navigation_prototype/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/navigation_prototype/models.py b/src/navigation_prototype/models.py new file mode 100644 index 000000000..7cd10f236 --- /dev/null +++ b/src/navigation_prototype/models.py @@ -0,0 +1,63 @@ +from django.db import models +from modelcluster.fields import ParentalKey +from modelcluster.models import ClusterableModel +from wagtail.admin.panels import PageChooserPanel +from wagtail.models import Orderable +from wagtail.snippets.models import register_snippet + +from core.panels import FieldPanel, InlinePanel + + +@register_snippet +class Nav(ClusterableModel): + panels = [ + InlinePanel("links", label="Links", min_num=1), + ] + +class NavLinkBase(Orderable): + label = models.CharField(max_length=255) + url = models.URLField(null=True, blank=True) + page = models.ForeignKey( + "wagtailcore.Page", + null=True, + blank=True, + on_delete=models.PROTECT, + related_name="+", + ) + + def get_url(self): + if self.page: + return self.page.get_full_url() + return self.url + + def __str__(self): + return self.label + + panels = [ + FieldPanel("label"), + FieldPanel("url"), + PageChooserPanel("page"), + ] + + class Meta: + abstract = True + + +class PrimaryNavLink(ClusterableModel, NavLinkBase): + navigation = ParentalKey( + "Nav", + on_delete=models.PROTECT, + related_name="links", + ) + + panels = NavLinkBase.panels + [ + InlinePanel("child_links", label="Sub links"), + ] + +class SecondaryNavLink(NavLinkBase): + parent_link = ParentalKey( + "PrimaryNavLink", + on_delete=models.PROTECT, + null=True, + related_name="child_links", + ) \ No newline at end of file diff --git a/src/navigation_prototype/templates/navigation_prototype/navigation.html b/src/navigation_prototype/templates/navigation_prototype/navigation.html new file mode 100644 index 000000000..169c2fe60 --- /dev/null +++ b/src/navigation_prototype/templates/navigation_prototype/navigation.html @@ -0,0 +1,69 @@ + + + + \ No newline at end of file diff --git a/src/navigation_prototype/templatetags/nav_proto.py b/src/navigation_prototype/templatetags/nav_proto.py new file mode 100644 index 000000000..db6966938 --- /dev/null +++ b/src/navigation_prototype/templatetags/nav_proto.py @@ -0,0 +1,17 @@ +from django import template + +from navigation_prototype.models import Nav + +register = template.Library() + + +@register.inclusion_tag("navigation_prototype/navigation.html") +def nav_proto(): + try: + nav = Nav.objects.first() + except Nav.DoesNotExist: + return {} + + return { + "primary_links": nav.links.all(), + } diff --git a/src/navigation_prototype/wagtail_hooks.py b/src/navigation_prototype/wagtail_hooks.py new file mode 100644 index 000000000..1005d6347 --- /dev/null +++ b/src/navigation_prototype/wagtail_hooks.py @@ -0,0 +1,14 @@ +from wagtail_modeladmin.options import ModelAdmin, modeladmin_register + +from navigation_prototype.models import Nav + + +class NavAdmin(ModelAdmin): + model = Nav + menu_label = "Prototype nav" + menu_icon = "link" + menu_order = 200 + add_to_settings_menu = False + exclude_from_explorer = False + +modeladmin_register(NavAdmin) From 26006947054a0da983ba8c696c274db49e536e57 Mon Sep 17 00:00:00 2001 From: Nico Picchio Date: Wed, 11 Dec 2024 10:42:00 +0000 Subject: [PATCH 2/7] runs linter --- src/navigation_prototype/models.py | 6 ++++-- .../templates/navigation_prototype/navigation.html | 6 ++++-- src/navigation_prototype/templatetags/nav_proto.py | 1 + src/navigation_prototype/wagtail_hooks.py | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/navigation_prototype/models.py b/src/navigation_prototype/models.py index 7cd10f236..bea558574 100644 --- a/src/navigation_prototype/models.py +++ b/src/navigation_prototype/models.py @@ -14,6 +14,7 @@ class Nav(ClusterableModel): InlinePanel("links", label="Links", min_num=1), ] + class NavLinkBase(Orderable): label = models.CharField(max_length=255) url = models.URLField(null=True, blank=True) @@ -54,10 +55,11 @@ class PrimaryNavLink(ClusterableModel, NavLinkBase): InlinePanel("child_links", label="Sub links"), ] -class SecondaryNavLink(NavLinkBase): + +class SecondaryNavLink(NavLinkBase): parent_link = ParentalKey( "PrimaryNavLink", on_delete=models.PROTECT, null=True, related_name="child_links", - ) \ No newline at end of file + ) diff --git a/src/navigation_prototype/templates/navigation_prototype/navigation.html b/src/navigation_prototype/templates/navigation_prototype/navigation.html index 169c2fe60..26f03b75e 100644 --- a/src/navigation_prototype/templates/navigation_prototype/navigation.html +++ b/src/navigation_prototype/templates/navigation_prototype/navigation.html @@ -6,7 +6,9 @@ {% if l.child_links.exists %} {% endif %} @@ -66,4 +68,4 @@ .nav-proto-ul li ul li a:hover { background-color: #f0f0f0; } - \ No newline at end of file + diff --git a/src/navigation_prototype/templatetags/nav_proto.py b/src/navigation_prototype/templatetags/nav_proto.py index db6966938..4548e7bc0 100644 --- a/src/navigation_prototype/templatetags/nav_proto.py +++ b/src/navigation_prototype/templatetags/nav_proto.py @@ -2,6 +2,7 @@ from navigation_prototype.models import Nav + register = template.Library() diff --git a/src/navigation_prototype/wagtail_hooks.py b/src/navigation_prototype/wagtail_hooks.py index 1005d6347..ec864c99a 100644 --- a/src/navigation_prototype/wagtail_hooks.py +++ b/src/navigation_prototype/wagtail_hooks.py @@ -11,4 +11,5 @@ class NavAdmin(ModelAdmin): add_to_settings_menu = False exclude_from_explorer = False + modeladmin_register(NavAdmin) From 57cd615991db4d6aacb99948f17f4faf0cdca6f7 Mon Sep 17 00:00:00 2001 From: Nico Picchio Date: Wed, 11 Dec 2024 12:00:37 +0000 Subject: [PATCH 3/7] squash all migrations into one --- .../migrations/0001_initial.py | 62 +++++++++++--- ...alter_nav_options_remove_nav_sort_order.py | 21 ----- .../0003_alter_navlink_navigation.py | 24 ------ ...navlink_secondarynavlink_delete_navlink.py | 81 ------------------- ...0005_alter_secondarynavlink_parent_link.py | 25 ------ ...ink_page_secondarynavlink_page_and_more.py | 47 ----------- 6 files changed, 51 insertions(+), 209 deletions(-) delete mode 100644 src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py delete mode 100644 src/navigation_prototype/migrations/0003_alter_navlink_navigation.py delete mode 100644 src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py delete mode 100644 src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py delete mode 100644 src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py diff --git a/src/navigation_prototype/migrations/0001_initial.py b/src/navigation_prototype/migrations/0001_initial.py index 59b72314a..8d2c75156 100644 --- a/src/navigation_prototype/migrations/0001_initial.py +++ b/src/navigation_prototype/migrations/0001_initial.py @@ -1,18 +1,38 @@ -# Generated by Django 4.2.16 on 2024-12-10 16:44 +# Generated by Django 4.2.16 on 2024-12-11 11:47 from django.db import migrations, models import django.db.models.deletion +import modelcluster.fields class Migration(migrations.Migration): initial = True - dependencies = [] + dependencies = [ + ("wagtailcore", "0094_alter_page_locale"), + ] operations = [ migrations.CreateModel( name="Nav", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="PrimaryNavLink", fields=[ ( "id", @@ -27,14 +47,33 @@ class Migration(migrations.Migration): "sort_order", models.IntegerField(blank=True, editable=False, null=True), ), + ("label", models.CharField(max_length=255)), + ("url", models.URLField(blank=True, null=True)), + ( + "navigation", + modelcluster.fields.ParentalKey( + on_delete=django.db.models.deletion.PROTECT, + related_name="links", + to="navigation_prototype.nav", + ), + ), + ( + "page", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="+", + to="wagtailcore.page", + ), + ), ], options={ - "ordering": ["sort_order"], "abstract": False, }, ), migrations.CreateModel( - name="NavLink", + name="SecondaryNavLink", fields=[ ( "id", @@ -50,27 +89,28 @@ class Migration(migrations.Migration): models.IntegerField(blank=True, editable=False, null=True), ), ("label", models.CharField(max_length=255)), - ("url", models.CharField(max_length=255)), + ("url", models.URLField(blank=True, null=True)), ( - "navigation", + "page", models.ForeignKey( + blank=True, + null=True, on_delete=django.db.models.deletion.PROTECT, - related_name="links", - to="navigation_prototype.nav", + related_name="+", + to="wagtailcore.page", ), ), ( "parent_link", - models.ForeignKey( + modelcluster.fields.ParentalKey( null=True, on_delete=django.db.models.deletion.PROTECT, related_name="child_links", - to="navigation_prototype.navlink", + to="navigation_prototype.primarynavlink", ), ), ], options={ - "ordering": ["sort_order"], "abstract": False, }, ), diff --git a/src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py b/src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py deleted file mode 100644 index cedcb9a12..000000000 --- a/src/navigation_prototype/migrations/0002_alter_nav_options_remove_nav_sort_order.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 4.2.16 on 2024-12-10 16:47 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("navigation_prototype", "0001_initial"), - ] - - operations = [ - migrations.AlterModelOptions( - name="nav", - options={}, - ), - migrations.RemoveField( - model_name="nav", - name="sort_order", - ), - ] diff --git a/src/navigation_prototype/migrations/0003_alter_navlink_navigation.py b/src/navigation_prototype/migrations/0003_alter_navlink_navigation.py deleted file mode 100644 index 2c58d8378..000000000 --- a/src/navigation_prototype/migrations/0003_alter_navlink_navigation.py +++ /dev/null @@ -1,24 +0,0 @@ -# Generated by Django 4.2.16 on 2024-12-10 16:49 - -from django.db import migrations -import django.db.models.deletion -import modelcluster.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ("navigation_prototype", "0002_alter_nav_options_remove_nav_sort_order"), - ] - - operations = [ - migrations.AlterField( - model_name="navlink", - name="navigation", - field=modelcluster.fields.ParentalKey( - on_delete=django.db.models.deletion.PROTECT, - related_name="links", - to="navigation_prototype.nav", - ), - ), - ] diff --git a/src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py b/src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py deleted file mode 100644 index c8caa3ab1..000000000 --- a/src/navigation_prototype/migrations/0004_primarynavlink_secondarynavlink_delete_navlink.py +++ /dev/null @@ -1,81 +0,0 @@ -# Generated by Django 4.2.16 on 2024-12-10 16:52 - -from django.db import migrations, models -import django.db.models.deletion -import modelcluster.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ("navigation_prototype", "0003_alter_navlink_navigation"), - ] - - operations = [ - migrations.CreateModel( - name="PrimaryNavLink", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "sort_order", - models.IntegerField(blank=True, editable=False, null=True), - ), - ("label", models.CharField(max_length=255)), - ("url", models.CharField(max_length=255)), - ( - "navigation", - modelcluster.fields.ParentalKey( - on_delete=django.db.models.deletion.PROTECT, - related_name="links", - to="navigation_prototype.nav", - ), - ), - ], - options={ - "abstract": False, - }, - ), - migrations.CreateModel( - name="SecondaryNavLink", - fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ( - "sort_order", - models.IntegerField(blank=True, editable=False, null=True), - ), - ("label", models.CharField(max_length=255)), - ("url", models.CharField(max_length=255)), - ( - "parent_link", - models.ForeignKey( - null=True, - on_delete=django.db.models.deletion.PROTECT, - related_name="child_links", - to="navigation_prototype.primarynavlink", - ), - ), - ], - options={ - "abstract": False, - }, - ), - migrations.DeleteModel( - name="NavLink", - ), - ] diff --git a/src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py b/src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py deleted file mode 100644 index e0cd302e0..000000000 --- a/src/navigation_prototype/migrations/0005_alter_secondarynavlink_parent_link.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.2.16 on 2024-12-10 16:53 - -from django.db import migrations -import django.db.models.deletion -import modelcluster.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ("navigation_prototype", "0004_primarynavlink_secondarynavlink_delete_navlink"), - ] - - operations = [ - migrations.AlterField( - model_name="secondarynavlink", - name="parent_link", - field=modelcluster.fields.ParentalKey( - null=True, - on_delete=django.db.models.deletion.PROTECT, - related_name="child_links", - to="navigation_prototype.primarynavlink", - ), - ), - ] diff --git a/src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py b/src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py deleted file mode 100644 index d0a562f71..000000000 --- a/src/navigation_prototype/migrations/0006_primarynavlink_page_secondarynavlink_page_and_more.py +++ /dev/null @@ -1,47 +0,0 @@ -# Generated by Django 4.2.16 on 2024-12-10 17:06 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ("wagtailcore", "0094_alter_page_locale"), - ("navigation_prototype", "0005_alter_secondarynavlink_parent_link"), - ] - - operations = [ - migrations.AddField( - model_name="primarynavlink", - name="page", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.PROTECT, - related_name="+", - to="wagtailcore.page", - ), - ), - migrations.AddField( - model_name="secondarynavlink", - name="page", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.PROTECT, - related_name="+", - to="wagtailcore.page", - ), - ), - migrations.AlterField( - model_name="primarynavlink", - name="url", - field=models.URLField(blank=True, null=True), - ), - migrations.AlterField( - model_name="secondarynavlink", - name="url", - field=models.URLField(blank=True, null=True), - ), - ] From 982610a0a954b8dce1d52bb7050f38141cc7331e Mon Sep 17 00:00:00 2001 From: Cameron Lamb Date: Wed, 11 Dec 2024 13:35:18 +0000 Subject: [PATCH 4/7] Fix ordering --- src/navigation_prototype/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/navigation_prototype/models.py b/src/navigation_prototype/models.py index bea558574..46c9a1160 100644 --- a/src/navigation_prototype/models.py +++ b/src/navigation_prototype/models.py @@ -40,7 +40,7 @@ def __str__(self): PageChooserPanel("page"), ] - class Meta: + class Meta(Orderable.Meta): abstract = True From 5503fbc926513142efea645f8bdbee206ddbbcff Mon Sep 17 00:00:00 2001 From: Nico Picchio Date: Wed, 11 Dec 2024 16:34:19 +0000 Subject: [PATCH 5/7] fix missing migration CI error --- src/navigation_prototype/migrations/0001_initial.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/navigation_prototype/migrations/0001_initial.py b/src/navigation_prototype/migrations/0001_initial.py index 8d2c75156..ab8ea6527 100644 --- a/src/navigation_prototype/migrations/0001_initial.py +++ b/src/navigation_prototype/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.16 on 2024-12-11 11:47 +# Generated by Django 4.2.16 on 2024-12-11 16:23 from django.db import migrations, models import django.db.models.deletion @@ -111,6 +111,7 @@ class Migration(migrations.Migration): ), ], options={ + "ordering": ["sort_order"], "abstract": False, }, ), From fc97625187ce43e99e4f81a2db681150d0add8a1 Mon Sep 17 00:00:00 2001 From: Cameron Lamb Date: Mon, 16 Dec 2024 15:02:20 +0000 Subject: [PATCH 6/7] Fix scenario where nav isn't created yet --- src/navigation_prototype/templatetags/nav_proto.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/navigation_prototype/templatetags/nav_proto.py b/src/navigation_prototype/templatetags/nav_proto.py index 4548e7bc0..33474bb6b 100644 --- a/src/navigation_prototype/templatetags/nav_proto.py +++ b/src/navigation_prototype/templatetags/nav_proto.py @@ -8,9 +8,9 @@ @register.inclusion_tag("navigation_prototype/navigation.html") def nav_proto(): - try: - nav = Nav.objects.first() - except Nav.DoesNotExist: + nav = Nav.objects.first() + + if not nav: return {} return { From 7b1e0ae302e8b48f7e8008c5bab3ee225b55d07b Mon Sep 17 00:00:00 2001 From: Cameron Lamb Date: Mon, 6 Jan 2025 10:57:25 +0000 Subject: [PATCH 7/7] Fix ordering of primary nav items --- .../0002_alter_primarynavlink_options.py | 17 +++++++++++++++++ src/navigation_prototype/models.py | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/navigation_prototype/migrations/0002_alter_primarynavlink_options.py diff --git a/src/navigation_prototype/migrations/0002_alter_primarynavlink_options.py b/src/navigation_prototype/migrations/0002_alter_primarynavlink_options.py new file mode 100644 index 000000000..0fd86a56a --- /dev/null +++ b/src/navigation_prototype/migrations/0002_alter_primarynavlink_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.17 on 2025-01-06 10:55 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("navigation_prototype", "0001_initial"), + ] + + operations = [ + migrations.AlterModelOptions( + name="primarynavlink", + options={"ordering": ["sort_order"]}, + ), + ] diff --git a/src/navigation_prototype/models.py b/src/navigation_prototype/models.py index 46c9a1160..e682cf9d1 100644 --- a/src/navigation_prototype/models.py +++ b/src/navigation_prototype/models.py @@ -11,7 +11,7 @@ @register_snippet class Nav(ClusterableModel): panels = [ - InlinePanel("links", label="Links", min_num=1), + InlinePanel("links", label="Links"), ] @@ -44,7 +44,7 @@ class Meta(Orderable.Meta): abstract = True -class PrimaryNavLink(ClusterableModel, NavLinkBase): +class PrimaryNavLink(NavLinkBase, ClusterableModel): navigation = ParentalKey( "Nav", on_delete=models.PROTECT,