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

WIP: Improve support for forms and other complex Python/Django constructs #140

Closed

Conversation

ababic
Copy link
Contributor

@ababic ababic commented Mar 26, 2021

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 current HttpRequest be passed as an argument to __init__() - which can be very useful in a Django context. This solution automatically passes the current HttpRequest using the request kwarg if the __init__() method accepts it.

Fixes #113.

Related: #106, #134

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added an appropriate CHANGELOG entry

@ababic ababic added decision needed This requires a decision enhancement New feature or request status: Needs tests status: Needs docs labels Mar 26, 2021
@ababic ababic marked this pull request as draft March 26, 2021 16:38
@ababic ababic force-pushed the feature/python-object-injection-support branch 3 times, most recently from 18f73ad to 3d3135d Compare March 26, 2021 17:22
@ababic ababic force-pushed the feature/python-object-injection-support branch from 3d3135d to 5706210 Compare March 26, 2021 17:28
@ababic ababic closed this Mar 27, 2021
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.

Django form fields not well supported
1 participant