From 4abd9cd3d437a149973655af10ed49654efb57dd Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Wed, 2 Jan 2013 18:56:25 -0500 Subject: [PATCH] get closer to working again --- common/djangoapps/student/models.py | 57 ++++++++++++++++- common/djangoapps/student/views.py | 81 ++++++++++++++----------- lms/templates/test_center_register.html | 76 ++++++++++++++--------- 3 files changed, 148 insertions(+), 66 deletions(-) diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 716c472330..88b3c3cd80 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -47,6 +47,7 @@ from django.contrib.auth.models import User from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver +from django.forms import ModelForm import comment_client as cc from django_comment_client.models import Role @@ -194,7 +195,7 @@ class TestCenterUser(models.Model): # Confirmation upload_status = models.CharField(max_length=20, blank=True) # 'Error' or 'Accepted' - uploaded_at = models.DateTimeField(null=True, db_index=True) + uploaded_at = models.DateTimeField(null=True, blank=True, db_index=True) upload_error_message = models.CharField(max_length=512, blank=True) @staticmethod @@ -206,7 +207,56 @@ class TestCenterUser(models.Model): @property def email(self): return self.user.email + + def needs_update(self, dict): +# needs_updating = any([__getattribute__(fieldname) != dict[fieldname] +# for fieldname in TestCenterUser.user_provided_fields()]) + for fieldname in TestCenterUser.user_provided_fields(): + if self.__getattribute__(fieldname) != dict[fieldname]: + return True + + return False + + def update(self, dict): + # leave user and client_candidate_id as before + self.user_updated_at = datetime.now() + for fieldname in TestCenterUser.user_provided_fields(): + self.__setattr__(fieldname, dict[fieldname]) + @staticmethod + def create(user, dict): + testcenter_user = TestCenterUser(user=user) + testcenter_user.update(dict) + # testcenter_user.candidate_id remains unset + # TODO: assign an ID of our own: + testcenter_user.client_candidate_id = 'edx' + '123456' # some unique value + + +class TestCenterUserForm(ModelForm): + class Meta: + model = TestCenterUser + fields = ( 'first_name', 'middle_name', 'last_name', 'suffix', 'salutation', + 'address_1', 'address_2', 'address_3', 'city', 'state', 'postal_code', 'country', + 'phone', 'extension', 'phone_country_code', 'fax', 'fax_country_code', 'company_name') + + + + + + +ACCOMODATION_CODES = ( + ('EQPMNT', 'Equipment'), + ('ET12ET', 'Extra Time - 1/2 Exam Time'), + ('ET30MN', 'Extra Time - 30 Minutes'), + ('ETDBTM', 'Extra Time - Double Time'), + ('SEPRMM', 'Separate Room'), + ('SRREAD', 'Separate Room & Reader'), + ('SRRERC', 'Separate Room & Reader/Recorder'), + ('SRRECR', 'Separate Room & Recorder'), + ('SRSEAN', 'Separate Room & Service Animal'), + ('SRSGNR', 'Separate Room & Sign Lang Interp'), + ) + class TestCenterRegistration(models.Model): """ This is our representation of a user's registration for in-person testing, @@ -242,7 +292,8 @@ class TestCenterRegistration(models.Model): exam_series_code = models.CharField(max_length=15, db_index=True) eligibility_appointment_date_first = models.DateField(db_index=True) eligibility_appointment_date_last = models.DateField(db_index=True) - # TODO: this should be an enumeration: + + # this is really a list of codes, using an '*' as a delimiter. accommodation_code = models.CharField(max_length=64, blank=True) # store the original text of the accommodation request. @@ -250,7 +301,7 @@ class TestCenterRegistration(models.Model): # Confirmation upload_status = models.CharField(max_length=20, blank=True) # 'Error' or 'Accepted' - uploaded_at = models.DateTimeField(null=True, db_index=True) + uploaded_at = models.DateTimeField(null=True, blank=True, db_index=True) upload_error_message = models.CharField(max_length=512, blank=True) @property diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 29d8a206cb..47992554f2 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -29,7 +29,7 @@ from bs4 import BeautifulSoup from django.core.cache import cache from django_future.csrf import ensure_csrf_cookie, csrf_exempt -from student.models import (Registration, UserProfile, TestCenterUser, TestCenterRegistration, +from student.models import (Registration, UserProfile, TestCenterUser, TestCenterUserForm, TestCenterRegistration, PendingNameChange, PendingEmailChange, CourseEnrollment, unique_id_for_user, get_testcenter_registrations_for_user_and_course) @@ -650,29 +650,41 @@ def _do_create_or_update_test_center_user(post_vars): try: testcenter_user = TestCenterUser.objects.get(user=user) # found a TestCenterUser, so check to see if it has changed - needs_updating = any([testcenter_user.__getattribute__(fieldname) != post_vars[fieldname] - for fieldname in TestCenterUser.user_provided_fields()]) - +# needs_updating = any([testcenter_user.__getattribute__(fieldname) != post_vars[fieldname] +# for fieldname in TestCenterUser.user_provided_fields()]) + needs_updating = testcenter_user.needs_update(post_vars) if needs_updating: - # leave user and client_candidate_id as before - testcenter_user.user_updated_at = datetime.datetime.now() - for fieldname in TestCenterUser.user_provided_fields(): - testcenter_user.__setattr__(fieldname, post_vars[fieldname]) +# # leave user and client_candidate_id as before +# testcenter_user.user_updated_at = datetime.datetime.now() +# for fieldname in TestCenterUser.user_provided_fields(): +# testcenter_user.__setattr__(fieldname, post_vars[fieldname]) + testcenter_user.update(post_vars) needs_saving = True except TestCenterUser.DoesNotExist: # did not find the TestCenterUser, so create a new one - testcenter_user = TestCenterUser(user=user) - for fieldname in TestCenterUser.user_provided_fields(): - testcenter_user.__setattr__(fieldname, post_vars[fieldname]) - # testcenter_user.candidate_id remains unset - testcenter_user.client_candidate_id = 'edx' + '123456' # some unique value - testcenter_user.user_updated_at = datetime.datetime.now() + testcenter_user = TestCenterUser.create(user, post_vars) +# testcenter_user = TestCenterUser(user=user) +# testcenter_user.update(post_vars) +## for fieldname in TestCenterUser.user_provided_fields(): +## testcenter_user.__setattr__(fieldname, post_vars[fieldname]) +# # testcenter_user.candidate_id remains unset +# testcenter_user.client_candidate_id = 'edx' + '123456' # some unique value +## testcenter_user.user_updated_at = datetime.datetime.now() needs_saving = True - # additional validation occurs at save time, so handle exceptions if needs_saving: try: + # first perform validation on the user information + # using a Django Form. + form = TestCenterUserForm(testcenter_user) + if not form.is_valid(): + response_data = {'success': False} + # return a list of errors... + response_data['field_errors'] = form.errors + response_data['non_field_errors'] = form.non_field_errors() + return HttpResponse(json.dumps(response_data)) + testcenter_user.save() except IntegrityError, ie: js = {'success': False} @@ -728,7 +740,7 @@ def _do_create_or_update_test_center_user(post_vars): def create_test_registration(request, post_override=None): ''' JSON call to create test registration. - Used by form in test_center_register_modal.html, which is included + Used by form in test_center_register.html, which is called from into dashboard.html ''' js = {'success': False} @@ -736,24 +748,24 @@ def create_test_registration(request, post_override=None): post_vars = post_override if post_override else request.POST # Confirm we have a properly formed request - for a in ['first_name', 'last_name', 'address_1', 'city', 'country']: - if a not in post_vars: - js['value'] = "Error (401 {field}). E-mail us.".format(field=a) - js['field'] = a - return HttpResponse(json.dumps(js)) - - # Confirm appropriate fields are filled in with something for now - for a in ['first_name', 'last_name', 'address_1', 'city', 'country']: - if len(post_vars[a]) < 2: - error_str = {'first_name': 'First name must be minimum of two characters long.', - 'last_name': 'Last name must be minimum of two characters long.', - 'address_1': 'Address must be minimum of two characters long.', - 'city': 'City must be minimum of two characters long.', - 'country': 'Country must be minimum of two characters long.', - } - js['value'] = error_str[a] - js['field'] = a - return HttpResponse(json.dumps(js)) +# for a in ['first_name', 'last_name', 'address_1', 'city', 'country']: +# if a not in post_vars: +# js['value'] = "Error (401 {field}). E-mail us.".format(field=a) +# js['field'] = a +# return HttpResponse(json.dumps(js)) +# +# # Confirm appropriate fields are filled in with something for now +# for a in ['first_name', 'last_name', 'address_1', 'city', 'country']: +# if len(post_vars[a]) < 2: +# error_str = {'first_name': 'First name must be minimum of two characters long.', +# 'last_name': 'Last name must be minimum of two characters long.', +# 'address_1': 'Address must be minimum of two characters long.', +# 'city': 'City must be minimum of two characters long.', +# 'country': 'Country must be minimum of two characters long.', +# } +# js['value'] = error_str[a] +# js['field'] = a +# return HttpResponse(json.dumps(js)) # Once the test_center_user information has been validated, create the entries: ret = _do_create_or_update_test_center_user(post_vars) @@ -791,6 +803,7 @@ def create_test_registration(request, post_override=None): js = {'success': True} return HttpResponse(json.dumps(js), mimetype="application/json") + def get_random_post_override(): """ Return a dictionary suitable for passing to post_vars of _do_create_account or post_override diff --git a/lms/templates/test_center_register.html b/lms/templates/test_center_register.html index 0860adfe6c..d6a38e1bb4 100644 --- a/lms/templates/test_center_register.html +++ b/lms/templates/test_center_register.html @@ -45,6 +45,13 @@ exam_info = course.testcenter_info If the user has already registered in the past for a test center, then also display their ID. --> + + <% + registrations = get_testcenter_registrations_for_user_and_course(user, course.id) + %> + +

