diff --git a/common/djangoapps/student/management/commands/pearson_export_cdd.py b/common/djangoapps/student/management/commands/pearson_export_cdd.py index fedf6dfae1..67230c7f74 100644 --- a/common/djangoapps/student/management/commands/pearson_export_cdd.py +++ b/common/djangoapps/student/management/commands/pearson_export_cdd.py @@ -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 @@ -100,4 +99,4 @@ class Command(BaseCommand): tcu.save() - \ No newline at end of file + diff --git a/common/djangoapps/student/management/commands/pearson_export_ead.py b/common/djangoapps/student/management/commands/pearson_export_ead.py index 0e5ffb0243..de3bfc04ee 100644 --- a/common/djangoapps/student/management/commands/pearson_export_ead.py +++ b/common/djangoapps/student/management/commands/pearson_export_ead.py @@ -1,8 +1,7 @@ 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 @@ -90,6 +89,5 @@ class Command(BaseCommand): tcr.save() - - \ No newline at end of file + diff --git a/common/djangoapps/student/management/commands/pearson_make_tc_registration.py b/common/djangoapps/student/management/commands/pearson_make_tc_registration.py index 5536844cab..81a478d19d 100644 --- a/common/djangoapps/student/management/commands/pearson_make_tc_registration.py +++ b/common/djangoapps/student/management/commands/pearson_make_tc_registration.py @@ -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 = "" - 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) - 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: 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: diff --git a/common/djangoapps/student/management/commands/pearson_make_tc_user.py b/common/djangoapps/student/management/commands/pearson_make_tc_user.py index 57ee78e391..da9bfc3bd0 100644 --- a/common/djangoapps/student/management/commands/pearson_make_tc_user.py +++ b/common/djangoapps/student/management/commands/pearson_make_tc_user.py @@ -125,7 +125,7 @@ class Command(BaseCommand): ), ) args = "" - 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): diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index bfa7077176..d8e38170c8 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -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): @@ -283,15 +283,12 @@ class TestCenterUserForm(ModelForm): except UnicodeEncodeError: 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(): @@ -526,13 +523,19 @@ class TestCenterRegistrationForm(ModelForm): class Meta: 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. diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 34c8d0ecc3..0182a8edf1 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -237,7 +237,7 @@ % if registration.is_accepted:
Schedule Pearson exam -

Registration number: ${registration.client_authorization_id}

+

Registration number: ${registration.client_candidate_id}

Write this down! You’ll need it to schedule your exam.

% endif diff --git a/lms/templates/test_center_register.html b/lms/templates/test_center_register.html index 6ff1d1caec..03883d907c 100644 --- a/lms/templates/test_center_register.html +++ b/lms/templates/test_center_register.html @@ -113,7 +113,7 @@ % if registration.is_accepted:

Your registration for the Pearson exam has been processed

-

Your registration number is ${registration.client_authorization_id}. (Write this down! You’ll need it to schedule your exam.)

+

Your registration number is ${registration.client_candidate_id}. (Write this down! You’ll need it to schedule your exam.)

Schedule Pearson exam
% endif