feat(pages): populate navs from Page objects
parent
818e478353
commit
adbb5685a0
@ -1,8 +1,9 @@
|
||||
from pathlib import Path
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PagesConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "shiftregister.pages"
|
||||
|
||||
def ready(self):
|
||||
from . import signals
|
||||
|
@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0.4 on 2024-05-03 21:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("pages", "0002_page_kind_alter_page_title"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="page",
|
||||
name="show_in_footer_nav",
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="page",
|
||||
name="show_in_main_nav",
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
@ -0,0 +1,30 @@
|
||||
from django.dispatch import receiver
|
||||
from django.urls import reverse
|
||||
|
||||
from shiftregister.core.signals import populate_footer_nav, populate_nav
|
||||
|
||||
from .models import Page
|
||||
|
||||
|
||||
@receiver(populate_footer_nav, dispatch_uid="populate_pages_footer_nav")
|
||||
def populate_pages_footer_nav(sender, **kwargs):
|
||||
return [
|
||||
{
|
||||
"link": reverse("pages:view", args=(page.url,)),
|
||||
"text": page.title or page.url,
|
||||
}
|
||||
for page in Page.objects.filter(visible=True)
|
||||
if page.visible and page.show_in_footer_nav
|
||||
]
|
||||
|
||||
|
||||
@receiver(populate_nav, dispatch_uid="populate_pages_nav")
|
||||
def populate_pages_nav(sender, **kwargs):
|
||||
return [
|
||||
{
|
||||
"link": reverse("pages:view", args=(page.url,)),
|
||||
"text": page.title or page.url,
|
||||
}
|
||||
for page in Page.objects.filter(visible=True)
|
||||
if page.visible and page.show_in_main_nav
|
||||
]
|
Loading…
Reference in New Issue