@@ -67,12 +74,6 @@ exam_info = course.testcenter_info

Last Eligible Appointment Date: ${exam_info.get('Last_Eligible_Appointment_Date')}

% endif - - <% - registrations = get_testcenter_registrations_for_user_and_course(user, course.id) - %> - % if len(registrations) > 0: <% registration = registrations[0] @@ -161,14 +162,14 @@ exam_info = course.testcenter_info % if len(registrations) > 0:

- Please complete the following form to update your demographic information used in your Pearson VUE Porctored Exam. Required fields are noted by bold text and an asterisk (*). + Please complete the following form to update your demographic information used in your Pearson VUE Proctored Exam. Required fields are noted by bold text and an asterisk (*).

% else:

- Please provide the following demographic information to register for a Pearson VUE Porctored Exam. Required fields are noted by bold text and an asterisk (*). + Please provide the following demographic information to register for a Pearson VUE Proctored Exam. Required fields are noted by bold text and an asterisk (*).

% endif - + @@ -181,24 +182,24 @@ exam_info = course.testcenter_info
  1. - +
  2. - +
  3. - +
  4. - +
  5. - +
@@ -209,30 +210,34 @@ exam_info = course.testcenter_info
  1. - +
  2. - +
    - +
  3. +
    + + +
    - +
    - +
    - +
@@ -245,30 +250,30 @@ exam_info = course.testcenter_info
  • - +
    - +
    - +
  • - +
    - +
  • - +
  • @@ -312,38 +317,51 @@ exam_info = course.testcenter_info
    - \ No newline at end of file +