-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept page change in before_serve_page handling #5753
Comments
Related: #11752. |
I like this idea! Sorry I didn't notice this before, @robmoorman... Marking this as a good first issue. As additional background for anyone interested in pick this up - see the documentation for the from wagtail import hooks
from myapp.models import BlogPage
@hooks.register('before_serve_page')
def block_googlebot(page, request, serve_args, serve_kwargs):
if request.META.get('HTTP_USER_AGENT') == 'GoogleBot':
# serve the "information for robots" page in place of the one requested
return BlogPage.objects.get(slug="information-for-robots") The code that @robmoorman has provided would go into the |
With the page-swapping examples... Does the final page not also need to be passed through the relevant hooks before it is served? |
@ababic I don't think so - can you expand on what you have in mind? Perhaps you're thinking along the lines of what happens to request objects inside middleware, where successive middleware classes contribute properties like |
@gasman I want to work on this issue... |
@akshatggupta Excellent! See https://docs.wagtail.org/en/latest/contributing/index.html for some pointers on getting started. |
@gasman Apologies for the delayed response. My github notifications are somewhat polluted with client project notifcations currently.
Yes, what I mean is: because pages have no equivalent |
@ababic Ah yep, that's a good point - and from a quick survey of public code on Github using All the same, I think it would be sufficient to document the fact that the ordering of |
@gasman In all honesty, I've got a bad feeling about doing this in The example above would simply become:
If the hook returns |
Hey @ababic I'm trying to work on this issue what do you think about this approach
If the page exists, it is returned directly. |
@akshatggupta I'm suggesting that if the page needs to be swapped, that be done via a separate |
When I gave the thumbs-up to this, it seemed like a quick win and a natural extension of the @robmoorman, can you give more detail about your planned use-case for this? Does this achieve anything that couldn't be done by setting a custom |
Is your proposal related to a problem?
Currently the
before_serve_page
acceptsHttpResponse's
in order to accept adjusted page content. For headless setups (and in theory other situations) you maybe don't want to return Html but Json instead. However you still want to benefit from thebefore_serve_page
hooks mechanisme.Describe the solution you'd like
Change the page instance in a
before_serve_page
rather than acceptingHttpResponse's
.Describe alternatives you've considered
I tried to re-build the
serve
method, however you're dependent of the implementation in modules (e.g.wagtail-personalization
) which are using thebefore_serve_page
hooks in order to apply their business logic.Additional context
Code example for the solution:
The text was updated successfully, but these errors were encountered: