[Fixed]-Invitation not accepted user are also registered

1πŸ‘

βœ…


Based on the update part of your question:

raise forms.ValidationError(errors['sorry! You are not yet invited'])

There is going quite wrong here. You are saying you have a dict with sorry! You are... as a key, and expecting it to return a value.

This is what you are attempting to access:

errors = {
    'sorry! you are not yet invited': None,
}

A key like that, with exclamation marks, spaces, etc is invalid.

Note that error is not defined in the method (and not anywhere I can see in the class). If you have initialized as a class variable, you should access it with self.

If you have not yet declared the error dict with a default error message, you should create it as a class variable.

class CustomerSignupForm(forms.Form):
    errors = {
        'not_invited': "Sorry! You are not yet invited.",
    }

Now in your signup method, you can access the error message:

raise forms.ValidationError(
    self.errors['not_invited'],
    code='not_invited'
)

Based on the original question:

I’m not 100% sure right now what the problem is. But there are a few things you can take a look at and improve.

Point 1: Your variable names should explain clearly what it contains. I.e.

value = self.cleaned_data.get('email')

is a field containing an e-mail string or None. Keep it simple and clear, and keep email as variable name. If the value changes in your logic, you can rename it to a new name that clearly explains the contents of the variable. value is a too broad name, and is quite confusing.

 value = get_adapter().clean_email(value)

What is happening here? You have a print after defining value (bad name again), what does it return? What do you expect it to do?

Point 2: Keep your validation in the clean methods
Your try and except with the ValidationError should be in your form cleaning method. If it does not properly fit in one of the fields that are being cleaned, you should override the clean method, run the superβ€˜s clean method and add the custom method that validates what you want.

Point 3: The signup method.
I’ve not seen a place where you call the signup method. It is not inherited from forms.Form, so it is not yet called as far as I can see.

Note: I’m not going to create any new answers to this topic, I will be updating this β€˜answer’.

πŸ‘€Nrzonline

Leave a comment