WIP: Improve support for forms and other complex Python/Django constructs #140
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Provides a low-friction mechanism for adding real form instances into template contexts by looking for data definitions in YAML with a
klass: path.to.SomePythonClass
key/value pair. The code then attempts to import the relevant class, create an object of that type, and add it to the context.A generic set of objects can also be defined using the
PATTERN_LIBRARY_COMMON_OBJECTS
setting (using a similar dict format), which will be added to all pattern library contexts.In cases where the default instantiation behaviour just won't do, the
PATTERN_LIBRARY_CUSTOM_FACTORIES
setting can be used to specify alternative factories for objects of a specific type.https://pyyaml.org/wiki/PyYAMLDocumentation supports object instantiation via the
!!python/object
tag, but that doesn't provide any way to have the currentHttpRequest
be passed as an argument to__init__()
- which can be very useful in a Django context. This solution automatically passes the currentHttpRequest
using therequest
kwarg if the__init__()
method accepts it.Fixes #113.
Related: #106, #134
Checklist