Commit 96da4ac5 by Brian Wilson

Add some log statements. Add missing fields to _make_tc_user, and make…

Add some log statements. Add missing fields to _make_tc_user, and make _make_tc_registration independent of course configuration (for testing)
parent 8e059ff9
from optparse import make_option from optparse import make_option
from time import strftime
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -6,6 +7,7 @@ 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.models import TestCenterUser, TestCenterRegistration, TestCenterRegistrationForm, get_testcenter_registration
from student.views import course_from_id from student.views import course_from_id
from xmodule.course_module import CourseDescriptor from xmodule.course_module import CourseDescriptor
from xmodule.modulestore.exceptions import ItemNotFoundError
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
...@@ -91,14 +93,14 @@ class Command(BaseCommand): ...@@ -91,14 +93,14 @@ class Command(BaseCommand):
raise CommandError("User {%s} does not exist".format(student)) raise CommandError("User {%s} does not exist".format(student))
# check to see if a course_id was specified, and use information from that: # check to see if a course_id was specified, and use information from that:
course = course_from_id(course_id) try:
if course is not None: course = course_from_id(course_id)
if 'ignore_registration_dates' in our_options: 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')] 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 exam = examlist[0] if len(examlist) > 0 else None
else: else:
exam = course.current_test_center_exam exam = course.current_test_center_exam
else: except ItemNotFoundError:
# otherwise use explicit values (so we don't have to define a course): # otherwise use explicit values (so we don't have to define a course):
exam_name = "Dummy Placeholder Name" exam_name = "Dummy Placeholder Name"
exam_info = { 'Exam_Series_Code': our_options['exam_series_code'], exam_info = { 'Exam_Series_Code': our_options['exam_series_code'],
...@@ -106,6 +108,10 @@ class Command(BaseCommand): ...@@ -106,6 +108,10 @@ class Command(BaseCommand):
'Last_Eligible_Appointment_Date' : our_options['eligibility_appointment_date_last'], 'Last_Eligible_Appointment_Date' : our_options['eligibility_appointment_date_last'],
} }
exam = CourseDescriptor.TestCenterExam(course_id, exam_name, exam_info) 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: if exam is None:
raise CommandError("Exam for course_id {%s} does not exist".format(course_id)) raise CommandError("Exam for course_id {%s} does not exist".format(course_id))
...@@ -167,6 +173,8 @@ class Command(BaseCommand): ...@@ -167,6 +173,8 @@ class Command(BaseCommand):
# override internal values: # override internal values:
change_internal = False 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] registration = get_testcenter_registration(student, course_id, exam_code)[0]
for internal_field in [ 'upload_error_message', 'upload_status', 'authorization_id']: for internal_field in [ 'upload_error_message', 'upload_status', 'authorization_id']:
if internal_field in our_options: if internal_field in our_options:
......
...@@ -14,16 +14,41 @@ class Command(BaseCommand): ...@@ -14,16 +14,41 @@ class Command(BaseCommand):
dest='first_name', dest='first_name',
), ),
make_option( make_option(
'--middle_name',
action='store',
dest='middle_name',
),
make_option(
'--last_name', '--last_name',
action='store', action='store',
dest='last_name', dest='last_name',
), ),
make_option( make_option(
'--suffix',
action='store',
dest='suffix',
),
make_option(
'--salutation',
action='store',
dest='salutation',
),
make_option(
'--address_1', '--address_1',
action='store', action='store',
dest='address_1', dest='address_1',
), ),
make_option( make_option(
'--address_2',
action='store',
dest='address_2',
),
make_option(
'--address_3',
action='store',
dest='address_3',
),
make_option(
'--city', '--city',
action='store', action='store',
dest='city', dest='city',
...@@ -52,11 +77,33 @@ class Command(BaseCommand): ...@@ -52,11 +77,33 @@ class Command(BaseCommand):
help='Pretty free-form (parens, spaces, dashes), but no country code' help='Pretty free-form (parens, spaces, dashes), but no country code'
), ),
make_option( make_option(
'--extension',
action='store',
dest='extension',
),
make_option(
'--phone_country_code', '--phone_country_code',
action='store', action='store',
dest='phone_country_code', dest='phone_country_code',
help='Phone country code, just "1" for the USA' 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: # internal values:
make_option( make_option(
'--client_candidate_id', '--client_candidate_id',
......
...@@ -223,8 +223,6 @@ class TestCenterUser(models.Model): ...@@ -223,8 +223,6 @@ class TestCenterUser(models.Model):
return self.user.email return self.user.email
def needs_update(self, dict): 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(): for fieldname in TestCenterUser.user_provided_fields():
if fieldname in dict and self.__getattribute__(fieldname) != dict[fieldname]: if fieldname in dict and self.__getattribute__(fieldname) != dict[fieldname]:
return True return True
...@@ -275,6 +273,7 @@ class TestCenterUserForm(ModelForm): ...@@ -275,6 +273,7 @@ class TestCenterUserForm(ModelForm):
# create additional values here: # create additional values here:
new_user.user_updated_at = datetime.utcnow() new_user.user_updated_at = datetime.utcnow()
new_user.save() new_user.save()
log.info("Updated demographic information for user's test center exam registration: username \"{}\" ".format(new_user.username))
# add validation: # add validation:
...@@ -534,6 +533,7 @@ class TestCenterRegistrationForm(ModelForm): ...@@ -534,6 +533,7 @@ class TestCenterRegistrationForm(ModelForm):
# create additional values here: # create additional values here:
registration.user_updated_at = datetime.utcnow() registration.user_updated_at = datetime.utcnow()
registration.save() 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. # TODO: add validation code for values added to accommodation_code field.
......
...@@ -694,10 +694,13 @@ def create_test_registration(request, post_override=None): ...@@ -694,10 +694,13 @@ def create_test_registration(request, post_override=None):
registrations = get_testcenter_registration(user, course_id, exam_code) registrations = get_testcenter_registration(user, course_id, exam_code)
if len(registrations) > 0: if len(registrations) > 0:
registration = registrations[0] registration = registrations[0]
# TODO: check to see if registration changed. Should check appointment dates too... # NOTE: we do not bother to check here to see if the registration has changed,
# And later should check changes in accommodation_code. # because at the moment there is no way for a user to change anything about their
# But at the moment, we don't expect anything to cause this to change # registration. They only provide an optional accommodation request once, and
# because of the registration form. # 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: else:
accommodation_request = post_vars.get('accommodation_request','') accommodation_request = post_vars.get('accommodation_request','')
...@@ -720,27 +723,25 @@ def create_test_registration(request, post_override=None): ...@@ -720,27 +723,25 @@ def create_test_registration(request, post_override=None):
# only do the following if there is accommodation text to send, # only do the following if there is accommodation text to send,
# and a destination to which to send it. # and a destination to which to send it.
# TODO: still need to create the accommodation email templates # TODO: still need to create the accommodation email templates
if 'accommodation_request' in post_vars and settings.MITX_FEATURES.get('ACCOMMODATION_EMAIL'): # if 'accommodation_request' in post_vars and 'TESTCENTER_ACCOMMODATION_REQUEST_EMAIL' in settings:
d = {'accommodation_request': post_vars['accommodation_request'] } # d = {'accommodation_request': post_vars['accommodation_request'] }
#
# composes accommodation email # # composes accommodation email
subject = render_to_string('emails/accommodation_email_subject.txt', d) # subject = render_to_string('emails/accommodation_email_subject.txt', d)
# Email subject *must not* contain newlines # # Email subject *must not* contain newlines
subject = ''.join(subject.splitlines()) # subject = ''.join(subject.splitlines())
message = render_to_string('emails/accommodation_email.txt', d) # message = render_to_string('emails/accommodation_email.txt', d)
#
# skip if destination email address is not specified # try:
try: # dest_addr = settings['TESTCENTER_ACCOMMODATION_REQUEST_EMAIL']
dest_addr = settings.MITX_FEATURES['ACCOMMODATION_EMAIL'] # from_addr = user.email
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [dest_addr], fail_silently=False) # send_mail(subject, message, from_addr, [dest_addr], fail_silently=False)
except: # except:
log.exception(sys.exc_info()) # log.exception(sys.exc_info())
response_data = {'success': False} # response_data = {'success': False}
response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ] # response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ]
return HttpResponse(json.dumps(response_data), mimetype="application/json") # return HttpResponse(json.dumps(response_data), mimetype="application/json")
# TODO: enable appropriate stat
# statsd.increment("common.student.account_created")
js = {'success': True} js = {'success': True}
return HttpResponse(json.dumps(js), mimetype="application/json") return HttpResponse(json.dumps(js), mimetype="application/json")
......
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