@login_required
def preview_handler(request, usage_key_string, handler, suffix=''):
 usage_key = UsageKey.from_string(usage_key_string)
 if isinstance(usage_key, (AsideUsageKeyV1, AsideUsageKeyV2)):
  descriptor = modulestore().get_item(usage_key.usage_key)
  for aside in descriptor.runtime.get_asides(descriptor):
   if (aside.scope_ids.block_type == usage_key.aside_type):
    asides = [aside]
    instance = aside
    break
 else:
  descriptor = modulestore().get_item(usage_key)
  instance = _load_preview_module(request, descriptor)
  asides = []
 req = django_to_webob_request(request)
 try:
  resp = instance.handle(handler, req, suffix)
 except NoSuchHandlerError:
  log.exception('XBlock %s attempted to access missing handler %r', instance, handler)
  raise Http404
 except NotFoundError:
  log.exception("Module indicating to user that request doesn't exist")
  raise Http404
 except ProcessingError:
  log.warning('Module raised an error while processing AJAX request', exc_info=True)
  return HttpResponseBadRequest()
 except Exception:
  log.exception('error processing ajax call')
  raise
 modulestore().update_item(descriptor, request.user.id, asides=asides)
 return webob_to_django_response(resp)

@ login_required def preview_handler ( request , usage_key_string , handler , suffix = '' ) : usage_key = UsageKey . from_string ( usage_key_string ) if isinstance ( usage_key , ( AsideUsageKeyV1 , AsideUsageKeyV2 ) ) : descriptor = modulestore ( ) . get_item ( usage_key . usage_key ) for aside in descriptor . runtime . get_asides ( descriptor ) : if ( aside . scope_ids . block_type == usage_key . aside_type ) : asides = [ aside ] instance = aside break else : descriptor = modulestore ( ) . get_item ( usage_key ) instance = _load_preview_module ( request , descriptor ) asides = [ ] req = django_to_webob_request ( request ) try : resp = instance . handle ( handler , req , suffix ) except NoSuchHandlerError : log . exception ( 'XBlock %s attempted to access missing handler %r' , instance , handler ) raise Http404 except NotFoundError : log . exception ( "Module indicating to user that request doesn't exist" ) raise Http404 except ProcessingError : log . warning ( 'Module raised an error while processing AJAX request' , exc_info = True ) return HttpResponseBadRequest ( ) except Exception : log . exception ( 'error processing ajax call' ) raise modulestore ( ) . update_item ( descriptor , request . user . id , asides = asides ) return webob_to_django_response ( resp )
dispatch an ajax action to an xblock usage_key_string: the usage_key_string-id of the block to dispatch to .