Commit 6a65041e by Bridger Maxwell

Added a form on the profile page to request a certificate. Still needs major…

Added a form on the profile page to request a certificate. Still needs major styling, but the basic back-and-forth works.
parent 1837c4c0
......@@ -17,6 +17,7 @@ from mitxmako.shortcuts import render_to_response, render_to_string
#from django.views.decorators.csrf import ensure_csrf_cookie
from django.db import connection
from django.views.decorators.cache import cache_control
from django_future.csrf import ensure_csrf_cookie
from lxml import etree
......@@ -78,8 +79,8 @@ def profile(request, student_id = None):
'format_url_params' : content_parser.format_url_params,
'csrf':csrf(request)['csrf_token'],
'grade_cutoffs' : course_settings.GRADE_CUTOFFS,
'grade_sheet' : grades.grade_sheet(student),
}
context.update(grades.grade_sheet(student))
return render_to_response('profile.html', context)
......@@ -190,3 +191,37 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
result = render_to_response('courseware.html', context)
return result
@ensure_csrf_cookie
def certificate_request(request):
''' Attempt to send a certificate. '''
if request.method != "POST":
raise Http404
verification_checked = request.POST.get('cert_request_verify', 'false')
destination_email = request.POST.get('cert_request_email', '')
error = ''
if verification_checked != 'true':
error += 'You must verify that you have followed the honor code to receive a certificate. '
# TODO: Check e-mail format is correct.
if len(destination_email) < 5:
error += 'Please provide a valid email address to send the certificate. '
grade = None
if len(error) == 0:
student_gradesheet = grades.grade_sheet(request.user)
grade = student_gradesheet['grade']
if not grade:
error += 'You have not earned a grade in this course. '
if len(error) == 0:
# TODO: Send the certificate email
return HttpResponse(json.dumps({'success':True,
'value': 'A certificate is being generated and will be sent. ' }))
else:
return HttpResponse(json.dumps({'success':False,
'error': error }))
\ No newline at end of file
......@@ -12,7 +12,7 @@
<script type="text/javascript" src="/static/js/flot/jquery.flot.stack.js"></script>
<script type="text/javascript" src="/static/js/flot/jquery.flot.symbol.js"></script>
<script>
${profile_graphs.body(grade_summary, grade_cutoffs, "grade-detail-graph")}
${profile_graphs.body(grade_sheet['grade_summary'], grade_cutoffs, "grade-detail-graph")}
</script>
<script>
......@@ -100,6 +100,7 @@ $(function() {
"new_email":new_email});
return false;
});
$("#change_name_form").submit(function(){
var new_name = $('#new_name_field').val();
......@@ -119,7 +120,26 @@ $(function() {
"rationale":rationale});
return false;
});
$("#cert_request_form").submit(function(){
var values = {'cert_request_verify' : $("#cert_request_verify").is(':checked'),
'cert_request_email': $("#cert_request_email").val() };
postJSON('/certificate_request', values, function(data) {
if (data.success) {
$("#cert_request").html("<h1>Certificate Request Received</h1><p>A certificate will be sent to the specified email in a short time.</p>");
} else {
$("#cert_request_error").html(data.error);
}
});
//TODO: What do I log here?
// log_event("profile", {"type":"email_change_request",
// "old_email":"${email}",
// "new_email":new_email});
return false;
});
});
</script>
</%block>
......@@ -136,9 +156,18 @@ $(function() {
</header>
<div id="grade-detail-graph"></div>
<div id="grade">
%if grade_sheet['grade']:
Final Grade <strong>${grade_sheet['grade']}</strong>
<a rel="leanModal" class="cert_request" href="#cert_request">Request Certificate</a>
%else:
No letter grade has been earned for this course
%endif
</div>
<ol class="chapters">
%for chapter in courseware_summary:
%for chapter in grade_sheet['courseware_summary']:
%if not chapter['chapter'] == "hidden":
<li>
<h2><a href="${reverse('courseware_chapter', args=format_url_params([chapter['course'], chapter['chapter']])) }">
......@@ -308,3 +337,31 @@ $(function() {
</fieldset>
</form>
</div>
<div id="cert_request" class="leanModal_box">
<h1>Request a 6.002x Certificate</h1>
<p>You have earned the grade <strong>${grade_sheet['grade']}</strong> in this class.</p>
<p>Your name is <strong>${name}</strong></p>
<p>You can request a certificate be sent to your email, or send the certificate directly to another school or employer.</p>
<form id="cert_request_form">
<div id="cert_request_error"> </div>
<fieldset>
<ul>
<li>
<input type="checkbox" id="cert_request_verify"/>
<label> I certify that I have not violated the Honor Code for this course. The name shown above is correct. </label>
</li>
<li>
<label> Please enter your new email address: </label>
<input id="cert_request_email" type="email" value="" />
</li>
<li>
<input type="submit" id="" value="Send Certificate" />
</li>
</ul>
</fieldset>
</form>
</div>
......@@ -15,6 +15,7 @@ urlpatterns = ('',
url(r'^accept_name_change$', 'student.views.accept_name_change'),
url(r'^reject_name_change$', 'student.views.reject_name_change'),
url(r'^pending_name_changes$', 'student.views.pending_name_changes'),
url(r'^certificate_request$', 'courseware.views.certificate_request'),
url(r'^gradebook$', 'courseware.views.gradebook'),
url(r'^event$', 'track.views.user_track'),
url(r'^t/(?P<template>[^/]*)$', 'static_template_view.views.index'),
......
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