Commit ef0f973c by Brian Wilson

display client_candidate_id when registration accepted; strip whitespace from…

display client_candidate_id when registration accepted; strip whitespace from accommodation_request; cosmetic cleanup on pearson management commands.
parent fb251cac
......@@ -2,7 +2,6 @@ import csv
from collections import OrderedDict
from datetime import datetime
from os.path import isdir
from fs.path import pathjoin
from optparse import make_option
from django.core.management.base import BaseCommand
......@@ -68,7 +67,7 @@ class Command(BaseCommand):
# used in the system.
dest = args[0]
if isdir(dest):
destfile = pathjoin(dest, uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat"))
destfile = os.path.join(dest, uploaded_at.strftime("cdd-%Y%m%d-%H%M%S.dat"))
else:
destfile = dest
......
import csv
from collections import OrderedDict
from datetime import datetime
from os.path import isdir
from fs.path import pathjoin
from os.path import isdir, join
from optparse import make_option
from django.core.management.base import BaseCommand
......@@ -61,7 +60,7 @@ class Command(BaseCommand):
# used in the system.
dest = args[0]
if isdir(dest):
destfile = pathjoin(dest, uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat"))
destfile = join(dest, uploaded_at.strftime("ead-%Y%m%d-%H%M%S.dat"))
else:
destfile = dest
......@@ -92,4 +91,3 @@ class Command(BaseCommand):
\ No newline at end of file
......@@ -37,11 +37,13 @@ class Command(BaseCommand):
'--eligibility_appointment_date_first',
action='store',
dest='eligibility_appointment_date_first',
help='use YYYY-MM-DD format if overriding existing course values, or YYYY-MM-DDTHH:MM if not using an existing course.'
),
make_option(
'--eligibility_appointment_date_last',
action='store',
dest='eligibility_appointment_date_last',
help='use YYYY-MM-DD format if overriding existing course values, or YYYY-MM-DDTHH:MM if not using an existing course.'
),
# internal values:
make_option(
......@@ -67,11 +69,11 @@ class Command(BaseCommand):
'--ignore_registration_dates',
action='store_true',
dest='ignore_registration_dates',
help='find exam info for course based on exam_series_code, even if it is not active.'
help='find exam info for course based on exam_series_code, even if the exam is not active.'
),
)
args = "<student_username course_id>"
help = "Create a TestCenterRegistration entry for a given Student"
help = "Create or modify a TestCenterRegistration entry for a given Student"
@staticmethod
def is_valid_option(option_name):
......@@ -86,11 +88,15 @@ class Command(BaseCommand):
our_options = dict((k, v) for k, v in options.items()
if Command.is_valid_option(k) and v is not None)
try:
student = User.objects.get(username=username)
except User.DoesNotExist:
raise CommandError("User \"{}\" does not exist".format(username))
try:
testcenter_user = TestCenterUser.objects.get(user=student)
except TestCenterUser.DoesNotExist:
raise CommandError("User {%s} does not exist".format(student))
raise CommandError("User \"{}\" does not have an existing demographics record".format(username))
# check to see if a course_id was specified, and use information from that:
try:
......
......@@ -125,7 +125,7 @@ class Command(BaseCommand):
),
)
args = "<student_username>"
help = "Create a TestCenterUser entry for a given Student"
help = "Create or modify a TestCenterUser entry for a given Student"
@staticmethod
def is_valid_option(option_name):
......
......@@ -229,13 +229,13 @@ class TestCenterUser(models.Model):
return False
@staticmethod
def _generate_edx_id():
def _generate_edx_id(prefix):
NUM_DIGITS = 12
return u"edX{:012}".format(randint(1, 10**NUM_DIGITS-1))
return u"{}{:012}".format(prefix, randint(1, 10**NUM_DIGITS-1))
@staticmethod
def _generate_candidate_id():
return TestCenterUser._generate_edx_id()
return TestCenterUser._generate_edx_id("edX")
@staticmethod
def create(user):
......@@ -284,15 +284,12 @@ class TestCenterUserForm(ModelForm):
return False
return True
def check_country_code(self, fieldname):
code = self.cleaned_data[fieldname]
def clean_country(self):
code = self.cleaned_data['country']
if code and len(code) != 3:
raise forms.ValidationError(u'Must be three characters (ISO 3166-1): e.g. USA, CAN, MNG')
return code
def clean_country(self):
return self.check_country_code('country')
def clean(self):
cleaned_data = super(TestCenterUserForm, self).clean()
......@@ -434,7 +431,7 @@ class TestCenterRegistration(models.Model):
def create(testcenter_user, exam, accommodation_request):
registration = TestCenterRegistration(testcenter_user = testcenter_user)
registration.course_id = exam.course_id
registration.accommodation_request = accommodation_request
registration.accommodation_request = accommodation_request.strip()
registration.exam_series_code = exam.exam_series_code
registration.eligibility_appointment_date_first = strftime("%Y-%m-%d", exam.first_eligible_appointment_date)
registration.eligibility_appointment_date_last = strftime("%Y-%m-%d", exam.last_eligible_appointment_date)
......@@ -444,7 +441,7 @@ class TestCenterRegistration(models.Model):
@staticmethod
def _generate_authorization_id():
return TestCenterUser._generate_edx_id()
return TestCenterUser._generate_edx_id("edXexam")
@staticmethod
def _create_client_authorization_id():
......@@ -527,12 +524,18 @@ class TestCenterRegistrationForm(ModelForm):
model = TestCenterRegistration
fields = ( 'accommodation_request', 'accommodation_code' )
def clean_accommodation_request(self):
code = self.cleaned_data['accommodation_request']
if code and len(code) > 0:
return code.strip()
return code
def update_and_save(self):
registration = self.save(commit=False)
# create additional values here:
registration.user_updated_at = datetime.utcnow()
registration.save()
log.info("Updated registration information for user's test center exam registration: username \"{}\" course \"{}\", examcode \"{}\"".format(registration.testcenter_user.username, registration.course_id, registration.exam_series_code))
log.info("Updated registration information for user's test center exam registration: username \"{}\" course \"{}\", examcode \"{}\"".format(registration.testcenter_user.user.username, registration.course_id, registration.exam_series_code))
# TODO: add validation code for values added to accommodation_code field.
......
......@@ -237,7 +237,7 @@
% if registration.is_accepted:
<div class="message message-status is-shown exam-schedule">
<a href="${registration.registration_signup_url}" class="button exam-button">Schedule Pearson exam</a>
<p class="exam-registration-number"><a href="${testcenter_register_target}" id="exam_register_link">Registration</a> number: <strong>${registration.client_authorization_id}</strong></p>
<p class="exam-registration-number"><a href="${testcenter_register_target}" id="exam_register_link">Registration</a> number: <strong>${registration.client_candidate_id}</strong></p>
<p class="message-copy">Write this down! You’ll need it to schedule your exam.</p>
</div>
% endif
......
......@@ -113,7 +113,7 @@
% if registration.is_accepted:
<section class="status message message-flash registration-processed message-action is-shown">
<h3 class="message-title">Your registration for the Pearson exam has been processed</h3>
<p class="message-copy">Your registration number is <strong>${registration.client_authorization_id}</strong>. (Write this down! You’ll need it to schedule your exam.)</p>
<p class="message-copy">Your registration number is <strong>${registration.client_candidate_id}</strong>. (Write this down! You’ll need it to schedule your exam.)</p>
<a href="${registration.registration_signup_url}" class="button exam-button">Schedule Pearson exam</a>
</section>
% endif
......
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