2
0
Fork 0

feat(pages): populate navs from Page objects
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Luca 2024-05-04 00:06:58 +02:00
parent 818e478353
commit adbb5685a0
5 changed files with 75 additions and 4 deletions

View File

@ -15,6 +15,21 @@ def reimport(modeladmin, request, queryset):
@admin.register(Page) @admin.register(Page)
class PageAdmin(admin.ModelAdmin): class PageAdmin(admin.ModelAdmin):
fields = ("url", "content", "title", "visible", "kind") fields = (
list_display = ("url", "title", "visible", "kind") "url",
"content",
"title",
"visible",
"kind",
"show_in_footer_nav",
"show_in_main_nav",
)
list_display = (
"url",
"title",
"visible",
"kind",
"show_in_footer_nav",
"show_in_main_nav",
)
actions = (reimport,) actions = (reimport,)

View File

@ -1,8 +1,9 @@
from pathlib import Path
from django.apps import AppConfig from django.apps import AppConfig
class PagesConfig(AppConfig): class PagesConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField" default_auto_field = "django.db.models.BigAutoField"
name = "shiftregister.pages" name = "shiftregister.pages"
def ready(self):
from . import signals

View File

@ -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),
),
]

View File

@ -16,6 +16,8 @@ class Page(models.Model):
visible = models.BooleanField(default=True) visible = models.BooleanField(default=True)
title = models.CharField(blank=True, max_length=200) title = models.CharField(blank=True, max_length=200)
kind = models.CharField(choices=KIND_CHOICES, default=REGULAR, max_length=8) kind = models.CharField(choices=KIND_CHOICES, default=REGULAR, max_length=8)
show_in_footer_nav = models.BooleanField(default=True)
show_in_main_nav = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return ( return (

View File

@ -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
]