My codes below do not work, please help me correct them... Thanks in advance

urlpatterns = patterns('symphony.accounts.views',
    (r'^email/change/$', 'email_change'),
    url(r'^email/change/done/$', direct_to_template,
        {'template': 'registration/email_change_done.html'}, 
name="email_change_done"),
    url(r'^email/change/error/$', direct_to_template,
        {'template': 'registration/email_change_error.html'}, 
name="email_change_error"),)

FORMS.PY
class EmailChangeForm(forms.Form):
    error_messages = {
        'email_mismatch': _("The two email fields didn't match."),
    }
    new_email1 = forms.CharField(label=_("Type new Email"))
    new_email2 = forms.CharField(label=_("Type Email again"))

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super(EmailChangeForm, self).__init__(*args, **kwargs)

    def clean_new_email2(self):
        email1 = self.cleaned_data.get('new_email1')
        email2 = self.cleaned_data.get('new_email2')
        if email1 and email2:
            if email1 != email2:
                raise forms.ValidationError(
                    self.error_messages['email_mismatch'])
        return email2
    
    def save(self, commit=True):
        self.user.email=(self.cleaned_data['new_email1'])
        if commit:
            self.user.save()
        return self.user

VIEWS.PY
def email_change(request, 
template_name='registration/email_change_form.html',
email_change_form=EmailChangeForm, success_url='email_change_done', 
error_url='email_change_error'):
        user = User.objects.using('default').get(email=request.user.email)
         if request.method == "POST":
            form = email_change_form(user=user, data=request.POST)
             if form.is_valid():
                form.save()
                return redirect(success_url)
        else:
            form = email_change_form(user=user)
        return render_to_response(template_name, {
        'form': form, }, context_instance=RequestContext(request))
    except User.DoesNotExist:
        return redirect(error_url)

On Tuesday, May 14, 2013 4:38:48 PM UTC+8, Sergiy Khohlov wrote:
>
> Post your models, views, forms and sometimes a template 
>
> Many thanks,
>
> Serge
>
>
> +380 636150445
> skype: skhohlov
>
>
> On Tue, May 14, 2013 at 11:18 AM, Nathaniel <nathan...@bdpint.com<javascript:>
> > wrote:
>
>> Hi. Upon login, user can go to email_change_form.html to update their 
>> email address. They will enter their new email twice to update their 
>> profile.
>> Actually, a change email confirmation would be perfect.
>>
>>
>> On Tuesday, May 14, 2013 3:33:41 PM UTC+8, Nathaniel wrote:
>>>
>>> Hi guys. What is wrong with my codes below?
>>>
>>> class EmailChangeForm(forms.**ModelForm):
>>>     new_email1 = forms.CharField(label = _("Type new Email"))
>>>     new_email2 = forms.CharField(label = _("Type Email again"))
>>>
>>>     def __init__(self, user, *args, **kwargs):
>>>         self.user = user
>>>
>>>     def clean_new_email2(self):
>>>         email1 = self.cleaned_data.get('new_**email1')
>>>         email2 = self.cleaned_data.get('new_**email2')
>>>         if email1 and email2:
>>>             if email1 != email2:
>>>                 raise forms.ValidationError(
>>>                     self.error_messages['password_**mismatch'])
>>>         return email2
>>>         
>>>     def save(self, commit=True):
>>>         user = super(EmailChangeForm, self).save(commit=False)
>>>         user.email = self.cleaned_data["email1"]
>>>         if commit:
>>>             user.save()
>>>         return user
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to