@transaction.non_atomic_requests
@require_POST
@require_certificate_permission
def regenerate_certificate_for_user(request):
 (params, response) = _validate_post_params(request.POST)
 if (response is not None):
  return response
 course = modulestore().get_course(params['course_key'])
 if (course is None):
  msg = _('The course {course_key} does not exist').format(course_key=params['course_key'])
  return HttpResponseBadRequest(msg)
 if (not CourseEnrollment.is_enrolled(params['user'], params['course_key'])):
  msg = _('User {username} is not enrolled in the course {course_key}').format(username=params['user'].username, course_key=params['course_key'])
  return HttpResponseBadRequest(msg)
 try:
  certificate = api.regenerate_user_certificates(params['user'], params['course_key'], course=course)
 except:
  log.exception('Could not regenerate certificates for user %s in course %s', params['user'].id, params['course_key'])
  return HttpResponseServerError(_('An unexpected error occurred while regenerating certificates.'))
 _deactivate_invalidation(certificate)
 log.info('Started regenerating certificates for user %s in course %s from the support page.', params['user'].id, params['course_key'])
 return HttpResponse(200)

@ transaction . non_atomic_requests @ require_POST @ require_certificate_permission def regenerate_certificate_for_user ( request ) : ( params , response ) = _validate_post_params ( request . POST ) if ( response is not None ) : return response course = modulestore ( ) . get_course ( params [ 'course_key' ] ) if ( course is None ) : msg = _ ( 'The course {course_key} does not exist' ) . format ( course_key = params [ 'course_key' ] ) return HttpResponseBadRequest ( msg ) if ( not CourseEnrollment . is_enrolled ( params [ 'user' ] , params [ 'course_key' ] ) ) : msg = _ ( 'User {username} is not enrolled in the course {course_key}' ) . format ( username = params [ 'user' ] . username , course_key = params [ 'course_key' ] ) return HttpResponseBadRequest ( msg ) try : certificate = api . regenerate_user_certificates ( params [ 'user' ] , params [ 'course_key' ] , course = course ) except : log . exception ( 'Could not regenerate certificates for user %s in course %s' , params [ 'user' ] . id , params [ 'course_key' ] ) return HttpResponseServerError ( _ ( 'An unexpected error occurred while regenerating certificates.' ) ) _deactivate_invalidation ( certificate ) log . info ( 'Started regenerating certificates for user %s in course %s from the support page.' , params [ 'user' ] . id , params [ 'course_key' ] ) return HttpResponse ( 200 )
regenerate certificates for a user .