@transaction.non_atomic_requests
@csrf_exempt
def request_certificate(request):
 if (request.method == 'POST'):
  if request.user.is_authenticated():
   username = request.user.username
   student = User.objects.get(username=username)
   course_key = SlashSeparatedCourseKey.from_deprecated_string(request.POST.get('course_id'))
   course = modulestore().get_course(course_key, depth=2)
   status = certificate_status_for_student(student, course_key)['status']
   if (status in [CertificateStatuses.unavailable, CertificateStatuses.notpassing, CertificateStatuses.error]):
    log_msg = u'Grading and certification requested for user %s in course %s via /request_certificate call'
    log.info(log_msg, username, course_key)
    status = generate_user_certificates(student, course_key, course=course)
   return HttpResponse(json.dumps({'add_status': status}), content_type='application/json')
  return HttpResponse(json.dumps({'add_status': 'ERRORANONYMOUSUSER'}), content_type='application/json')

@ transaction . non_atomic_requests @ csrf_exempt def request_certificate ( request ) : if ( request . method == 'POST' ) : if request . user . is_authenticated ( ) : username = request . user . username student = User . objects . get ( username = username ) course_key = SlashSeparatedCourseKey . from_deprecated_string ( request . POST . get ( 'course_id' ) ) course = modulestore ( ) . get_course ( course_key , depth = 2 ) status = certificate_status_for_student ( student , course_key ) [ 'status' ] if ( status in [ CertificateStatuses . unavailable , CertificateStatuses . notpassing , CertificateStatuses . error ] ) : log_msg = u'Grading and certification requested for user %s in course %s via /request_certificate call' log . info ( log_msg , username , course_key ) status = generate_user_certificates ( student , course_key , course = course ) return HttpResponse ( json . dumps ( { 'add_status' : status } ) , content_type = 'application/json' ) return HttpResponse ( json . dumps ( { 'add_status' : 'ERRORANONYMOUSUSER' } ) , content_type = 'application/json' )
request the on-demand creation of a certificate for some user .