@allow_unvouched
@never_cache
def change_primary_email(request, email_pk):
 user = User.objects.get(pk=request.user.id)
 profile = user.userprofile
 alternate_emails = ExternalAccount.objects.filter(user=profile, type=ExternalAccount.TYPE_EMAIL)
 if (not alternate_emails.filter(pk=email_pk).exists()):
  raise Http404()
 alternate_email = alternate_emails.get(pk=email_pk)
 primary_email = user.email
 user.email = alternate_email.identifier
 alternate_email.identifier = primary_email
 with transaction.atomic():
  user.save()
  alternate_email.save()
 update_email_in_basket.delay(primary_email, user.email)
 return redirect('phonebook:profile_edit')

@ allow_unvouched @ never_cache def change_primary_email ( request , email_pk ) : user = User . objects . get ( pk = request . user . id ) profile = user . userprofile alternate_emails = ExternalAccount . objects . filter ( user = profile , type = ExternalAccount . TYPE_EMAIL ) if ( not alternate_emails . filter ( pk = email_pk ) . exists ( ) ) : raise Http404 ( ) alternate_email = alternate_emails . get ( pk = email_pk ) primary_email = user . email user . email = alternate_email . identifier alternate_email . identifier = primary_email with transaction . atomic ( ) : user . save ( ) alternate_email . save ( ) update_email_in_basket . delay ( primary_email , user . email ) return redirect ( 'phonebook:profile_edit' )
change primary email address .