Add support for passing extra parameters to the form constructor (FormPreview) #233
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.
Hey there,
I'm writing to submit a pull request that improves the FormPreview view.
I ran into an issue when trying to pass extra context to the form constructor. While it's common to pass the request object to a form instance in Django, doing so with the FormPreview view required me to override several methods, including
post_post
,preview_post
, andpreview_get
. This made the code more complex and harder to maintain.To address this problem, I propose adding a
form_extra_params(self, request)
method that allows users to pass extra data to their form if needed. This method takes the request object as an argument, and by default, it returns an empty dictionary. Users can override this method to provide additional context to the form constructor, without having to modify the view's core methods.I believe that this solution simplifies the code and makes it more flexible for developers who need to handle custom validation logic. I hope that you will find this pull request useful and that you will consider merging it into the main branch.
Thank you for your time and for maintaining this great package!
Best regards,
Tobi
PS: I'm not entirely sure how to write a test for this feature, but I believe it's straightforward enough that testing may not be necessary. However, if you feel that testing is required, I would be more than happy to conduct research and update my code accordingly. Thanks.