Commit a24bbabe by Bridger Maxwell

Just some cleanups to the certificates / survey code.

parent 6058d8d2
...@@ -73,7 +73,3 @@ def certificate_state_for_student(student, grade): ...@@ -73,7 +73,3 @@ def certificate_state_for_student(student, grade):
else: else:
# No grade, no certificate. No exceptions # No grade, no certificate. No exceptions
return ("unavailable", None) return ("unavailable", None)
\ No newline at end of file
...@@ -46,23 +46,23 @@ def certificate_request(request): ...@@ -46,23 +46,23 @@ def certificate_request(request):
grade = None grade = None
if len(error) == 0: 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. ' error += 'You have not earned a grade in this course. '
if len(error) == 0: if len(error) == 0:
generate_certificate(request.user, grade) generate_certificate(request.user, grade)
# TODO: Send the certificate email
return HttpResponse(json.dumps({'success':True})) return HttpResponse(json.dumps({'success':True}))
else: else:
return HttpResponse(json.dumps({'success':False, return HttpResponse(json.dumps({'success':False,
'error': error })) 'error': error }))
else: else:
#This is a request for the page with the form #This is not a POST, we should render the page with the form
grade_sheet = grades.grade_sheet(request.user) grade_sheet = grades.grade_sheet(request.user)
certificate_state, certificate_download_url = certificate_state_for_student(request.user, grade_sheet['grade']) certificate_state, certificate_download_url = certificate_state_for_student(request.user, grade_sheet['grade'])
...@@ -88,21 +88,27 @@ def certificate_request(request): ...@@ -88,21 +88,27 @@ def certificate_request(request):
return render_to_response('cert_request.html', context) return render_to_response('cert_request.html', context)
# This method should only be called if the user has a grade and has requested a certificate # This method should only be called if the user has a grade and has requested a certificate
def generate_certificate(user, grade): def generate_certificate(user, grade):
# Make sure to see the comments in models.GeneratedCertificate to read about the valid # Make sure to see the comments in models.GeneratedCertificate to read about the valid
# states for a GeneratedCertificate object # states for a GeneratedCertificate object
generated_certificate = None if grade:
generated_certificate = None
try: try:
generated_certificate = GeneratedCertificate.objects.get(user = user) generated_certificate = GeneratedCertificate.objects.get(user = user)
except GeneratedCertificate.DoesNotExist: except GeneratedCertificate.DoesNotExist:
generated_certificate = GeneratedCertificate(user = user, certificate_id = uuid.uuid4().hex) generated_certificate = GeneratedCertificate(user = user, certificate_id = uuid.uuid4().hex)
generated_certificate.enabled = True generated_certificate.enabled = True
generated_certificate.save() generated_certificate.save()
certificate_id = generated_certificate.certificate_id certificate_id = generated_certificate.certificate_id
log.debug("Generating certificate for " + str(user.username) + " with ID: " + certificate_id) log.debug("Generating certificate for " + str(user.username) + " with ID: " + certificate_id)
# TODO: If the certificate was pre-generated, send the email that it is ready to download
else:
log.warning("Asked to generate a certifite for student " + str(user.username) + " but without a grade.")
...@@ -17,8 +17,8 @@ def exit_survey_list_for_student(student): ...@@ -17,8 +17,8 @@ def exit_survey_list_for_student(student):
survey_list = common_questions + chosen_questions survey_list = common_questions + chosen_questions
return survey_list return survey_list
exit_survey_questions = { exit_survey_questions = {
'common_questions' : [ 'common_questions' : [
......
...@@ -492,7 +492,6 @@ def record_exit_survey(request, internal_request = False): ...@@ -492,7 +492,6 @@ def record_exit_survey(request, internal_request = False):
return returnResults({'success':True}) return returnResults({'success':True})
else: else:
log.debug("response values: " + str( response.values() ))
if internal_request and all( value == None or value == [''] for value in response.values() ): if internal_request and all( value == None or value == [''] for value in response.values() ):
# If all values are empty, then the student didn't answer any questions. # If all values are empty, then the student didn't answer any questions.
# In the case of this being an internal request, we don't mark the survey as taken # In the case of this being an internal request, we don't mark the survey as taken
......
...@@ -54,16 +54,7 @@ $(function() { ...@@ -54,16 +54,7 @@ $(function() {
postJSON('/certificate_request', values, function(data) { postJSON('/certificate_request', values, function(data) {
if (data.success) { if (data.success) {
$("#cert_request").html("<h1>Certificate Request Received</h1><p>Thank you! We will let you know when the certificate is ready to download <a href='/profile'>from the Profile page</a>.</p>");
//Now we move the survey_survey_holder back to a safer container, and submit the survey
if ($("#survey_fieldset").length > 0) {
$("#survey_survey_holder").prepend($("#survey_fieldset").remove());
$("#survey_form").submit();
}
$("#cert_request").html("<h1>Certificate Request Received</h1><p>Thank you! A certificate is being generated. You will be notified when it is ready to download.</p>");
$(".cert_request_link").text("Certificate is being generated...");
} else { } else {
$("#cert_request_error").html(data.error).scrollMinimal(); $("#cert_request_error").html(data.error).scrollMinimal();
} }
...@@ -78,12 +69,6 @@ $(function() { ...@@ -78,12 +69,6 @@ $(function() {
postJSON('/exit_survey', values, function(data) { postJSON('/exit_survey', values, function(data) {
if (data.success) { if (data.success) {
$("#survey").html("<h1>Survey Response Recorded</h1><p>Thank you for filling out the survey!</p>"); $("#survey").html("<h1>Survey Response Recorded</h1><p>Thank you for filling out the survey!</p>");
//Make sure that the survey fieldset is removed
$("#survey_fieldset").remove();
//Remove the links to take the survey
$(".survey_offer").hide();
} else { } else {
$("#survey_error").html(data.error).scrollMinimal(); $("#survey_error").html(data.error).scrollMinimal();
} }
......
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