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
cc31c795
Commit
cc31c795
authored
Jan 15, 2013
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes for first round of code review
parent
3b28e328
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
24 deletions
+24
-24
common/djangoapps/student/models.py
+19
-20
common/djangoapps/student/views.py
+5
-4
No files found.
common/djangoapps/student/models.py
View file @
cc31c795
...
...
@@ -221,9 +221,9 @@ class TestCenterUser(models.Model):
def
email
(
self
):
return
self
.
user
.
email
def
needs_update
(
self
,
dict
):
def
needs_update
(
self
,
fields
):
for
fieldname
in
TestCenterUser
.
user_provided_fields
():
if
fieldname
in
dict
and
self
.
__getattribute__
(
fieldname
)
!=
dict
[
fieldname
]:
if
fieldname
in
fields
and
getattr
(
self
,
fieldname
)
!=
fields
[
fieldname
]:
return
True
return
False
...
...
@@ -237,14 +237,14 @@ class TestCenterUser(models.Model):
def
_generate_candidate_id
():
return
TestCenterUser
.
_generate_edx_id
(
"edX"
)
@
static
method
def
create
(
user
):
testcenter_user
=
TestCenterUser
(
user
=
user
)
@
class
method
def
create
(
cls
,
user
):
testcenter_user
=
cls
(
user
=
user
)
# testcenter_user.candidate_id remains unset
# assign an ID of our own:
cand_id
=
TestCenterUser
.
_generate_candidate_id
()
cand_id
=
cls
.
_generate_candidate_id
()
while
TestCenterUser
.
objects
.
filter
(
client_candidate_id
=
cand_id
)
.
exists
():
cand_id
=
TestCenterUser
.
_generate_candidate_id
()
cand_id
=
cls
.
_generate_candidate_id
()
testcenter_user
.
client_candidate_id
=
cand_id
return
testcenter_user
...
...
@@ -276,14 +276,6 @@ class TestCenterUserForm(ModelForm):
# add validation:
@staticmethod
def
can_encode_as_latin
(
fieldvalue
):
try
:
fieldvalue
.
encode
(
'iso-8859-1'
)
except
UnicodeEncodeError
:
return
False
return
True
def
clean_country
(
self
):
code
=
self
.
cleaned_data
[
'country'
]
if
code
and
len
(
code
)
!=
3
:
...
...
@@ -291,6 +283,13 @@ class TestCenterUserForm(ModelForm):
return
code
def
clean
(
self
):
def
_can_encode_as_latin
(
fieldvalue
):
try
:
fieldvalue
.
encode
(
'iso-8859-1'
)
except
UnicodeEncodeError
:
return
False
return
True
cleaned_data
=
super
(
TestCenterUserForm
,
self
)
.
clean
()
# check for interactions between fields:
...
...
@@ -312,7 +311,7 @@ class TestCenterUserForm(ModelForm):
# check encoding for all fields:
cleaned_data_fields
=
[
fieldname
for
fieldname
in
cleaned_data
]
for
fieldname
in
cleaned_data_fields
:
if
not
TestCenterUserForm
.
can_encode_as_latin
(
cleaned_data
[
fieldname
]):
if
not
_
can_encode_as_latin
(
cleaned_data
[
fieldname
]):
self
.
_errors
[
fieldname
]
=
self
.
error_class
([
u'Must only use characters in Latin-1 (iso-8859-1) encoding'
])
del
cleaned_data
[
fieldname
]
...
...
@@ -427,15 +426,15 @@ class TestCenterRegistration(models.Model):
# TODO: figure out if this should really go in the database (with a default value).
return
1
@
static
method
def
create
(
testcenter_user
,
exam
,
accommodation_request
):
registration
=
TestCenterRegistration
(
testcenter_user
=
testcenter_user
)
@
class
method
def
create
(
cls
,
testcenter_user
,
exam
,
accommodation_request
):
registration
=
cls
(
testcenter_user
=
testcenter_user
)
registration
.
course_id
=
exam
.
course_id
registration
.
accommodation_request
=
accommodation_request
.
strip
()
registration
.
exam_series_code
=
exam
.
exam_series_code
registration
.
eligibility_appointment_date_first
=
strftime
(
"
%
Y-
%
m-
%
d"
,
exam
.
first_eligible_appointment_date
)
registration
.
eligibility_appointment_date_last
=
strftime
(
"
%
Y-
%
m-
%
d"
,
exam
.
last_eligible_appointment_date
)
registration
.
client_authorization_id
=
TestCenterRegistration
.
_create_client_authorization_id
()
registration
.
client_authorization_id
=
cls
.
_create_client_authorization_id
()
# accommodation_code remains blank for now, along with Pearson confirmation information
return
registration
...
...
common/djangoapps/student/views.py
View file @
cc31c795
...
...
@@ -471,8 +471,9 @@ def _do_create_account(post_vars):
try
:
profile
.
year_of_birth
=
int
(
post_vars
[
'year_of_birth'
])
except
(
ValueError
,
KeyError
):
profile
.
year_of_birth
=
None
# If they give us garbage, just ignore it instead
# of asking them to put an integer.
# If they give us garbage, just ignore it instead
# of asking them to put an integer.
profile
.
year_of_birth
=
None
try
:
profile
.
save
()
except
Exception
:
...
...
@@ -615,7 +616,7 @@ def exam_registration_info(user, course):
exam_code
=
exam_info
.
exam_series_code
registrations
=
get_testcenter_registration
(
user
,
course
.
id
,
exam_code
)
if
len
(
registrations
)
>
0
:
if
registrations
:
registration
=
registrations
[
0
]
else
:
registration
=
None
...
...
@@ -705,7 +706,7 @@ def create_exam_registration(request, post_override=None):
exam
=
course
.
current_test_center_exam
exam_code
=
exam
.
exam_series_code
registrations
=
get_testcenter_registration
(
user
,
course_id
,
exam_code
)
if
len
(
registrations
)
>
0
:
if
registrations
:
registration
=
registrations
[
0
]
# 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
...
...
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