Commit 4abd9cd3 by Brian Wilson

get closer to working again

parent e170afa9
......@@ -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
......@@ -207,6 +208,55 @@ class TestCenterUser(models.Model):
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
......
......@@ -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
......
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