context_processors.py 781 B

12345678910111213141516171819202122
  1. from mezzanine.pages.models import Page
  2. def page(request):
  3. """
  4. Adds the current page to the template context and runs its
  5. ``set_helper`` method. This was previously part of
  6. ``PageMiddleware``, but moved to a context processor so that
  7. we could assign these template context variables without
  8. the middleware depending on Django's ``TemplateResponse``.
  9. """
  10. context = {}
  11. page = getattr(request, "page", None)
  12. if isinstance(page, Page):
  13. # set_helpers has always expected the current template context,
  14. # but here we're just passing in our context dict with enough
  15. # variables to satisfy it.
  16. context = {"request": request, "page": page, "_current_page": page}
  17. page.set_helpers(context)
  18. return context