Make the Custom Navbar/Footer in Pro Template work in Multi-Site Installs
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne damit, die benutzerdefinierten Definitionen von Navbar und Footer in models.py sowie die Rendering-Funktionen in website_tags.py zu überprüfen, und sieh dir anschließend die vorhandenen pro-Template-Tests und die Dokumentation an. Lege fest, wie standortspezifische Ergebnisse und vorhandene nicht zugewiesene Instanzen sich verhalten sollen, füge die erforderliche Migration und Testabdeckung hinzu und aktualisiere die Dokumentation, sobald die Multi-Site-Komponenten korrekt gerendert werden, ohne bestehende Installationen zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Is your feature request related to a problem? Please describe.
We receently implemented WagtailCRX, and noticed that wagtail's Navbar and Footer models in the basic template work in multi-site installations, but the custom Navbar and Footer models in the pro template do not (though you could fall back to wagtail's default models with CRX_DISABLE_NAVBAR = False and CRX_DISABLE_FOOTER = False).
Describe the solution you'd like
We implemented the following in our site, which allows us to use custom Navbar(s) and Footer(s) in our multi-site install. Because nulls are allowed, it won't cause errors on existing installs. In existing installs, though, the template tags as implemented below would cause the components to not be rendered (existing model instances would not associated with any site initially). To resolve this, we could:
- Modify the template tags to check for a setting before implementing their site checks so it won't disappear the navbars and footers in existing projects (falling back to current functionality if
CRX_USE_SITE_FIELD=Falsefor example) - Or, just set the template tags to fall back to showing all Navbar(s) and Footer(s) if there are no site-specific results
Would a PR to update the pro template (and add relevant tests & updates to docs) be of interest? Any additional thoughts/recommendations?
This proposal would also resolve #673
models.py
"""
Create or customize your page models here.
"""
from coderedcms.blocks import (
HTML_STREAMBLOCKS,
LAYOUT_STREAMBLOCKS,
BaseBlock,
BaseLinkBlock,
LinkStructValue,
)
from coderedcms.forms import CoderedFormField
from coderedcms.models import (
CoderedArticleIndexPage,
CoderedArticlePage,
CoderedEmail,
CoderedEventIndexPage,
CoderedEventOccurrence,
CoderedEventPage,
CoderedFormPage,
CoderedLocationIndexPage,
CoderedLocationPage,
CoderedWebPage,
)
from django.db import models
from modelcluster.fields import ParentalKey
from wagtail import blocks
from wagtail.admin.panels import FieldPanel
from wagtail.fields import StreamField
from wagtail.snippets.models import register_snippet
# Other models...
@register_snippet
class Navbar(models.Model):
"""Custom navigation bar / menu."""
class Meta:
"""Meta class for Navbar."""
verbose_name = "Navigation Bar"
name = models.CharField(
max_length=255,
)
content = StreamField(
[
("link", NavbarLinkBlock()),
("dropdown", NavbarDropdownBlock()),
],
use_json_field=True,
)
site = models.ForeignKey( # <-- New Field
"wagtailcore.Site",
on_delete=models.CASCADE,
related_name="navbars",
null=True,
blank=True,
)
panels = [
FieldPanel("name"),
FieldPanel("site"), # <-- New panel item
FieldPanel("content"),
]
def __str__(self) -> str:
return self.name
@register_snippet
class Footer(models.Model):
"""Custom footer for bottom of pages on the site."""
class Meta:
"""Meta class for Footer."""
verbose_name = "Footer"
name = models.CharField(
max_length=255,
)
content = StreamField(
LAYOUT_STREAMBLOCKS,
verbose_name="Content",
blank=True,
use_json_field=True,
)
site = models.ForeignKey( # <-- New Field
"wagtailcore.Site",
on_delete=models.CASCADE,
related_name="footers",
null=True,
blank=True,
)
panels = [
FieldPanel("name"),
FieldPanel("site"), # <-- New panel item
FieldPanel("content"),
]
def __str__(self) -> str:
return self.name
Updated template tags render the navbar(s) and footer(s) for the current site:
website_tags.py
"""Custom template tags for the website app."""
from django import template
from wagtail.models import Site
from website.models import Footer, Navbar
register = template.Library()
@register.simple_tag(takes_context=True)
def get_website_navbars(context):
"""Get the navbars for the current site.
Args:
context: The template context which contains the current request
Returns:
QuerySet: Navbar queryset filtered by the current site
"""
try:
# Get the current request from context
request = context['request']
# Get the current site from the request
current_site = Site.find_for_request(request)
# Return navbars associated with the current site
return Navbar.objects.filter(site=current_site)
except (KeyError, AttributeError):
# Fallback to returning all navbars if we can't determine the current site
return Navbar.objects.all()
@register.simple_tag(takes_context=True)
def get_website_footers(context):
"""Get the footers for the current site.
Args:
context: The template context which contains the current request
Returns:
QuerySet: Footer queryset filtered by the current site
"""
try:
# Get the current request from context
request = context['request']
# Get the current site from the request
current_site = Site.find_for_request(request)
# Return footers associated with the current site
return Footer.objects.filter(site=current_site)
except (KeyError, AttributeError):
# Fallback to returning all footers if we can't determine the current site
return Footer.objects.all()
- Vorherrschende Sprache
- Python
- Sterne
- 765
- Forks
- 154
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
Die Einrichtungsdateien dieses Projekts haben wir noch nicht geprüft. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus coderedcorp/coderedcms
-
Type: Bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
coderedcorp/coderedcms#714 ·
-
Type: Bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 65/100
coderedcorp/coderedcms#711 ·
-
Type: Bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
coderedcorp/coderedcms#713 · 1 Kommentar ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 55/100
coderedcorp/coderedcms#710 · 4 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 58/100
coderedcorp/coderedcms#709 ·
Alle Issues in coderedcorp/coderedcms
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
PedestrianDynamics/pyFDS-Evac#343 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
theskumar/python-dotenv#708 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Docs Timedelta
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
pandas-dev/pandas#69919 ·
Maintainer antworten meist innerhalb von 1 Tag
-
API documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
zephyrproject-rtos/west#1009 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 3 Tagen