Skip to content
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

Change template context generation in TemplateHTMLRenderer #4236

Merged
merged 1 commit into from
Aug 2, 2016

Conversation

rfleschenberg
Copy link
Contributor

Make TemplateHTMLRenderer more subclass-friendly. Refs #4230.

  • Change the name of resolve_context() to get_template_context().
  • Pass the renderer context to this method, to give subclasses more flexibility
    when overriding.

This allows users to write code like this:

class ViewInContextHTMLRenderer(TemplateHTMLRenderer):

    def get_template_context(self, data, renderer_context):
        context = super().get_template_context(data, renderer_context)
        context['view'] = renderer_context['view']
        return context

Or maybe even:

class ExtraContextHTMLRenderer(TemplateHTMLRenderer):

    def get_template_context(self, data, renderer_context):
        context = super().get_template_context(data, renderer_context)
        context.update(renderer_context['extra_template_context'])
        return context

Currently, you have to override and reimplement the whole render() method instead.

This change does break compatibility with existing code that touches this interface. As far as I see, the interface was not documented. If desirable, we could add a compatibility shim.

- Change the name of ``resolve_context()`` to ``get_template_context()``.

- Pass the renderer context to this method, to give subclasses more flexibility
  when overriding.
@tomchristie
Copy link
Member

Broadly in favour, yup.

@tomchristie tomchristie added this to the 3.4.2 Release milestone Jul 28, 2016
@tomchristie
Copy link
Member

As far as I see, the interface was not documented.

Going to merge this, given the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants