kopia lustrzana https://github.com/wagtail/bakerydemo
Apply PreviewableMixin with single preview mode to FooterText model
rodzic
ae3f2f2396
commit
8888011b66
|
@ -12,7 +12,13 @@ from wagtail.admin.panels import (
|
|||
)
|
||||
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
|
||||
from wagtail.fields import RichTextField, StreamField
|
||||
from wagtail.models import Collection, DraftStateMixin, Page, RevisionMixin
|
||||
from wagtail.models import (
|
||||
Collection,
|
||||
DraftStateMixin,
|
||||
Page,
|
||||
PreviewableMixin,
|
||||
RevisionMixin,
|
||||
)
|
||||
from wagtail.search import index
|
||||
from wagtail.snippets.models import register_snippet
|
||||
|
||||
|
@ -85,7 +91,7 @@ class Person(index.Indexed, ClusterableModel):
|
|||
|
||||
|
||||
@register_snippet
|
||||
class FooterText(DraftStateMixin, RevisionMixin, models.Model):
|
||||
class FooterText(DraftStateMixin, RevisionMixin, PreviewableMixin, models.Model):
|
||||
"""
|
||||
This provides editable text for the site footer. Again it uses the decorator
|
||||
`register_snippet` to allow it to be accessible via the admin. It is made
|
||||
|
@ -103,6 +109,12 @@ class FooterText(DraftStateMixin, RevisionMixin, models.Model):
|
|||
def __str__(self):
|
||||
return "Footer text"
|
||||
|
||||
def get_preview_template(self, request, mode_name):
|
||||
return "base.html"
|
||||
|
||||
def get_preview_context(self, request, mode_name):
|
||||
return {"footer_text": self.body}
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Footer Text"
|
||||
|
||||
|
|
|
@ -96,7 +96,12 @@ def breadcrumbs(context):
|
|||
|
||||
@register.inclusion_tag("base/include/footer_text.html", takes_context=True)
|
||||
def get_footer_text(context):
|
||||
footer_text = ""
|
||||
# Get the footer text from the context if exists,
|
||||
# so that it's possible to pass a custom instance e.g. for previews
|
||||
# or page types that need a custom footer
|
||||
footer_text = context.get("footer_text", "")
|
||||
|
||||
# If the context doesn't have footer_text defined, get one that's live
|
||||
if not footer_text:
|
||||
instance = FooterText.objects.filter(live=True).first()
|
||||
footer_text = instance.body if instance else ""
|
||||
|
|
Ładowanie…
Reference in New Issue