def do_email_change_request(user, new_email, activation_key=None):
 pec_list = PendingEmailChange.objects.filter(user=user)
 if (len(pec_list) == 0):
  pec = PendingEmailChange()
  pec.user = user
 else:
  pec = pec_list[0]
 if (not activation_key):
  activation_key = uuid.uuid4().hex
 pec.new_email = new_email
 pec.activation_key = activation_key
 pec.save()
 context = {'key': pec.activation_key, 'old_email': user.email, 'new_email': pec.new_email}
 subject = render_to_string('emails/email_change_subject.txt', context)
 subject = ''.join(subject.splitlines())
 message = render_to_string('emails/email_change.txt', context)
 from_address = configuration_helpers.get_value('email_from_address', settings.DEFAULT_FROM_EMAIL)
 try:
  mail.send_mail(subject, message, from_address, [pec.new_email])
 except Exception:
  log.error(u'Unable to send email activation link to user from "%s"', from_address, exc_info=True)
  raise ValueError(_('Unable to send email activation link. Please try again later.'))
 tracker.emit(SETTING_CHANGE_INITIATED, {'setting': 'email', 'old': context['old_email'], 'new': context['new_email'], 'user_id': user.id})

def do_email_change_request ( user , new_email , activation_key = None ) : pec_list = PendingEmailChange . objects . filter ( user = user ) if ( len ( pec_list ) == 0 ) : pec = PendingEmailChange ( ) pec . user = user else : pec = pec_list [ 0 ] if ( not activation_key ) : activation_key = uuid . uuid4 ( ) . hex pec . new_email = new_email pec . activation_key = activation_key pec . save ( ) context = { 'key' : pec . activation_key , 'old_email' : user . email , 'new_email' : pec . new_email } subject = render_to_string ( 'emails/email_change_subject.txt' , context ) subject = '' . join ( subject . splitlines ( ) ) message = render_to_string ( 'emails/email_change.txt' , context ) from_address = configuration_helpers . get_value ( 'email_from_address' , settings . DEFAULT_FROM_EMAIL ) try : mail . send_mail ( subject , message , from_address , [ pec . new_email ] ) except Exception : log . error ( u'Unable to send email activation link to user from "%s"' , from_address , exc_info = True ) raise ValueError ( _ ( 'Unable to send email activation link. Please try again later.' ) ) tracker . emit ( SETTING_CHANGE_INITIATED , { 'setting' : 'email' , 'old' : context [ 'old_email' ] , 'new' : context [ 'new_email' ] , 'user_id' : user . id } )
given a new email for a user .