From 15a11e9cb7b643f07e653e0923e2064f3fb810c5 Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Tue, 29 Jan 2013 11:16:23 -0500 Subject: [PATCH] add validation of accommodation codes --- .../commands/pearson_make_tc_registration.py | 3 ++- common/djangoapps/student/models.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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 2fcfa9ae48..b59241240d 100644 --- a/common/djangoapps/student/management/commands/pearson_make_tc_registration.py +++ b/common/djangoapps/student/management/commands/pearson_make_tc_registration.py @@ -179,7 +179,8 @@ class Command(BaseCommand): if (len(form.errors) > 0): print "Field Form errors encountered:" for fielderror in form.errors: - print "Field Form Error: %s" % fielderror + for msg in form.errors[fielderror]: + print "Field Form Error: {} -- {}".format(fielderror, msg) if (len(form.non_field_errors()) > 0): print "Non-field Form errors encountered:" for nonfielderror in form.non_field_errors: diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index f39cc2e119..838680c844 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -552,7 +552,15 @@ class TestCenterRegistrationForm(ModelForm): registration.save() 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. + def clean_accommodation_code(self): + code = self.cleaned_data['accommodation_code'] + if code: + code = code.upper() + codes = code.split('*') + for codeval in codes: + if codeval not in ACCOMMODATION_CODE_DICT: + raise forms.ValidationError(u'Invalid accommodation code specified: "{}"'.format(codeval)) + return code