davegri
davegri

Reputation: 2286

allauth problems extending SignupForm class

I keep finding outdated solutions that don't seem to be working.

I'm trying to change the error messages from English to Hebrew, for my website in django-allauth, I haven't checked if their are any translations because I would like to write them myself anyhow.

I tried changing for example the duplicate email error with the following code.

forms.py

from allauth.account.forms import SignupForm

class CustomSignupForm(SignupForm):
    def raise_duplicate_email_error(self):
        raise forms.ValidationError("שם משתמש כבר קיים עם כתובת אימייל")

base.py (base settings file)

SOCIALACCOUNT_FORMS = {
    'signup': 'website.forms.CustomSignupForm',
}

this resulted in the following error:

__init__() got an unexpected keyword argument 'sociallogin'

Traceback:

File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/socialaccount/views.py" in dispatch
  38.         return super(SignupView, self).dispatch(request, *args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/views.py" in dispatch
  68.                                             **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/views.py" in dispatch
  151.                                                           **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/base.py" in dispatch
  89.         return handler(request, *args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/edit.py" in get
  205.         form = self.get_form()
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/django/views/generic/edit.py" in get_form
  74.         return form_class(**self.get_form_kwargs())
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/forms.py" in __init__
  289.         super(SignupForm, self).__init__(*args, **kwargs)
File "/home/david/.virtualenvs/sikumim/lib/python3.4/site-packages/allauth/account/forms.py" in __init__
  223.         super(BaseSignupForm, self).__init__(*args, **kwargs)

Exception Type: TypeError at /accounts/social/signup/
Exception Value: __init__() got an unexpected keyword argument 'sociallogin'

What am I doing wrong?

Upvotes: 1

Views: 652

Answers (2)

Javier Lopez
Javier Lopez

Reputation: 240

You are inheriting from allauth.account.forms.SignupForm but using it in the setting SOCIALACCOUNT_FORMS, which is for social accounts. Your code should look like this:

website/forms.py

from allauth.socialaccount.forms import SignupForm

class CustomSignupForm(SignupForm):
     def raise_duplicate_email_error(self):
         raise forms.ValidationError("שם משתמש כבר קיים עם כתובת אימייל")

settings.py

SOCIALACCOUNT_FORMS = {
    'signup': 'website.forms.CustomSignupForm',
}

Upvotes: 1

fabfuel
fabfuel

Reputation: 1

You need to overwrite the __init__() method and define sociallogin as parameter, which then will not be passed to the __init__() method of the super class.

Like this:

def __init__(self, sociallogin=None, *args, **kwargs):
    super().__init__(*args, **kwargs)

Upvotes: 0

Related Questions