@intercept_errors(UserAPIInternalError, ignore_errors=[UserAPIRequestError])
def update_email_opt_in(user, org, opt_in):
 (preference, _) = UserOrgTag.objects.get_or_create(user=user, org=org, key='email-optin')
 try:
  user_profile = UserProfile.objects.get(user=user)
 except ObjectDoesNotExist:
  raise UserNotFound()
 if user_profile.requires_parental_consent(age_limit=getattr(settings, 'EMAIL_OPTIN_MINIMUM_AGE', 13), default_requires_consent=False):
  opt_in = False
 preference.value = str(opt_in)
 try:
  preference.save()
  if (hasattr(settings, 'LMS_SEGMENT_KEY') and settings.LMS_SEGMENT_KEY):
   _track_update_email_opt_in(user.id, org, opt_in)
 except IntegrityError as err:
  log.warn(u'Could not update organization wide preference due to IntegrityError: {}'.format(err.message))

@ intercept_errors ( UserAPIInternalError , ignore_errors = [ UserAPIRequestError ] ) def update_email_opt_in ( user , org , opt_in ) : ( preference , _ ) = UserOrgTag . objects . get_or_create ( user = user , org = org , key = 'email-optin' ) try : user_profile = UserProfile . objects . get ( user = user ) except ObjectDoesNotExist : raise UserNotFound ( ) if user_profile . requires_parental_consent ( age_limit = getattr ( settings , 'EMAIL_OPTIN_MINIMUM_AGE' , 13 ) , default_requires_consent = False ) : opt_in = False preference . value = str ( opt_in ) try : preference . save ( ) if ( hasattr ( settings , 'LMS_SEGMENT_KEY' ) and settings . LMS_SEGMENT_KEY ) : _track_update_email_opt_in ( user . id , org , opt_in ) except IntegrityError as err : log . warn ( u'Could not update organization wide preference due to IntegrityError: {}' . format ( err . message ) )
updates a users preference for receiving org-wide emails .