Commit 41c6d310 by Bridger Maxwell

Restructured error returns of certificate request validation.

parent a674cc91
...@@ -30,6 +30,10 @@ def certificate_request(request): ...@@ -30,6 +30,10 @@ def certificate_request(request):
id_verify = request.POST.get('cert_request_id_verify', 'false') id_verify = request.POST.get('cert_request_id_verify', 'false')
error = '' error = ''
def return_error(error):
return HttpResponse(json.dumps({'success':False,
'error': error }))
if honor_code_verify != 'true': if honor_code_verify != 'true':
error += 'Please verify that you have followed the honor code to receive a certificate. ' error += 'Please verify that you have followed the honor code to receive a certificate. '
...@@ -39,27 +43,23 @@ def certificate_request(request): ...@@ -39,27 +43,23 @@ def certificate_request(request):
if id_verify != 'true': if id_verify != 'true':
error += 'Please certify that you understand the unique ID on the certificate. ' error += 'Please certify that you understand the unique ID on the certificate. '
if len(error) == 0: if len(error) > 0:
return return_error(error)
survey_response = record_exit_survey(request, internal_request=True) survey_response = record_exit_survey(request, internal_request=True)
if not survey_response['success']: if not survey_response['success']:
error += survey_response['error'] return return_error( survey_response['error'] )
grade = None grade = None
if len(error) == 0:
student_gradesheet = grades.grade_sheet(request.user) student_gradesheet = grades.grade_sheet(request.user)
grade = student_gradesheet['grade'] grade = student_gradesheet['grade']
if not grade: if not grade:
error += 'You have not earned a grade in this course. ' return return_error('You have not earned a grade in this course. ')
if len(error) == 0:
generate_certificate(request.user, grade) generate_certificate(request.user, grade)
return HttpResponse(json.dumps({'success':True})) return HttpResponse(json.dumps({'success':True}))
else:
return HttpResponse(json.dumps({'success':False,
'error': error }))
else: else:
#This is not a POST, we should render the page with the form #This is not a POST, we should render the page with the form
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment