Rendering Alliance UI Form Components
- class alliance_platform.ui.forms.renderers.FormInputContextRenderer
Renderer to accommodate passing extra context variables to widgets
Django widget interface provides no way to pass extra context to widget templates short of extending the widget class, or adding it to widget.attrs. The problem with passing it in widget.attrs it that it’s typically passed directly through to the widget. Polluting
attrswith extra context is problematic both because it’s unexpected and because you either just have to accept all the values and hope it causes no issues, or filter them out which is inconvenient in templates.This renderer works with
form_inputto pass extra context to widgets by setting a special key in thewidget.attrsdictionary. The renderer then pops this value and adds the contents to thecontextthat is then used to render the template.
- class alliance_platform.ui.forms.renderers.form_input_context_key
This class serves as a unique sentinel value in a form’s widget attributes dictionary to set special Alliance Platform context values. It serves no purpose except as a dictionary key with special handling.