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

@rfleschenberg rfleschenberg commented Jul 2, 2016

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

tomchristie commented Jul 28, 2016

Broadly in favour, yup.

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

tomchristie commented Aug 2, 2016

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

Going to merge this, given the above.

@tomchristie tomchristie merged commit 9f5e841 into encode:master Aug 2, 2016
2 checks passed
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.

None yet

2 participants