Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django change password issue, super(type, obj): obj must be an instance or subtype of type

i'm having some trouble with my changepassword form, it continues to give me the same error: super(type, obj): obj must be an instance or subtype of type

this is my form:

class PasswordChangeForm(forms.Form):
    current_password = forms.CharField(label=u'Current Password', widget=forms.PasswordInput(render_value=False))
    new_password = forms.CharField(label=u'New Password', widget=forms.PasswordInput(render_value=False))
    retyped_password = forms.CharField(label=u'Retype New Password', widget=forms.PasswordInput(render_value=False))

    def __init__(self, data=None, user=None, *args, **kwargs):
        self.user = user
        super(UserProfileEditForm, self).__init__(data=data, *args, **kwargs)

    def clean_current_password(self):
        cleaned_data = self.cleaned_data
        current_password = cleaned_data.get('current_password', '')

        if not self.user.check_password(current_password):
            raise ValidationError('Wrong current password.')

        return current_password

    def clean(self):
        cleaned_data = self.cleaned_data
        new_password = cleaned_data.get('new_password', '')
        retyped_password = cleaned_data.get('retyped_password', '')

        if len(new_password) == 0 or len(retyped_password) == 0:
            raise ValidationError('Blank password fields.')

        if new_password != retyped_password:
            raise ValidationError('New password and retyped password do not match.')

        return cleaned_data

    def save(self):
        self.user.set_password(new_password)
        return self.user

any ideas?

like image 361
user3803558 Avatar asked Jul 08 '14 13:07

user3803558


1 Answers

Your issue is in this line:

super(UserProfileEditForm, self).__init__(data=data, *args, **kwargs)

It should be

super(PasswordChangeForm, self).__init__(data=data, *args, **kwargs)

It is probably a copy-paste issue, when you were copying from the other form.

Some more context here

like image 55
karthikr Avatar answered Oct 25 '22 13:10

karthikr