@transaction.non_atomic_requests
@require_POST
def generate_user_cert(request, course_id):
 if (not request.user.is_authenticated()):
  log.info(u'Anon user trying to generate certificate for %s', course_id)
  return HttpResponseBadRequest(_('You must be signed in to {platform_name} to create a certificate.').format(platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME)))
 student = request.user
 course_key = CourseKey.from_string(course_id)
 course = modulestore().get_course(course_key, depth=2)
 if (not course):
  return HttpResponseBadRequest(_('Course is not valid'))
 if (not is_course_passed(course, None, student, request)):
  return HttpResponseBadRequest(_('Your certificate will be available when you pass the course.'))
 certificate_status = certs_api.certificate_downloadable_status(student, course.id)
 if certificate_status['is_downloadable']:
  return HttpResponseBadRequest(_('Certificate has already been created.'))
 elif certificate_status['is_generating']:
  return HttpResponseBadRequest(_('Certificate is being created.'))
 else:
  certs_api.generate_user_certificates(student, course.id, course=course, generation_mode='self')
  _track_successful_certificate_generation(student.id, course.id)
  return HttpResponse()

@ transaction . non_atomic_requests @ require_POST def generate_user_cert ( request , course_id ) : if ( not request . user . is_authenticated ( ) ) : log . info ( u'Anon user trying to generate certificate for %s' , course_id ) return HttpResponseBadRequest ( _ ( 'You must be signed in to {platform_name} to create a certificate.' ) . format ( platform_name = configuration_helpers . get_value ( 'PLATFORM_NAME' , settings . PLATFORM_NAME ) ) ) student = request . user course_key = CourseKey . from_string ( course_id ) course = modulestore ( ) . get_course ( course_key , depth = 2 ) if ( not course ) : return HttpResponseBadRequest ( _ ( 'Course is not valid' ) ) if ( not is_course_passed ( course , None , student , request ) ) : return HttpResponseBadRequest ( _ ( 'Your certificate will be available when you pass the course.' ) ) certificate_status = certs_api . certificate_downloadable_status ( student , course . id ) if certificate_status [ 'is_downloadable' ] : return HttpResponseBadRequest ( _ ( 'Certificate has already been created.' ) ) elif certificate_status [ 'is_generating' ] : return HttpResponseBadRequest ( _ ( 'Certificate is being created.' ) ) else : certs_api . generate_user_certificates ( student , course . id , course = course , generation_mode = 'self' ) _track_successful_certificate_generation ( student . id , course . id ) return HttpResponse ( )
start generating a new certificate for the user .