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

Pass "data" as a keyword argument when instantiating form_class #552

Merged
merged 1 commit into from
Jul 23, 2023

Conversation

lassebomh
Copy link
Contributor

I ran into a problem using AuthenticationForm as form_class in UnicornView due to the extra request argument in the forms constructor. This caused form data to be passed incorrectly in _get_form and was fixed by simply changing "data" to a keyword argument.

My component:

from django_unicorn.components import UnicornView
from django.contrib.auth.forms import AuthenticationForm

class AuthenticateView(UnicornView):
    form_class = AuthenticationForm
    
    username = ""
    password = ""

Cause the error:

'AuthenticationForm' object has no attribute 'cleaned_data'

While not necessarily condoning the use of authentication forms with unicorn, a temporary fix to a problem like this can be solved by inheriting the form class and changing init, like this:

class AuthForm(AuthenticationForm):
    def __init__(self, *args, **kwargs):
        super().__init__(None, *args, **kwargs)

class AuthenticateView(UnicornView):
    form_class = AuthForm
    
    username = ""
    password = ""

Great work on Unicorn by the way

adamghill added a commit that referenced this pull request Jul 22, 2023
@adamghill adamghill mentioned this pull request Jul 22, 2023
@adamghill adamghill self-assigned this Jul 22, 2023
@adamghill adamghill merged commit 7750520 into adamghill:main Jul 23, 2023
@adamghill
Copy link
Owner

@all-contributors please add @lassebomh for code

@allcontributors
Copy link
Contributor

@adamghill

I've put up a pull request to add @lassebomh! 🎉

@adamghill
Copy link
Owner

Thanks for the issue! This has been fixed in 0.53.0 and it has just been published to pypi. 😄

@lassebomh
Copy link
Contributor Author

No problem! Happy to contribute - even if it's 5 characters ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants