django-formtools icon indicating copy to clipboard operation
django-formtools copied to clipboard

Add support for passing extra parameters to the form constructor (FormPreview)

Open Tobi-De opened this issue 1 year ago • 0 comments

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, and preview_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.

Tobi-De avatar Mar 30 '23 15:03 Tobi-De