Widget should own its renderer
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 423
- Forks
- 158
- PR merge metrics
- No merged PRs in 30d
Description
When extending a widget (e.g., to use a template with a different rendering engine), we're usually stumbling upon the fact that the renderer used to render a template is an instance variable on the Field. Consider this code example:
class ColorChooserWidget(TextInputWidget):
template = "forms/color_chooser.jinja2"
def serialize(self, field, cstruct, **kw):
original_renderer = field.renderer
field.renderer = lambda template, **kwargs: render(self.template, kwargs)
rendered = super(ColorChooserWidget, self).serialize(field, cstruct, **kw)
field.renderer = original_renderer
return rendered
This works, but I do not see why the renderer would have to be set on the field. It would be much more sensible if the widgets would go through a self.render() which is easy to override.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how widgets serialize templates and how the field.renderer instance variable is used. Compare the current temporary renderer replacement with the proposed widget-level render hook; done means a widget can override rendering without mutating the field renderer, with behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100