wagtail / guide

A website to teach Wagtail CMS to content editors, moderators and administrators.
https://guide.wagtail.org
BSD 3-Clause "New" or "Revised" License
32 stars 26 forks source link

Previews don't work for unpublished pages #358

Open thibaudcolas opened 1 year ago

thibaudcolas commented 1 year ago

https://guide.wagtail.org/admin/pages/213/view_draft/

If a page has never been published, we can’t use the live preview, nor view_draft.


Perhaps related to wagtail-localise field replacement not happening for drafts

laymonage commented 7 months ago

This is probably because of the following code https://github.com/wagtail/guide/blob/195797c837557fd13cf91af38b8fcf4964020748/apps/core/models/content.py#L47-L55

It doesn't return the context at all if the page is not live. It should be changed to something like

def get_context(self, request, *args, **kwargs): 
    context = super().get_context(request, *args, **kwargs) 
    if self.live and self.show_in_menus: 
        pages = Page.objects.live().in_menu() 
        context.update( 
            previous=pages.filter(path__lt=self.path).last(), 
            next=pages.filter(path__gt=self.path).first(), 
        ) 
    return context