def certificate_status_for_student(student, course_id):
 from course_modes.models import CourseMode
 try:
  generated_certificate = GeneratedCertificate.objects.get(user=student, course_id=course_id)
  cert_status = {'status': generated_certificate.status, 'mode': generated_certificate.mode, 'uuid': generated_certificate.verify_uuid}
  if generated_certificate.grade:
   cert_status['grade'] = generated_certificate.grade
  if (generated_certificate.mode == 'audit'):
   course_mode_slugs = [mode.slug for mode in CourseMode.modes_for_course(course_id)]
   if ('honor' not in course_mode_slugs):
    cert_status['status'] = CertificateStatuses.auditing
    return cert_status
  if (generated_certificate.status == CertificateStatuses.downloadable):
   cert_status['download_url'] = generated_certificate.download_url
  return cert_status
 except GeneratedCertificate.DoesNotExist:
  pass
 return {'status': CertificateStatuses.unavailable, 'mode': GeneratedCertificate.MODES.honor, 'uuid': None}

def certificate_status_for_student ( student , course_id ) : from course_modes . models import CourseMode try : generated_certificate = GeneratedCertificate . objects . get ( user = student , course_id = course_id ) cert_status = { 'status' : generated_certificate . status , 'mode' : generated_certificate . mode , 'uuid' : generated_certificate . verify_uuid } if generated_certificate . grade : cert_status [ 'grade' ] = generated_certificate . grade if ( generated_certificate . mode == 'audit' ) : course_mode_slugs = [ mode . slug for mode in CourseMode . modes_for_course ( course_id ) ] if ( 'honor' not in course_mode_slugs ) : cert_status [ 'status' ] = CertificateStatuses . auditing return cert_status if ( generated_certificate . status == CertificateStatuses . downloadable ) : cert_status [ 'download_url' ] = generated_certificate . download_url return cert_status except GeneratedCertificate . DoesNotExist : pass return { 'status' : CertificateStatuses . unavailable , 'mode' : GeneratedCertificate . MODES . honor , 'uuid' : None }
this returns a dictionary with a key for status .