3
0
Fork 0

feat: add get_template_context() method for master view

allow override / supplement context for any view template
This commit is contained in:
Lance Edgar 2024-11-25 19:10:58 -06:00
parent 6085ea78ec
commit ba9021c990

View file

@ -1629,6 +1629,9 @@ class MasterView(View):
if 'instance_deletable' not in context:
context['instance_deletable'] = self.is_deletable(instance)
# supplement context further if needed
context = self.get_template_context(context)
# first try the template path most specific to this view
template_prefix = self.get_template_prefix()
mako_path = f'{template_prefix}/{template}.mako'
@ -1648,6 +1651,26 @@ class MasterView(View):
# let that error raise on up
return render_to_response(mako_path, context, request=self.request)
def get_template_context(self, context):
"""
This method should return the "complete" context for rendering
the current view template.
Default logic for this method returns the given context
unchanged.
You may wish to override to pass extra context to the view
template. Check :attr:`viewing` and similar, or
``request.current_route_name`` etc. in order to add extra
context only for certain view templates.
:params: context: The context dict we have so far,
auto-provided by the master view logic.
:returns: Final context dict for the template.
"""
return context
def get_fallback_templates(self, template):
"""
Returns a list of "fallback" template paths which may be