-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update admin views to consistently return TemplateContext #6
base: master
Are you sure you want to change the base?
Update admin views to consistently return TemplateContext #6
Conversation
5e09b5e
to
20dcad9
Compare
df4f80a
to
c9232b1
Compare
@ababic, I'm not understanding why it's ok to just swap
|
Hi @ncastro-nypr. You might find this answer on stackoverflow helpful: https://stackoverflow.com/questions/38838601/django-templateresponse-vs-render |
I see, thank you! This all looks good to me then. |
I'll be honest I don't fully understand the benefits of this (I get that it runs custom middleware, but I guess other than translation I don't know what we use that for), but I'm all for consistency with the Wagtail codebase. That being said, it looks like a lot of these updates are actually taking us further away from Wagtail core (which at least on Aside from that, is this intended to replace every |
…of using the render() shortcut
…ntext of translation.override()
Thanks for the feedback @mike-hearn. I've now replaced those last few uses of To clarify, this is the NYPR equivalent of a PR that I've submitted to upstream Wagtail, which we should hopefully be able to get reviewed/merged soon: I wanted to utilise the |
c9232b1
to
b307475
Compare
As explained in the Django docs, when using
TemplateResponse
, the rendering of the template is delayed until necessary, and middleware and view decorators have the opportunity to make changes before rendering happens.Specifically, the
process_template_response()
method on custom middleware gets to do its thing (which doesn't happen when using therender()
shortcut), giving developers an important and convenient hook to make certain types of customisation (that might otherwise require replacing entire function-based views or monkey-patching).Most class-based views in Wagtail subclass Django's
TemplateResponseMixin
somewhere along the line, and so already return aTemplateResponse
- So these changes also greatly improve consistency.While implementing these changes, I also noticed an issue that seems not to have been reported yet: The
wagtail.auth.require_admin_access
decorator isn't working quite as expected in many cases: Specifically, where views return aTemplateResponse
. Because template rendering is delayed, it happens outside thetranslation.override()
context manager, meaning the language is only active while view logic is run - the template itself is still rendered in the default language. I've fixed this here by invoking the response'srender()
method if it has one - which means the language override is fully applied.