Commit cc31c795 by Brian Wilson

fixes for first round of code review

parent 3b28e328
...@@ -221,9 +221,9 @@ class TestCenterUser(models.Model): ...@@ -221,9 +221,9 @@ class TestCenterUser(models.Model):
def email(self): def email(self):
return self.user.email return self.user.email
def needs_update(self, dict): def needs_update(self, fields):
for fieldname in TestCenterUser.user_provided_fields(): for fieldname in TestCenterUser.user_provided_fields():
if fieldname in dict and self.__getattribute__(fieldname) != dict[fieldname]: if fieldname in fields and getattr(self, fieldname) != fields[fieldname]:
return True return True
return False return False
...@@ -237,14 +237,14 @@ class TestCenterUser(models.Model): ...@@ -237,14 +237,14 @@ class TestCenterUser(models.Model):
def _generate_candidate_id(): def _generate_candidate_id():
return TestCenterUser._generate_edx_id("edX") return TestCenterUser._generate_edx_id("edX")
@staticmethod @classmethod
def create(user): def create(cls, user):
testcenter_user = TestCenterUser(user=user) testcenter_user = cls(user=user)
# testcenter_user.candidate_id remains unset # testcenter_user.candidate_id remains unset
# assign an ID of our own: # assign an ID of our own:
cand_id = TestCenterUser._generate_candidate_id() cand_id = cls._generate_candidate_id()
while TestCenterUser.objects.filter(client_candidate_id=cand_id).exists(): while TestCenterUser.objects.filter(client_candidate_id=cand_id).exists():
cand_id = TestCenterUser._generate_candidate_id() cand_id = cls._generate_candidate_id()
testcenter_user.client_candidate_id = cand_id testcenter_user.client_candidate_id = cand_id
return testcenter_user return testcenter_user
...@@ -276,14 +276,6 @@ class TestCenterUserForm(ModelForm): ...@@ -276,14 +276,6 @@ class TestCenterUserForm(ModelForm):
# add validation: # add validation:
@staticmethod
def can_encode_as_latin(fieldvalue):
try:
fieldvalue.encode('iso-8859-1')
except UnicodeEncodeError:
return False
return True
def clean_country(self): def clean_country(self):
code = self.cleaned_data['country'] code = self.cleaned_data['country']
if code and len(code) != 3: if code and len(code) != 3:
...@@ -291,6 +283,13 @@ class TestCenterUserForm(ModelForm): ...@@ -291,6 +283,13 @@ class TestCenterUserForm(ModelForm):
return code return code
def clean(self): def clean(self):
def _can_encode_as_latin(fieldvalue):
try:
fieldvalue.encode('iso-8859-1')
except UnicodeEncodeError:
return False
return True
cleaned_data = super(TestCenterUserForm, self).clean() cleaned_data = super(TestCenterUserForm, self).clean()
# check for interactions between fields: # check for interactions between fields:
...@@ -312,7 +311,7 @@ class TestCenterUserForm(ModelForm): ...@@ -312,7 +311,7 @@ class TestCenterUserForm(ModelForm):
# check encoding for all fields: # check encoding for all fields:
cleaned_data_fields = [fieldname for fieldname in cleaned_data] cleaned_data_fields = [fieldname for fieldname in cleaned_data]
for fieldname in cleaned_data_fields: for fieldname in cleaned_data_fields:
if not TestCenterUserForm.can_encode_as_latin(cleaned_data[fieldname]): if not _can_encode_as_latin(cleaned_data[fieldname]):
self._errors[fieldname] = self.error_class([u'Must only use characters in Latin-1 (iso-8859-1) encoding']) self._errors[fieldname] = self.error_class([u'Must only use characters in Latin-1 (iso-8859-1) encoding'])
del cleaned_data[fieldname] del cleaned_data[fieldname]
...@@ -427,15 +426,15 @@ class TestCenterRegistration(models.Model): ...@@ -427,15 +426,15 @@ class TestCenterRegistration(models.Model):
# TODO: figure out if this should really go in the database (with a default value). # TODO: figure out if this should really go in the database (with a default value).
return 1 return 1
@staticmethod @classmethod
def create(testcenter_user, exam, accommodation_request): def create(cls, testcenter_user, exam, accommodation_request):
registration = TestCenterRegistration(testcenter_user = testcenter_user) registration = cls(testcenter_user = testcenter_user)
registration.course_id = exam.course_id registration.course_id = exam.course_id
registration.accommodation_request = accommodation_request.strip() 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)
registration.client_authorization_id = TestCenterRegistration._create_client_authorization_id() registration.client_authorization_id = cls._create_client_authorization_id()
# accommodation_code remains blank for now, along with Pearson confirmation information # accommodation_code remains blank for now, along with Pearson confirmation information
return registration return registration
......
...@@ -471,8 +471,9 @@ def _do_create_account(post_vars): ...@@ -471,8 +471,9 @@ def _do_create_account(post_vars):
try: try:
profile.year_of_birth = int(post_vars['year_of_birth']) profile.year_of_birth = int(post_vars['year_of_birth'])
except (ValueError, KeyError): except (ValueError, KeyError):
profile.year_of_birth = None # If they give us garbage, just ignore it instead # If they give us garbage, just ignore it instead
# of asking them to put an integer. # of asking them to put an integer.
profile.year_of_birth = None
try: try:
profile.save() profile.save()
except Exception: except Exception:
...@@ -615,7 +616,7 @@ def exam_registration_info(user, course): ...@@ -615,7 +616,7 @@ def exam_registration_info(user, course):
exam_code = exam_info.exam_series_code exam_code = exam_info.exam_series_code
registrations = get_testcenter_registration(user, course.id, exam_code) registrations = get_testcenter_registration(user, course.id, exam_code)
if len(registrations) > 0: if registrations:
registration = registrations[0] registration = registrations[0]
else: else:
registration = None registration = None
...@@ -705,7 +706,7 @@ def create_exam_registration(request, post_override=None): ...@@ -705,7 +706,7 @@ def create_exam_registration(request, post_override=None):
exam = course.current_test_center_exam exam = course.current_test_center_exam
exam_code = exam.exam_series_code exam_code = exam.exam_series_code
registrations = get_testcenter_registration(user, course_id, exam_code) registrations = get_testcenter_registration(user, course_id, exam_code)
if len(registrations) > 0: if registrations:
registration = registrations[0] registration = registrations[0]
# NOTE: we do not bother to check here to see if the registration has changed, # NOTE: we do not bother to check here to see if the registration has changed,
# because at the moment there is no way for a user to change anything about their # because at the moment there is no way for a user to change anything about their
......
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