Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e32dfcf0
Commit
e32dfcf0
authored
Jan 04, 2013
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get display of validation errors to work.
parent
c5cc15a9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
78 deletions
+38
-78
common/djangoapps/student/models.py
+14
-0
common/djangoapps/student/views.py
+24
-78
lms/templates/test_center_register.html
+0
-0
No files found.
common/djangoapps/student/models.py
View file @
e32dfcf0
...
@@ -303,6 +303,7 @@ class TestCenterRegistration(models.Model):
...
@@ -303,6 +303,7 @@ class TestCenterRegistration(models.Model):
eligibility_appointment_date_last
=
models
.
DateField
(
db_index
=
True
)
eligibility_appointment_date_last
=
models
.
DateField
(
db_index
=
True
)
# this is really a list of codes, using an '*' as a delimiter.
# this is really a list of codes, using an '*' as a delimiter.
# So it's not a choice list.
accommodation_code
=
models
.
CharField
(
max_length
=
64
,
blank
=
True
)
accommodation_code
=
models
.
CharField
(
max_length
=
64
,
blank
=
True
)
# store the original text of the accommodation request.
# store the original text of the accommodation request.
...
@@ -349,6 +350,19 @@ class TestCenterRegistration(models.Model):
...
@@ -349,6 +350,19 @@ class TestCenterRegistration(models.Model):
h
.
update
(
str
(
self
.
exam_series_code
))
h
.
update
(
str
(
self
.
exam_series_code
))
return
h
.
hexdigest
()
return
h
.
hexdigest
()
def
is_accepted
(
self
):
return
self
.
upload_status
==
'Accepted'
def
is_rejected
(
self
):
return
self
.
upload_status
==
'Error'
def
is_pending_accommodation
(
self
):
return
len
(
self
.
accommodation_request
)
>
0
and
self
.
accommodation_code
==
''
def
is_pending_acknowledgement
(
self
):
return
self
.
upload_status
==
''
and
not
self
.
is_pending_accommodation
()
def
get_testcenter_registrations_for_user_and_course
(
user
,
course_id
,
exam_series_code
=
None
):
def
get_testcenter_registrations_for_user_and_course
(
user
,
course_id
,
exam_series_code
=
None
):
try
:
try
:
tcu
=
TestCenterUser
.
objects
.
get
(
user
=
user
)
tcu
=
TestCenterUser
.
objects
.
get
(
user
=
user
)
...
...
common/djangoapps/student/views.py
View file @
e32dfcf0
...
@@ -594,7 +594,7 @@ def create_account(request, post_override=None):
...
@@ -594,7 +594,7 @@ def create_account(request, post_override=None):
@login_required
@login_required
@ensure_csrf_cookie
@ensure_csrf_cookie
def
begin_test_registration
(
request
,
course_id
,
form
=
None
,
message
=
''
):
def
begin_test_registration
(
request
,
course_id
):
user
=
request
.
user
user
=
request
.
user
try
:
try
:
...
@@ -605,6 +605,8 @@ def begin_test_registration(request, course_id, form=None, message=''):
...
@@ -605,6 +605,8 @@ def begin_test_registration(request, course_id, form=None, message=''):
# get the exam to be registered for:
# get the exam to be registered for:
# (For now, we just assume there is one at most.)
# (For now, we just assume there is one at most.)
# TODO: this should be an object, including the course_id and the
# exam info for a particular exam from the course.
exam_info
=
course
.
testcenter_info
exam_info
=
course
.
testcenter_info
# figure out if the user is already registered for this exam:
# figure out if the user is already registered for this exam:
...
@@ -624,16 +626,11 @@ def begin_test_registration(request, course_id, form=None, message=''):
...
@@ -624,16 +626,11 @@ def begin_test_registration(request, course_id, form=None, message=''):
except
TestCenterUser
.
DoesNotExist
:
except
TestCenterUser
.
DoesNotExist
:
testcenteruser
=
TestCenterUser
()
testcenteruser
=
TestCenterUser
()
testcenteruser
.
user
=
user
testcenteruser
.
user
=
user
if
form
is
None
:
form
=
TestCenterUserForm
(
instance
=
testcenteruser
)
context
=
{
'course'
:
course
,
context
=
{
'course'
:
course
,
'user'
:
user
,
'user'
:
user
,
'message'
:
message
,
'testcenteruser'
:
testcenteruser
,
'testcenteruser'
:
testcenteruser
,
'registration'
:
registration
,
'registration'
:
registration
,
'form'
:
form
,
'exam_info'
:
exam_info
,
'exam_info'
:
exam_info
,
}
}
...
@@ -669,32 +666,18 @@ def create_test_registration(request, post_override=None):
...
@@ -669,32 +666,18 @@ def create_test_registration(request, post_override=None):
# perform validation:
# perform validation:
if
needs_updating
:
if
needs_updating
:
log
.
info
(
"User {0} enrolled in course {1} updating demographic info for test registration"
.
format
(
user
.
username
,
course_id
))
log
.
info
(
"User {0} enrolled in course {1} updating demographic info for test registration"
.
format
(
user
.
username
,
course_id
))
try
:
# first perform validation on the user information
# first perform validation on the user information
# using a Django Form.
# using a Django Form.
form
=
TestCenterUserForm
(
instance
=
testcenter_user
,
data
=
post_vars
)
form
=
TestCenterUserForm
(
instance
=
testcenter_user
,
data
=
post_vars
)
if
form
.
is_valid
():
if
not
form
.
is_valid
():
# return begin_test_registration(request, course_id, form, 'failed to validate')
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
),
mimetype
=
"application/json"
)
form
.
update_and_save
()
form
.
update_and_save
()
except
IntegrityError
,
ie
:
else
:
js
=
{
'success'
:
False
}
response_data
=
{
'success'
:
False
}
error_msg
=
unicode
(
ie
);
# return a list of errors...
# attempt to find a field name to signal
response_data
[
'field_errors'
]
=
form
.
errors
for
fieldname
in
TestCenterUser
.
user_provided_fields
():
response_data
[
'non_field_errors'
]
=
form
.
non_field_errors
()
if
error_msg
.
find
(
fieldname
)
>=
0
:
return
HttpResponse
(
json
.
dumps
(
response_data
),
mimetype
=
"application/json"
)
js
[
'value'
]
=
error_msg
js
[
'field'
]
=
fieldname
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
# otherwise just return the error message
js
[
'value'
]
=
error_msg
js
[
'field'
]
=
"General Error"
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
# create and save the registration:
# create and save the registration:
needs_saving
=
False
needs_saving
=
False
exam_info
=
course
.
testcenter_info
exam_info
=
course
.
testcenter_info
...
@@ -712,53 +695,17 @@ def create_test_registration(request, post_override=None):
...
@@ -712,53 +695,17 @@ def create_test_registration(request, post_override=None):
accommodation_request
=
post_vars
.
get
(
'accommodations'
,
''
)
accommodation_request
=
post_vars
.
get
(
'accommodations'
,
''
)
registration
=
TestCenterRegistration
.
create
(
testcenter_user
,
course_id
,
exam_info
,
accommodation_request
)
registration
=
TestCenterRegistration
.
create
(
testcenter_user
,
course_id
,
exam_info
,
accommodation_request
)
needs_saving
=
True
needs_saving
=
True
# "client_authorization_id" is the client's unique identifier for the authorization.
# TODO: add validation of registration. (Mainly whether an accommodation request is too long.)
# This must be present for an update or delete to be sent to Pearson.
# Can we just use the id field of the registration? Lets...
if
needs_saving
:
if
needs_saving
:
try
:
registration
.
save
()
registration
.
save
()
except
IntegrityError
,
ie
:
raise
# return (user, testcenter_user, registration)
# 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))
# Once the test_center_user information has been validated, create the entries:
# ret = _do_create_or_update_test_center_user(post_vars)
# if isinstance(ret,HttpResponse): # if there was an error then return that
# return ret
#
#
# (user, testcenter_user, testcenter_registration) = ret
# 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
.
if
'accommodation'
in
post_vars
and
settings
.
MITX_FEATURES
.
get
(
'ACCOMMODATION_EMAIL'
):
# TODO: still need to create the accommodation email templates
d
=
{
'accommodation'
:
post_vars
[
'accommodation'
]
if
'accommodations'
in
post_vars
and
settings
.
MITX_FEATURES
.
get
(
'ACCOMMODATION_EMAIL'
):
}
d
=
{
'accommodations'
:
post_vars
[
'accommodations'
]
}
# 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
)
...
@@ -772,8 +719,9 @@ def create_test_registration(request, post_override=None):
...
@@ -772,8 +719,9 @@ def create_test_registration(request, post_override=None):
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
dest_addr
],
fail_silently
=
False
)
send_mail
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
,
[
dest_addr
],
fail_silently
=
False
)
except
:
except
:
log
.
exception
(
sys
.
exc_info
())
log
.
exception
(
sys
.
exc_info
())
js
[
'value'
]
=
'Could not send accommodation e-mail.'
response_data
=
{
'success'
:
False
}
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
response_data
[
'non_field_errors'
]
=
[
'Could not send accommodation e-mail.'
,
]
return
HttpResponse
(
json
.
dumps
(
response_data
),
mimetype
=
"application/json"
)
# TODO: enable appropriate stat
# TODO: enable appropriate stat
# statsd.increment("common.student.account_created")
# statsd.increment("common.student.account_created")
...
@@ -782,8 +730,6 @@ def create_test_registration(request, post_override=None):
...
@@ -782,8 +730,6 @@ def create_test_registration(request, post_override=None):
js
=
{
'success'
:
True
}
js
=
{
'success'
:
True
}
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
# return HttpResponseRedirect(reverse('dashboard'))
#return HttpResponse("Hello world")
def
get_random_post_override
():
def
get_random_post_override
():
...
...
lms/templates/test_center_register.html
View file @
e32dfcf0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment