pallets-eco / pallets-eco/wtforms
Merge obj and data + access obj as an attribute
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 409
- PR merge metrics
- No merged PRs in 30d
Description
Actual Behavior
Either have a UserForm(obj=user) or UserForm(request.form) but having a combination of both is not possible.
Expected Behavior
As forms can be partial instead of representing all the object's fields, it would be convenient to being able to access other attributes from the form.
IMHO the simplest would be to have UserForm(obj=user) in the GET page, and UserForm(request.form, obj=user) in the POST page. Fields would be merged with request.form data first, then obj attributes for the rest.
Also, this would require a form.obj getter which would return the obj, just like form.data/form.formData works.
Finally, this would be useful for the "protected" attribute feature ( #217 ) as one would not need to add fields that are here simply for display, as they are accessible through form.obj.protected_attribute in the template.
Hope it makes sense
Environment
- Python version: 3.9.5
- wtforms version: 2.3.3
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
No files or tests are named. Start by tracing how WTForms builds a form from request data and an object, then review existing form data access behavior. Done should include merged request and object values for partial forms, a form.obj getter, and coverage for GET and POST usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100