From 96da4ac55ede671a4f6147b60598f463cb35b943 Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Mon, 14 Jan 2013 16:27:28 -0500 Subject: [PATCH 1/2] Add some log statements. Add missing fields to _make_tc_user, and make _make_tc_registration independent of course configuration (for testing) --- .../commands/pearson_make_tc_registration.py | 14 ++++-- .../commands/pearson_make_tc_user.py | 47 ++++++++++++++++++ common/djangoapps/student/models.py | 4 +- common/djangoapps/student/views.py | 49 ++++++++++--------- 4 files changed, 85 insertions(+), 29 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 21a2da442a..5536844cab 100644 --- a/common/djangoapps/student/management/commands/pearson_make_tc_registration.py +++ b/common/djangoapps/student/management/commands/pearson_make_tc_registration.py @@ -1,4 +1,5 @@ from optparse import make_option +from time import strftime from django.contrib.auth.models import User from django.core.management.base import BaseCommand, CommandError @@ -6,6 +7,7 @@ from django.core.management.base import BaseCommand, CommandError from student.models import TestCenterUser, TestCenterRegistration, TestCenterRegistrationForm, get_testcenter_registration from student.views import course_from_id from xmodule.course_module import CourseDescriptor +from xmodule.modulestore.exceptions import ItemNotFoundError class Command(BaseCommand): option_list = BaseCommand.option_list + ( @@ -91,14 +93,14 @@ class Command(BaseCommand): raise CommandError("User {%s} does not exist".format(student)) # check to see if a course_id was specified, and use information from that: - course = course_from_id(course_id) - if course is not None: + try: + course = course_from_id(course_id) if 'ignore_registration_dates' in our_options: examlist = [exam for exam in course.test_center_exams if exam.exam_series_code == our_options.get('exam_series_code')] exam = examlist[0] if len(examlist) > 0 else None else: exam = course.current_test_center_exam - else: + except ItemNotFoundError: # otherwise use explicit values (so we don't have to define a course): exam_name = "Dummy Placeholder Name" exam_info = { 'Exam_Series_Code': our_options['exam_series_code'], @@ -106,6 +108,10 @@ class Command(BaseCommand): 'Last_Eligible_Appointment_Date' : our_options['eligibility_appointment_date_last'], } exam = CourseDescriptor.TestCenterExam(course_id, exam_name, exam_info) + # update option values for date_first and date_last to use YYYY-MM-DD format + # instead of YYYY-MM-DDTHH:MM + our_options['eligibility_appointment_date_first'] = strftime("%Y-%m-%d", exam.first_eligible_appointment_date) + our_options['eligibility_appointment_date_last'] = strftime("%Y-%m-%d", exam.last_eligible_appointment_date) if exam is None: raise CommandError("Exam for course_id {%s} does not exist".format(course_id)) @@ -167,6 +173,8 @@ class Command(BaseCommand): # override internal values: change_internal = False + if 'exam_series_code' in our_options: + exam_code = our_options['exam_series_code'] registration = get_testcenter_registration(student, course_id, exam_code)[0] for internal_field in [ 'upload_error_message', 'upload_status', 'authorization_id']: if internal_field in our_options: 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 2426b7f2ce..57ee78e391 100644 --- a/common/djangoapps/student/management/commands/pearson_make_tc_user.py +++ b/common/djangoapps/student/management/commands/pearson_make_tc_user.py @@ -13,16 +13,41 @@ class Command(BaseCommand): action='store', dest='first_name', ), + make_option( + '--middle_name', + action='store', + dest='middle_name', + ), make_option( '--last_name', action='store', dest='last_name', ), + make_option( + '--suffix', + action='store', + dest='suffix', + ), + make_option( + '--salutation', + action='store', + dest='salutation', + ), make_option( '--address_1', action='store', dest='address_1', ), + make_option( + '--address_2', + action='store', + dest='address_2', + ), + make_option( + '--address_3', + action='store', + dest='address_3', + ), make_option( '--city', action='store', @@ -51,12 +76,34 @@ class Command(BaseCommand): dest='phone', help='Pretty free-form (parens, spaces, dashes), but no country code' ), + make_option( + '--extension', + action='store', + dest='extension', + ), make_option( '--phone_country_code', action='store', dest='phone_country_code', help='Phone country code, just "1" for the USA' ), + make_option( + '--fax', + action='store', + dest='fax', + help='Pretty free-form (parens, spaces, dashes), but no country code' + ), + make_option( + '--fax_country_code', + action='store', + dest='fax_country_code', + help='Fax country code, just "1" for the USA' + ), + make_option( + '--company_name', + action='store', + dest='company_name', + ), # internal values: make_option( '--client_candidate_id', diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index da6f260a7d..d15afc5d83 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -223,8 +223,6 @@ class TestCenterUser(models.Model): 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 fieldname in dict and self.__getattribute__(fieldname) != dict[fieldname]: return True @@ -275,6 +273,7 @@ class TestCenterUserForm(ModelForm): # create additional values here: new_user.user_updated_at = datetime.utcnow() new_user.save() + log.info("Updated demographic information for user's test center exam registration: username \"{}\" ".format(new_user.username)) # add validation: @@ -534,6 +533,7 @@ class TestCenterRegistrationForm(ModelForm): # 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)) # TODO: add validation code for values added to accommodation_code field. diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 72c7798eb2..b41de103ca 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -694,10 +694,13 @@ def create_test_registration(request, post_override=None): registrations = get_testcenter_registration(user, course_id, exam_code) if len(registrations) > 0: registration = registrations[0] - # TODO: check to see if registration changed. Should check appointment dates too... - # And later should check changes in accommodation_code. - # But at the moment, we don't expect anything to cause this to change - # because of the registration form. + # 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 + # registration. They only provide an optional accommodation request once, and + # cannot make changes to it thereafter. + # It is possible that the exam_info content has been changed, such as the + # scheduled exam dates, but those kinds of changes should not be handled through + # this registration screen. else: accommodation_request = post_vars.get('accommodation_request','') @@ -720,27 +723,25 @@ def create_test_registration(request, post_override=None): # only do the following if there is accommodation text to send, # and a destination to which to send it. # TODO: still need to create the accommodation email templates - if 'accommodation_request' in post_vars and settings.MITX_FEATURES.get('ACCOMMODATION_EMAIL'): - d = {'accommodation_request': post_vars['accommodation_request'] } - - # composes accommodation email - subject = render_to_string('emails/accommodation_email_subject.txt', d) - # Email subject *must not* contain newlines - subject = ''.join(subject.splitlines()) - message = render_to_string('emails/accommodation_email.txt', d) +# if 'accommodation_request' in post_vars and 'TESTCENTER_ACCOMMODATION_REQUEST_EMAIL' in settings: +# d = {'accommodation_request': post_vars['accommodation_request'] } +# +# # composes accommodation email +# subject = render_to_string('emails/accommodation_email_subject.txt', d) +# # Email subject *must not* contain newlines +# subject = ''.join(subject.splitlines()) +# message = render_to_string('emails/accommodation_email.txt', d) +# +# try: +# dest_addr = settings['TESTCENTER_ACCOMMODATION_REQUEST_EMAIL'] +# from_addr = user.email +# send_mail(subject, message, from_addr, [dest_addr], fail_silently=False) +# except: +# log.exception(sys.exc_info()) +# response_data = {'success': False} +# response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ] +# return HttpResponse(json.dumps(response_data), mimetype="application/json") - # skip if destination email address is not specified - try: - dest_addr = settings.MITX_FEATURES['ACCOMMODATION_EMAIL'] - send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [dest_addr], fail_silently=False) - except: - log.exception(sys.exc_info()) - response_data = {'success': False} - response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ] - return HttpResponse(json.dumps(response_data), mimetype="application/json") - - # TODO: enable appropriate stat - # statsd.increment("common.student.account_created") js = {'success': True} return HttpResponse(json.dumps(js), mimetype="application/json") From 9e157b91f0a0ae432cf072db6bf93cbfd1abacdc Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Tue, 15 Jan 2013 00:59:34 -0500 Subject: [PATCH 2/2] change urls from xxx_test_registration to xxx_exam_registration. --- common/djangoapps/student/views.py | 11 ++++++----- lms/templates/dashboard.html | 2 +- lms/templates/test_center_register.html | 2 +- lms/urls.py | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index b41de103ca..12c869cae6 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -610,7 +610,7 @@ def exam_registration_info(user, course): @login_required @ensure_csrf_cookie -def begin_test_registration(request, course_id): +def begin_exam_registration(request, course_id): """ Handles request to register the user for the current test center exam of the specified course. Called by form in dashboard.html. @@ -649,7 +649,7 @@ def begin_test_registration(request, course_id): return render_to_response('test_center_register.html', context) @ensure_csrf_cookie -def create_test_registration(request, post_override=None): +def create_exam_registration(request, post_override=None): ''' JSON call to create a test center exam registration. Called by form in test_center_register.html @@ -662,19 +662,19 @@ def create_test_registration(request, post_override=None): user = User.objects.get(username=username) course_id = post_vars['course_id'] course = (course_from_id(course_id)) # assume it will be found.... - log.info("User {0} enrolled in course {1} clicked on enter/update demographic info for test registration".format(user.username, course_id)) try: testcenter_user = TestCenterUser.objects.get(user=user) - needs_updating = testcenter_user.needs_update(post_vars) + needs_updating = testcenter_user.needs_update(post_vars) + log.info("User {0} enrolled in course {1} {2}updating demographic info for exam registration".format(user.username, course_id, "" if needs_updating else "not ")) except TestCenterUser.DoesNotExist: # do additional initialization here: testcenter_user = TestCenterUser.create(user) needs_updating = True + log.info("User {0} enrolled in course {1} creating demographic info for exam registration".format(user.username, course_id)) # perform validation: if needs_updating: - log.info("User {0} enrolled in course {1} updating demographic info for test registration".format(user.username, course_id)) # first perform validation on the user information # using a Django Form. form = TestCenterUserForm(instance=testcenter_user, data=post_vars) @@ -706,6 +706,7 @@ def create_test_registration(request, post_override=None): accommodation_request = post_vars.get('accommodation_request','') registration = TestCenterRegistration.create(testcenter_user, exam, accommodation_request) needs_saving = True + log.info("User {0} enrolled in course {1} creating new exam registration".format(user.username, course_id)) if needs_saving: # do validation of registration. (Mainly whether an accommodation request is too long.) diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 73c7da23f9..34c8d0ecc3 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -222,7 +222,7 @@ <% testcenter_exam_info = course.current_test_center_exam registration = exam_registrations.get(course.id) - testcenter_register_target = reverse('begin_test_registration', args=[course.id]) + testcenter_register_target = reverse('begin_exam_registration', args=[course.id]) %> % if testcenter_exam_info is not None: diff --git a/lms/templates/test_center_register.html b/lms/templates/test_center_register.html index a0bba90445..679eacf3f4 100644 --- a/lms/templates/test_center_register.html +++ b/lms/templates/test_center_register.html @@ -136,7 +136,7 @@
-
+ % if registration:

diff --git a/lms/urls.py b/lms/urls.py index e81e25e86a..3b476f4821 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -43,8 +43,8 @@ urlpatterns = ('', url(r'^create_account$', 'student.views.create_account'), url(r'^activate/(?P[^/]*)$', 'student.views.activate_account', name="activate"), - url(r'^begin_test_registration/(?P[^/]+/[^/]+/[^/]+)$', 'student.views.begin_test_registration', name="begin_test_registration"), - url(r'^create_test_registration$', 'student.views.create_test_registration'), + url(r'^begin_exam_registration/(?P[^/]+/[^/]+/[^/]+)$', 'student.views.begin_exam_registration', name="begin_exam_registration"), + url(r'^create_exam_registration$', 'student.views.create_exam_registration'), url(r'^password_reset/$', 'student.views.password_reset', name='password_reset'), ## Obsolete Django views for password resets