Make the Custom Navbar/Footer in Pro Template work in Multi-Site Installs
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez par examiner les définitions personnalisées de Navbar et Footer dans models.py ainsi que les fonctions de rendu dans website_tags.py, puis inspectez les tests de templates pro existants et la documentation. Définissez le comportement attendu des résultats spécifiques au site et des instances existantes non attribuées, ajoutez la migration et la couverture requises, puis mettez à jour la documentation lorsque les composants multi-site se rendent correctement sans casser les installations existantes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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()
- Langage dominant
- Python
- Étoiles
- 763
- Forks
- 154
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de coderedcorp/coderedcms
-
Type: Bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
coderedcorp/coderedcms#714 ·
-
Typo in accordion_block.htmlOuverteType: Bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 65/100
coderedcorp/coderedcms#711 ·
-
Type: Bug
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
coderedcorp/coderedcms#713 · 1 commentaire ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
coderedcorp/coderedcms#710 · 4 commentaires ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 58/100
coderedcorp/coderedcms#709 ·
Toutes les issues de coderedcorp/coderedcms
Issues similaires
-
customer-reported
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Azure/azure-cli#34150 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
community-request
Difficulté 1/5 Moins d'une heure Accessibilité débutants 95/100
NVIDIA-NeMo/Curator#2464 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
weblate-discover crashes with an unhandled FileNotFoundError when the directory does not existOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
WeblateOrg/translation-finder#1099 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
trezor/trezor-firmware#7997 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
Les mainteneurs répondent en général sous 1 jour