def add_certificate_exception(course_key, student, certificate_exception):
 if (len(CertificateWhitelist.get_certificate_white_list(course_key, student)) > 0):
  raise ValueError(_('Student (username/email={user}) already in certificate exception list.').format(user=student.username))
 (certificate_white_list, __) = CertificateWhitelist.objects.get_or_create(user=student, course_id=course_key, defaults={'whitelist': True, 'notes': certificate_exception.get('notes', '')})
 generated_certificate = GeneratedCertificate.eligible_certificates.filter(user=student, course_id=course_key, status=CertificateStatuses.downloadable).first()
 exception = dict({'id': certificate_white_list.id, 'user_email': student.email, 'user_name': student.username, 'user_id': student.id, 'certificate_generated': (generated_certificate and generated_certificate.created_date.strftime('%B %d, %Y')), 'created': certificate_white_list.created.strftime('%A, %B %d, %Y')})
 return exception

def add_certificate_exception ( course_key , student , certificate_exception ) : if ( len ( CertificateWhitelist . get_certificate_white_list ( course_key , student ) ) > 0 ) : raise ValueError ( _ ( 'Student (username/email={user}) already in certificate exception list.' ) . format ( user = student . username ) ) ( certificate_white_list , __ ) = CertificateWhitelist . objects . get_or_create ( user = student , course_id = course_key , defaults = { 'whitelist' : True , 'notes' : certificate_exception . get ( 'notes' , '' ) } ) generated_certificate = GeneratedCertificate . eligible_certificates . filter ( user = student , course_id = course_key , status = CertificateStatuses . downloadable ) . first ( ) exception = dict ( { 'id' : certificate_white_list . id , 'user_email' : student . email , 'user_name' : student . username , 'user_id' : student . id , 'certificate_generated' : ( generated_certificate and generated_certificate . created_date . strftime ( '%B %d, %Y' ) ) , 'created' : certificate_white_list . created . strftime ( '%A, %B %d, %Y' ) } ) return exception
add a certificate exception to certificatewhitelist table .