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 ...@@ -2,7 +2,6 @@ import csv
from collections import OrderedDict from collections import OrderedDict
from datetime import datetime from datetime import datetime
from os.path import isdir from os.path import isdir
from fs.path import pathjoin
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
...@@ -68,7 +67,7 @@ class Command(BaseCommand): ...@@ -68,7 +67,7 @@ class Command(BaseCommand):
# used in the system. # used in the system.
dest = args[0] dest = args[0]
if isdir(dest): 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: else:
destfile = dest destfile = dest
...@@ -100,4 +99,4 @@ class Command(BaseCommand): ...@@ -100,4 +99,4 @@ class Command(BaseCommand):
tcu.save() tcu.save()
\ No newline at end of file
import csv import csv
from collections import OrderedDict from collections import OrderedDict
from datetime import datetime from datetime import datetime
from os.path import isdir from os.path import isdir, join
from fs.path import pathjoin
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
...@@ -61,7 +60,7 @@ class Command(BaseCommand): ...@@ -61,7 +60,7 @@ class Command(BaseCommand):
# used in the system. # used in the system.
dest = args[0] dest = args[0]
if isdir(dest): 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: else:
destfile = dest destfile = dest
...@@ -90,6 +89,5 @@ class Command(BaseCommand): ...@@ -90,6 +89,5 @@ class Command(BaseCommand):
tcr.save() tcr.save()
\ No newline at end of file
...@@ -37,11 +37,13 @@ class Command(BaseCommand): ...@@ -37,11 +37,13 @@ class Command(BaseCommand):
'--eligibility_appointment_date_first', '--eligibility_appointment_date_first',
action='store', action='store',
dest='eligibility_appointment_date_first', 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( make_option(
'--eligibility_appointment_date_last', '--eligibility_appointment_date_last',
action='store', action='store',
dest='eligibility_appointment_date_last', 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: # internal values:
make_option( make_option(
...@@ -67,11 +69,11 @@ class Command(BaseCommand): ...@@ -67,11 +69,11 @@ class Command(BaseCommand):
'--ignore_registration_dates', '--ignore_registration_dates',
action='store_true', action='store_true',
dest='ignore_registration_dates', 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>" 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 @staticmethod
def is_valid_option(option_name): def is_valid_option(option_name):
...@@ -86,11 +88,15 @@ class Command(BaseCommand): ...@@ -86,11 +88,15 @@ class Command(BaseCommand):
our_options = dict((k, v) for k, v in options.items() our_options = dict((k, v) for k, v in options.items()
if Command.is_valid_option(k) and v is not None) if Command.is_valid_option(k) and v is not None)
student = User.objects.get(username=username) try:
student = User.objects.get(username=username)
except User.DoesNotExist:
raise CommandError("User \"{}\" does not exist".format(username))
try: try:
testcenter_user = TestCenterUser.objects.get(user=student) testcenter_user = TestCenterUser.objects.get(user=student)
except TestCenterUser.DoesNotExist: 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: # check to see if a course_id was specified, and use information from that:
try: try:
......
...@@ -125,7 +125,7 @@ class Command(BaseCommand): ...@@ -125,7 +125,7 @@ class Command(BaseCommand):
), ),
) )
args = "<student_username>" args = "<student_username>"
help = "Create a TestCenterUser entry for a given Student" help = "Create or modify a TestCenterUser entry for a given Student"
@staticmethod @staticmethod
def is_valid_option(option_name): def is_valid_option(option_name):
......
...@@ -229,13 +229,13 @@ class TestCenterUser(models.Model): ...@@ -229,13 +229,13 @@ class TestCenterUser(models.Model):
return False return False
@staticmethod @staticmethod
def _generate_edx_id(): def _generate_edx_id(prefix):
NUM_DIGITS = 12 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 @staticmethod
def _generate_candidate_id(): def _generate_candidate_id():
return TestCenterUser._generate_edx_id() return TestCenterUser._generate_edx_id("edX")
@staticmethod @staticmethod
def create(user): def create(user):
...@@ -283,15 +283,12 @@ class TestCenterUserForm(ModelForm): ...@@ -283,15 +283,12 @@ class TestCenterUserForm(ModelForm):
except UnicodeEncodeError: except UnicodeEncodeError:
return False return False
return True return True
def check_country_code(self, fieldname): def clean_country(self):
code = self.cleaned_data[fieldname] code = self.cleaned_data['country']
if code and len(code) != 3: if code and len(code) != 3:
raise forms.ValidationError(u'Must be three characters (ISO 3166-1): e.g. USA, CAN, MNG') raise forms.ValidationError(u'Must be three characters (ISO 3166-1): e.g. USA, CAN, MNG')
return code return code
def clean_country(self):
return self.check_country_code('country')
def clean(self): def clean(self):
cleaned_data = super(TestCenterUserForm, self).clean() cleaned_data = super(TestCenterUserForm, self).clean()
...@@ -434,7 +431,7 @@ class TestCenterRegistration(models.Model): ...@@ -434,7 +431,7 @@ class TestCenterRegistration(models.Model):
def create(testcenter_user, exam, accommodation_request): def create(testcenter_user, exam, accommodation_request):
registration = TestCenterRegistration(testcenter_user = testcenter_user) registration = TestCenterRegistration(testcenter_user = testcenter_user)
registration.course_id = exam.course_id 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.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_first = strftime("%Y-%m-%d", exam.first_eligible_appointment_date)
registration.eligibility_appointment_date_last = strftime("%Y-%m-%d", exam.last_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): ...@@ -444,7 +441,7 @@ class TestCenterRegistration(models.Model):
@staticmethod @staticmethod
def _generate_authorization_id(): def _generate_authorization_id():
return TestCenterUser._generate_edx_id() return TestCenterUser._generate_edx_id("edXexam")
@staticmethod @staticmethod
def _create_client_authorization_id(): def _create_client_authorization_id():
...@@ -526,13 +523,19 @@ class TestCenterRegistrationForm(ModelForm): ...@@ -526,13 +523,19 @@ class TestCenterRegistrationForm(ModelForm):
class Meta: class Meta:
model = TestCenterRegistration model = TestCenterRegistration
fields = ( 'accommodation_request', 'accommodation_code' ) 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): def update_and_save(self):
registration = self.save(commit=False) registration = self.save(commit=False)
# create additional values here: # create additional values here:
registration.user_updated_at = datetime.utcnow() registration.user_updated_at = datetime.utcnow()
registration.save() 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. # TODO: add validation code for values added to accommodation_code field.
......
...@@ -237,7 +237,7 @@ ...@@ -237,7 +237,7 @@
% if registration.is_accepted: % if registration.is_accepted:
<div class="message message-status is-shown exam-schedule"> <div class="message message-status is-shown exam-schedule">
<a href="${registration.registration_signup_url}" class="button exam-button">Schedule Pearson exam</a> <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> <p class="message-copy">Write this down! You’ll need it to schedule your exam.</p>
</div> </div>
% endif % endif
......
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
% if registration.is_accepted: % if registration.is_accepted:
<section class="status message message-flash registration-processed message-action is-shown"> <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> <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> <a href="${registration.registration_signup_url}" class="button exam-button">Schedule Pearson exam</a>
</section> </section>
% endif % 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