@intercept_errors(UserAPIInternalError, ignore_errors=[UserAPIRequestError])
def update_user_preferences(requesting_user, update, user=None):
 if ((not user) or isinstance(user, basestring)):
  user = _get_authorized_user(requesting_user, user)
 else:
  _check_authorized(requesting_user, user.username)
 errors = {}
 serializers = {}
 for preference_key in update.keys():
  preference_value = update[preference_key]
  if (preference_value is not None):
   try:
    serializer = create_user_preference_serializer(user, preference_key, preference_value)
    validate_user_preference_serializer(serializer, preference_key, preference_value)
    serializers[preference_key] = serializer
   except PreferenceValidationError as error:
    preference_error = error.preference_errors[preference_key]
    errors[preference_key] = {'developer_message': preference_error['developer_message'], 'user_message': preference_error['user_message']}
 if errors:
  raise PreferenceValidationError(errors)
 for preference_key in update.keys():
  preference_value = update[preference_key]
  if (preference_value is not None):
   try:
    serializer = serializers[preference_key]
    serializer.save()
   except Exception as error:
    raise _create_preference_update_error(preference_key, preference_value, error)
  else:
   delete_user_preference(requesting_user, preference_key)

@ intercept_errors ( UserAPIInternalError , ignore_errors = [ UserAPIRequestError ] ) def update_user_preferences ( requesting_user , update , user = None ) : if ( ( not user ) or isinstance ( user , basestring ) ) : user = _get_authorized_user ( requesting_user , user ) else : _check_authorized ( requesting_user , user . username ) errors = { } serializers = { } for preference_key in update . keys ( ) : preference_value = update [ preference_key ] if ( preference_value is not None ) : try : serializer = create_user_preference_serializer ( user , preference_key , preference_value ) validate_user_preference_serializer ( serializer , preference_key , preference_value ) serializers [ preference_key ] = serializer except PreferenceValidationError as error : preference_error = error . preference_errors [ preference_key ] errors [ preference_key ] = { 'developer_message' : preference_error [ 'developer_message' ] , 'user_message' : preference_error [ 'user_message' ] } if errors : raise PreferenceValidationError ( errors ) for preference_key in update . keys ( ) : preference_value = update [ preference_key ] if ( preference_value is not None ) : try : serializer = serializers [ preference_key ] serializer . save ( ) except Exception as error : raise _create_preference_update_error ( preference_key , preference_value , error ) else : delete_user_preference ( requesting_user , preference_key )
update the user preferences for the given user .