I've created a newforms custom form in which I'm trying to update a user's email while making sure no other user currently has the new email address. Ignoring the fact that I could use the User generated forms, I was wondering if anyone could hint on the best way to pass a variable to a custom forms class.
For some unknown reason the EditUserForm class doesn't see the user variable. The error I'm getting is: "global name 'user' is not defined" from the EditUserForm class. I know for certain that request.user is valid when I make the call. I'm pretty sure I don't understand how DeclarativeFieldsMetaclass works and I think this is where I'm having problems. Anyone care to enlighten me? Call from view.py: data = {'email': request.user.email,} form = EditUserForm(request.user, data) Forms Class: class EditUserForm(forms.Form): email = forms.EmailField() def __init__(self, user, *args, **kwargs): self.user = user super(EditUserForm, self).__init__(*args, **kwargs) def clean_email(self): if user.email is not self.clean_data["email"]: email_exists = True try:email = User.objects.get(email__exact=self.clean_data["email"]) except:email_exists = False if(email_exists):raise ValidationError(u"E-mail already in use by another user.") return self.clean_data["email"] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---