Allow passing context to 503 view
ryselis opened this issue · comments
Currently we cannot pass any context to the view rendered by the middleware as it is set to {}. It would be nice to have a way to pass my own parameters to it, e.g., planned update finish time
@ryselis nice idea. I will add it as soon as possible, in the meanwhile feel free to send a PR.
@ryselis how do you expect to pass context data to the 503 view?
I have 2 ideas.
- Abstract out template rendering into its own method. Instead of calling
render_to_response
directly in middleware'sprocess_request
, add a new method toMaintanenceModeMiddleware
that does the rendering. If I want to do it differently, I override your middleware class and rewrite just this one method that renders the template. - Make some kind of hook that would let me specify just the context. For example, add a setting like
MAINTENANCE_MODE_TEMPLATE_RENDER_CONTEXT
so that I could assign a function to it, so it would look like this:
MAINTENANCE_MODE_TEMPLATE_RENDER_CONTEXT = get_maintenance_context
and I would have
def get_maintenance_context(request):
# return the context
in my code.
@ryselis the solution 1 is the one that I imagined, anyway the solution 2 could be a good alternative, I will add support for both solutions. Thanks
@ryselis in any case it's always possible to specify a custom template and load some template tags from it.
@fabiocaccamo yes, this is a possibility, but it is not an intuitive solution, at least for me
@ryselis just released 0.3.2
version.
Now it's possible to specify a custom function using the setting MAINTENANCE_MODE_TEMPLATE_CONTEXT
or extend the middleware and override the get_request_context
method.