Commit bc40a7f1 by Brian Wilson

make test-reg dialog non-modal, and pass course_id in URL. Add to course info.

parent c7d379be
...@@ -304,7 +304,7 @@ def change_enrollment(request): ...@@ -304,7 +304,7 @@ def change_enrollment(request):
try: try:
course = course_from_id(course_id) course = course_from_id(course_id)
except ItemNotFoundError: except ItemNotFoundError:
log.warning("User {0} tried to enroll in non-existant course {1}" log.warning("User {0} tried to enroll in non-existent course {1}"
.format(user.username, enrollment.course_id)) .format(user.username, enrollment.course_id))
return {'success': False, 'error': 'The course requested does not exist.'} return {'success': False, 'error': 'The course requested does not exist.'}
...@@ -595,6 +595,92 @@ def create_account(request, post_override=None): ...@@ -595,6 +595,92 @@ def create_account(request, post_override=None):
js = {'success': True} js = {'success': True}
return HttpResponse(json.dumps(js), mimetype="application/json") return HttpResponse(json.dumps(js), mimetype="application/json")
@login_required
@ensure_csrf_cookie
def begin_test_registration(request, course_id):
user = request.user
# we want to populate the registration page with the relevant information,
# if it already exists. Create an empty object otherwise.
try:
testcenteruser = TestCenterUser.objects.get(user=user)
except TestCenterUser.DoesNotExist:
testcenteruser = TestCenterUser()
testcenteruser.user = user
try:
course = (course_from_id(course_id))
except ItemNotFoundError:
log.error("User {0} enrolled in non-existent course {1}"
.format(user.username, course_id))
# placeholder for possible messages...
message = ""
if not user.is_active:
message = render_to_string('registration/activate_account_notice.html', {'email': user.email})
context = {'course': course,
'user': user,
'message': message,
'testcenteruser': testcenteruser,
}
return render_to_response('test_center_register.html', context)
def _do_create_or_update_test_center_user(post_vars):
"""
Given cleaned post variables, create the TestCenterUser and UserProfile objects, as well as the
registration for this user.
Returns a tuple (User, UserProfile, TestCenterUser).
Note: this function is also used for creating test users.
"""
user = User(username=post_vars['username'],
email=post_vars['email'],
is_active=False)
user.set_password(post_vars['password'])
registration = Registration()
# TODO: Rearrange so that if part of the process fails, the whole process fails.
# Right now, we can have e.g. no registration e-mail sent out and a zombie account
try:
user.save()
except IntegrityError:
js = {'success': False}
# Figure out the cause of the integrity error
if len(User.objects.filter(username=post_vars['username'])) > 0:
js['value'] = "An account with this username already exists."
js['field'] = 'username'
return HttpResponse(json.dumps(js))
if len(User.objects.filter(email=post_vars['email'])) > 0:
js['value'] = "An account with this e-mail already exists."
js['field'] = 'email'
return HttpResponse(json.dumps(js))
raise
registration.register(user)
profile = UserProfile(user=user)
profile.name = post_vars['name']
profile.level_of_education = post_vars.get('level_of_education')
profile.gender = post_vars.get('gender')
profile.mailing_address = post_vars.get('mailing_address')
profile.goals = post_vars.get('goals')
try:
profile.year_of_birth = int(post_vars['year_of_birth'])
except (ValueError, KeyError):
profile.year_of_birth = None # If they give us garbage, just ignore it instead
# of asking them to put an integer.
try:
profile.save()
except Exception:
log.exception("UserProfile creation failed for user {0}.".format(user.id))
return (user, profile, registration)
@ensure_csrf_cookie @ensure_csrf_cookie
def create_test_registration(request, post_override=None): def create_test_registration(request, post_override=None):
''' '''
......
...@@ -317,6 +317,18 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -317,6 +317,18 @@ class CourseDescriptor(SequenceDescriptor):
return self.metadata.get('end_of_course_survey_url') return self.metadata.get('end_of_course_survey_url')
@property @property
def testcenter_info(self):
"""
Pull from policy.
TODO: decide if we expect this entry to be a single test, or if multiple tests are possible
per course.
Returns None if no testcenter info specified.
"""
return self.metadata.get('testcenter_info')
@property
def title(self): def title(self):
return self.display_name return self.display_name
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
<%inherit file="main.html" /> <%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/> <%namespace name='static' file='static_content.html'/>
<%include file="test_center_register_modal.html" />
<%block name="title"><title>Dashboard</title></%block> <%block name="title"><title>Dashboard</title></%block>
...@@ -221,22 +220,31 @@ ...@@ -221,22 +220,31 @@
</hgroup> </hgroup>
<!-- TODO: need to add logic to select which of the following to display. Like certs? --> <!-- TODO: need to add logic to select which of the following to display. Like certs? -->
<div class="message message-status is-shown exam-register"> <%
<a href="#testcenter-register-modal" rel="leanModal" class="exam-button" id="exam_register_button">Register for Pearson exam</a> testcenter_info = course.testcenter_info
<p class="message-copy">Registration for the Pearson exam is now open.</p> %>
</div> % if testcenter_info is not None:
<div class="message message-status is-shown"> <%
<p class="message-copy">Your registration for the Pearson exam is pending. Within a few days, you should receive a confirmation number, which can be used to schedule your exam.</p> testcenter_register_target = reverse('begin_test_registration', args=[course.id])
</div> %>
<div class="message message-status is-shown exam-register">
<div class="message message-status is-shown exam-schedule"> <!-- <a href="#testcenter-register-modal" rel="leanModal" class="exam-button" data-course-id="${course.id}" data-course-number="${course.number}" id="exam_register_button">Register for Pearson exam</a>
<a href="#" class="exam-button">Schedule Pearson exam</a> --> <a href="${testcenter_register_target}" class="exam-button" id="exam_register_button">Register for Pearson exam</a>
<p class="exam-registration-number">Registration number: <strong>edx00015879548</strong></p> <p class="message-copy">Registration for the Pearson exam is now open.</p>
<p class="message-copy">Write this down! You’ll need it to schedule your exam.</p> </div>
</div>
<div class="message message-status is-shown">
<p class="message-copy">Your registration for the Pearson exam is pending. Within a few days, you should receive a confirmation number, which can be used to schedule your exam.</p>
</div>
<div class="message message-status is-shown exam-schedule">
<a href="#" class="exam-button">Schedule Pearson exam</a>
<p class="exam-registration-number">Registration number: <strong>edx00015879548</strong></p>
<p class="message-copy">Write this down! You’ll need it to schedule your exam.</p>
</div>
% endif
<% <%
cert_status = cert_statuses.get(course.id) cert_status = cert_statuses.get(course.id)
......
<%!
from django.core.urlresolvers import reverse
from courseware.courses import course_image_url, get_course_about_section
from courseware.access import has_access
from certificates.models import CertificateStatuses
%>
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
<%block name="title"><title>Sign Up for Pearson VUE Test Center Proctoring</title></%block>
<%block name="js_extra">
<script type="text/javascript">
(function() {
$(".unenroll").click(function(event) {
$("#unenroll_course_id").val( $(event.target).data("course-id") );
$("#unenroll_course_number").text( $(event.target).data("course-number") );
});
$(document).delegate('#unenroll_form', 'ajax:success', function(data, json, xhr) {
if(json.success) {
location.href="${reverse('dashboard')}";
} else {
if($('#unenroll_error').length == 0) {
$('#unenroll_form').prepend('<div id="unenroll_error" class="modal-form-error"></div>');
}
$('#unenroll_error').text(json.error).stop().css("display", "block");
}
});
})(this)
</script>
</%block>
<section id="testcenter-register" class="">
%if message:
<section class="dashboard-banner">
${message}
</section>
%endif
<div class="inner-wrapper">
<div id="register">
<header>
<h2></h2>
<hr>
</header>
<!-- display stuff about the exam and the course for which the user is registering.
If the user has already registered in the past for a test center, then also display
their ID. -->
<section class="info">
<hgroup>
<p class="date-block">
% if course.has_ended():
Course Completed - ${course.end_date_text}
% elif course.has_started():
Course Started - ${course.start_date_text}
% else: # hasn't started yet
Course Starts - ${course.start_date_text}
% endif
</p>
<h2 class="university">${get_course_about_section(course, 'university')}</h2>
<h3>${course.number} ${course.title}</h3>
</hgroup>
<!-- TODO: need to add logic to select which of the following to display. Like certs? -->
<%
testcenter_info = course.testcenter_info
%>
% if testcenter_info is not None:
<%
exam_info = testcenter_info.get('Final_Exam')
%>
<p>Exam Series Code: ${exam_info.get('Exam_Series_Code')}</p>
<p>First Eligible Appointment Date: ${exam_info.get('First_Eligible_Appointment_Date')}</p>
<p>Last Eligible Appointment Date: ${exam_info.get('Last_Eligible_Appointment_Date')}</p>
% endif
</section>
<form id="test_register_form" class="test_register_form" method="post" data-remote="true" action="/create_test_registration">
<div class="notice"></div>
<!-- TODO: why are both of these here? -->
<div id="register_error" class="modal-form-error" name="register_error"></div>
<div id="register_error" name="register_error"></div>
<!-- include these as pass-throughs -->
<input id="id_email" type="hidden" name="email" maxlength="75" value="${user.email}" />
<input id="id_username" type="hidden" name="username" maxlength="75" value="${user.username}" />
<!-- TODO: add the course somehow... -->
<input id="id_course_id" type="hidden" name="course_id" maxlength="75" value="${course.id}" />
<div class="input-group">
<label data-field="salutation">Salutation</label>
<input name="salutation" type="text" value="${testcenteruser.salutation}" placeholder="e.g. Dr.">
<br>
<label data-field="first_name">First Name*</label>
<input name="first_name" type="text" value="${testcenteruser.first_name}" maxlength="30" placeholder="e.g. Jane">
<br>
<label data-field="middle_name">Middle Name</label>
<input name="middle_name" type="text" value="${testcenteruser.middle_name}" placeholder="e.g. Michael">
<br>
<label data-field="last_name">Last Name*</label>
<input name="last_name" type="text" value="${testcenteruser.last_name}" placeholder="e.g. Smith">
<br>
<label data-field="suffix">Suffix</label>
<input name="suffix" type="text" value="${testcenteruser.suffix}" placeholder="e.g. Jr.">
<br>
</div>
<div class="input-group">
<label data-field="address_1">Address1*</label>
<input name="address_1" type="text" value="${testcenteruser.address_1}" placeholder="123 Main St.">
<br>
<label data-field="address_2">Address2</label>
<input name="address_2" type="text" value="${testcenteruser.address_2}" placeholder="Apartment 2B.">
<br>
<label data-field="address_3">Address3</label>
<input name="address_3" type="text" value="${testcenteruser.address_3}" placeholder="Attention: John Smith">
<br>
<label data-field="city">City</label>
<input name="city" type="text" value="${testcenteruser.city}" placeholder="Our Fair City">
<label data-field="state">State/Province</label>
<input name="state" type="text" value="${testcenteruser.state}" placeholder="MA">
<br>
<label data-field="postal_code">Postal Code</label>
<input name="postal_code" type="text" value="${testcenteruser.postal_code}" placeholder="02138">
<label data-field="country">Country Code*</label>
<input name="country" type="text" value="${testcenteruser.country}" placeholder="USA">
</div>
<div class="input-group">
<label data-field="phone">Phone*</label>
<input name="phone" type="text" value="${testcenteruser.phone}" placeholder="1-23-456-7890">
<label data-field="phone">Extension</label>
<input name="extension" type="text" value="${testcenteruser.extension}" placeholder="x123">
<label data-field="phone_country_code">Phone Country Code*</label>
<input name="phone_country_code" type="text" value="${testcenteruser.phone_country_code}" placeholder="ABC">
<br>
<label data-field="fax">Fax</label>
<input name="fax" type="text" value="${testcenteruser.fax}" placeholder="1-23-456-7891">
<label data-field="fax_country_code">Fax Country Code*</label>
<input name="fax_country_code" type="text" value="${testcenteruser.fax_country_code}" placeholder="ABC">
<br>
<label data-field="company_name">Company</label>
<input name="company_name" type="text" value="${testcenteruser.company_name}" placeholder="Acme Corporation">
</div>
<div class="input-group">
<label data-field="accommodations">Accommodations Requested</label>
<textarea name="accommodations"></textarea>
</div>
<div class="submit">
<input name="submit" type="submit" value="Register for Test">
</div>
</form>
</div>
<!--
<div class="close-modal">
<div class="inner">
<p>&#10005;</p>
</div>
</div> -->
</div>
</section>
\ No newline at end of file
...@@ -43,6 +43,7 @@ urlpatterns = ('', ...@@ -43,6 +43,7 @@ urlpatterns = ('',
url(r'^create_account$', 'student.views.create_account'), url(r'^create_account$', 'student.views.create_account'),
url(r'^activate/(?P<key>[^/]*)$', 'student.views.activate_account', name="activate"), url(r'^activate/(?P<key>[^/]*)$', 'student.views.activate_account', name="activate"),
url(r'^begin_test_registration/(?P<course_id>[^/]+/[^/]+/[^/]+)$', 'student.views.begin_test_registration', name="begin_test_registration"),
url(r'^create_test_registration$', 'student.views.create_test_registration'), url(r'^create_test_registration$', 'student.views.create_test_registration'),
url(r'^password_reset/$', 'student.views.password_reset', name='password_reset'), url(r'^password_reset/$', 'student.views.password_reset', name='password_reset'),
......
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