2
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Luca adbb5685a0 feat(pages): populate navs from Page objects
continuous-integration/drone/push Build is failing Details
2024-05-04 00:06:58 +02:00
Luca 818e478353 feat: generate footer nav from context 2024-05-04 00:05:00 +02:00
7 changed files with 91 additions and 16 deletions

View File

@ -110,9 +110,13 @@
{% endblock %} {% endblock %}
<div class="breadcrumb has-dot-separator is-flex-grow-1 is-right ml-5"> <div class="breadcrumb has-dot-separator is-flex-grow-1 is-right ml-5">
<ul> <ul>
<li><a href="{% url 'pages:view' 'map' %}">Karte</a></li> {% for item in footer_nav_items %}
<li><a href="{% url 'pages:view' 'faq' %}">Häufig gestellte Fragen</a></li> <li>
<li><a href="{% url 'pages:view' 'about' %}">Über diese Seite/Impressum</a></li> <{% if item.link %}a{% else %}p{% endif %}{% if item.class %} class="{{ item.class }}"{% endif %}{% if item.link %} href="{{ item.link }}"{% endif %}>
{{ item.text }}
</{% if item.link %}a{% else %}p{% endif %}>
</li>
{% endfor %}
</ul> </ul>
</div> </div>
</div> </div>

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
]

View File

@ -40,15 +40,15 @@ ALLOWED_HOSTS = list(filter(lambda s: s != "", getenv("ALLOWED_HOSTS", "").split
INSTALLED_APPS = [ INSTALLED_APPS = [
"dynamic_preferences", "dynamic_preferences",
"shiftregister.app.apps.AppConfig", "shiftregister.app",
"shiftregister.core.apps.CoreConfig", "shiftregister.core",
"shiftregister.fallback.apps.FallbackConfig", "shiftregister.fallback",
"shiftregister.importer.apps.ImporterConfig", "shiftregister.importer",
"shiftregister.metrics.apps.MetricsConfig", "shiftregister.metrics",
"shiftregister.pages.apps.PagesConfig", "shiftregister.pages",
"shiftregister.signage.apps.SignageConfig", "shiftregister.signage",
"shiftregister.team.apps.TeamConfig", "shiftregister.team",
"shiftregister.feedback.apps.FeedbackConfig", "shiftregister.feedback",
"django.contrib.admin", "django.contrib.admin",
"django.contrib.auth", "django.contrib.auth",
"django.contrib.contenttypes", "django.contrib.contenttypes",