jazzband / django-formtools

A set of high-level abstractions for Django forms
https://django-formtools.readthedocs.io
BSD 3-Clause "New" or "Revised" License
784 stars 135 forks source link

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

Open Tobi-De opened 1 year ago

Tobi-De commented 1 year ago

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.