def xblock_view(request, course_id, usage_id, view_name):
 if (not settings.FEATURES.get('ENABLE_XBLOCK_VIEW_ENDPOINT', False)):
  log.warn("Attempt to use deactivated XBlock view endpoint - see FEATURES['ENABLE_XBLOCK_VIEW_ENDPOINT']")
  raise Http404
 if (not request.user.is_authenticated()):
  raise PermissionDenied
 try:
  course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
 except InvalidKeyError:
  raise Http404('Invalid location')
 with modulestore().bulk_operations(course_key):
  course = modulestore().get_course(course_key)
  (instance, _) = get_module_by_usage_id(request, course_id, usage_id, course=course)
  try:
   fragment = instance.render(view_name, context=request.GET)
  except NoSuchViewError:
   log.exception('Attempt to render missing view on %s: %s', instance, view_name)
   raise Http404
  hashed_resources = OrderedDict()
  for resource in fragment.resources:
   hashed_resources[hash_resource(resource)] = resource
  return JsonResponse({'html': fragment.content, 'resources': hashed_resources.items(), 'csrf_token': unicode(csrf(request)['csrf_token'])})

def xblock_view ( request , course_id , usage_id , view_name ) : if ( not settings . FEATURES . get ( 'ENABLE_XBLOCK_VIEW_ENDPOINT' , False ) ) : log . warn ( "Attempt to use deactivated XBlock view endpoint - see FEATURES['ENABLE_XBLOCK_VIEW_ENDPOINT']" ) raise Http404 if ( not request . user . is_authenticated ( ) ) : raise PermissionDenied try : course_key = SlashSeparatedCourseKey . from_deprecated_string ( course_id ) except InvalidKeyError : raise Http404 ( 'Invalid location' ) with modulestore ( ) . bulk_operations ( course_key ) : course = modulestore ( ) . get_course ( course_key ) ( instance , _ ) = get_module_by_usage_id ( request , course_id , usage_id , course = course ) try : fragment = instance . render ( view_name , context = request . GET ) except NoSuchViewError : log . exception ( 'Attempt to render missing view on %s: %s' , instance , view_name ) raise Http404 hashed_resources = OrderedDict ( ) for resource in fragment . resources : hashed_resources [ hash_resource ( resource ) ] = resource return JsonResponse ( { 'html' : fragment . content , 'resources' : hashed_resources . items ( ) , 'csrf_token' : unicode ( csrf ( request ) [ 'csrf_token' ] ) } )
returns the rendered view of a given xblock .