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
1ea65455
Commit
1ea65455
authored
Jun 04, 2013
by
dcadams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Worked on reducing pep8 violations.
parent
56f81fb1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
52 deletions
+42
-52
common/djangoapps/student/views.py
+11
-17
lms/djangoapps/instructor/tests/test_enrollment.py
+2
-3
lms/djangoapps/instructor/views.py
+29
-32
No files found.
common/djangoapps/student/views.py
View file @
1ea65455
...
...
@@ -264,7 +264,6 @@ def dashboard(request):
if
not
user
.
is_active
:
message
=
render_to_string
(
'registration/activate_account_notice.html'
,
{
'email'
:
user
.
email
})
# Global staff can see what courses errored on their dashboard
staff_access
=
False
errored_courses
=
{}
...
...
@@ -355,7 +354,7 @@ def change_enrollment(request):
course
=
course_from_id
(
course_id
)
except
ItemNotFoundError
:
log
.
warning
(
"User {0} tried to enroll in non-existent course {1}"
.
format
(
user
.
username
,
course_id
))
.
format
(
user
.
username
,
course_id
))
return
HttpResponseBadRequest
(
"Course id is invalid"
)
if
not
has_access
(
user
,
course
,
'enroll'
):
...
...
@@ -363,9 +362,9 @@ def change_enrollment(request):
org
,
course_num
,
run
=
course_id
.
split
(
"/"
)
statsd
.
increment
(
"common.student.enrollment"
,
tags
=
[
"org:{0}"
.
format
(
org
),
"course:{0}"
.
format
(
course_num
),
"run:{0}"
.
format
(
run
)])
tags
=
[
"org:{0}"
.
format
(
org
),
"course:{0}"
.
format
(
course_num
),
"run:{0}"
.
format
(
run
)])
try
:
enrollment
,
created
=
CourseEnrollment
.
objects
.
get_or_create
(
user
=
user
,
course_id
=
course
.
id
)
...
...
@@ -382,9 +381,9 @@ def change_enrollment(request):
org
,
course_num
,
run
=
course_id
.
split
(
"/"
)
statsd
.
increment
(
"common.student.unenrollment"
,
tags
=
[
"org:{0}"
.
format
(
org
),
"course:{0}"
.
format
(
course_num
),
"run:{0}"
.
format
(
run
)])
tags
=
[
"org:{0}"
.
format
(
org
),
"course:{0}"
.
format
(
course_num
),
"run:{0}"
.
format
(
run
)])
return
HttpResponse
()
except
CourseEnrollment
.
DoesNotExist
:
...
...
@@ -454,7 +453,6 @@ def login_user(request, error=""):
expires_time
=
time
.
time
()
+
max_age
expires
=
cookie_date
(
expires_time
)
response
.
set_cookie
(
settings
.
EDXMKTG_COOKIE_NAME
,
'true'
,
max_age
=
max_age
,
expires
=
expires
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
...
...
@@ -515,8 +513,8 @@ def _do_create_account(post_vars):
Note: this function is also used for creating test users.
"""
user
=
User
(
username
=
post_vars
[
'username'
],
email
=
post_vars
[
'email'
],
is_active
=
False
)
email
=
post_vars
[
'email'
],
is_active
=
False
)
user
.
set_password
(
post_vars
[
'password'
])
registration
=
Registration
()
# TODO: Rearrange so that if part of the process fails, the whole process fails.
...
...
@@ -698,7 +696,6 @@ def create_account(request, post_override=None):
expires_time
=
time
.
time
()
+
max_age
expires
=
cookie_date
(
expires_time
)
response
.
set_cookie
(
settings
.
EDXMKTG_COOKIE_NAME
,
'true'
,
max_age
=
max_age
,
expires
=
expires
,
domain
=
settings
.
SESSION_COOKIE_DOMAIN
,
...
...
@@ -708,7 +705,6 @@ def create_account(request, post_override=None):
return
response
def
exam_registration_info
(
user
,
course
):
""" Returns a Registration object if the user is currently registered for a current
exam of the course. Returns None if the user is not registered, or if there is no
...
...
@@ -849,7 +845,6 @@ def create_exam_registration(request, post_override=None):
response_data
[
'non_field_errors'
]
=
form
.
non_field_errors
()
return
HttpResponse
(
json
.
dumps
(
response_data
),
mimetype
=
"application/json"
)
# 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
...
...
@@ -872,7 +867,6 @@ def create_exam_registration(request, post_override=None):
# response_data['non_field_errors'] = [ 'Could not send accommodation e-mail.', ]
# return HttpResponse(json.dumps(response_data), mimetype="application/json")
js
=
{
'success'
:
True
}
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
...
...
@@ -916,7 +910,7 @@ def activate_account(request, key):
if
not
r
[
0
]
.
user
.
is_active
:
r
[
0
]
.
activate
()
already_active
=
False
#Enroll student in any pending courses he/she may have if auto_enroll flag is set
student
=
request
.
user
ceas
=
CourseEnrollmentAllowed
.
objects
.
filter
(
email
=
student
.
email
)
...
...
@@ -924,7 +918,7 @@ def activate_account(request, key):
if
cea
.
auto_enroll
:
course_id
=
cea
.
course_id
enrollment
,
created
=
CourseEnrollment
.
objects
.
get_or_create
(
user_id
=
student
.
id
,
course_id
=
course_id
)
resp
=
render_to_response
(
"registration/activation_complete.html"
,
{
'user_logged_in'
:
user_logged_in
,
'already_active'
:
already_active
})
return
resp
if
len
(
r
)
==
0
:
...
...
lms/djangoapps/instructor/tests/test_enrollment.py
View file @
1ea65455
...
...
@@ -172,7 +172,7 @@ class TestInstructorEnrollsStudent(LoginEnrollmentTestCase):
'''
Clean user input test
'''
string
=
"abc@test.com, def@test.com ghi@test.com
\n
\n
jkl@test.com "
cleaned_string
,
cleaned_string_lc
=
get_and_clean_student_list
(
string
)
self
.
assertEqual
(
cleaned_string
,
[
'abc@test.com'
,
'def@test.com'
,
'ghi@test.com'
,
'jkl@test.com'
])
\ No newline at end of file
self
.
assertEqual
(
cleaned_string
,
[
'abc@test.com'
,
'def@test.com'
,
'ghi@test.com'
,
'jkl@test.com'
])
lms/djangoapps/instructor/views.py
View file @
1ea65455
...
...
@@ -9,7 +9,6 @@ import os
import
re
import
requests
from
requests.status_codes
import
codes
import
urllib
from
collections
import
OrderedDict
from
StringIO
import
StringIO
...
...
@@ -230,13 +229,13 @@ def instructor_dashboard(request, course_id):
if
student_to_reset
is
not
None
:
# find the module in question
if
'/'
not
in
problem_to_reset
:
# allow state of modules other than problem to be reset
problem_to_reset
=
"problem/"
+
problem_to_reset
# but problem is the default
problem_to_reset
=
"problem/"
+
problem_to_reset
# but problem is the default
try
:
(
org
,
course_name
,
_
)
=
course_id
.
split
(
"/"
)
module_state_key
=
"i4x://"
+
org
+
"/"
+
course_name
+
"/"
+
problem_to_reset
module_to_reset
=
StudentModule
.
objects
.
get
(
student_id
=
student_to_reset
.
id
,
course_id
=
course_id
,
module_state_key
=
module_state_key
)
course_id
=
course_id
,
module_state_key
=
module_state_key
)
msg
+=
"Found module to reset. "
except
Exception
:
msg
+=
"<font color='red'>Couldn't find module with that urlname. </font>"
...
...
@@ -260,19 +259,18 @@ def instructor_dashboard(request, course_id):
module_to_reset
.
state
=
json
.
dumps
(
problem_state
)
module_to_reset
.
save
()
track
.
views
.
server_track
(
request
,
'{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'
.
format
(
old_attempts
=
old_number_of_attempts
,
student
=
student_to_reset
,
problem
=
module_to_reset
.
module_state_key
,
instructor
=
request
.
user
,
course
=
course_id
),
{},
page
=
'idashboard'
)
'{instructor} reset attempts from {old_attempts} to 0 for {student} on problem {problem} in {course}'
.
format
(
old_attempts
=
old_number_of_attempts
,
student
=
student_to_reset
,
problem
=
module_to_reset
.
module_state_key
,
instructor
=
request
.
user
,
course
=
course_id
),
{},
page
=
'idashboard'
)
msg
+=
"<font color='green'>Module state successfully reset!</font>"
except
:
msg
+=
"<font color='red'>Couldn't reset module state. </font>"
elif
"Get link to student's progress page"
in
action
:
unique_student_identifier
=
request
.
POST
.
get
(
'unique_student_identifier'
,
''
)
try
:
...
...
@@ -282,12 +280,12 @@ def instructor_dashboard(request, course_id):
student_to_reset
=
User
.
objects
.
get
(
username
=
unique_student_identifier
)
progress_url
=
reverse
(
'student_progress'
,
kwargs
=
{
'course_id'
:
course_id
,
'student_id'
:
student_to_reset
.
id
})
track
.
views
.
server_track
(
request
,
'{instructor} requested progress page for {student} in {course}'
.
format
(
student
=
student_to_reset
,
instructor
=
request
.
user
,
course
=
course_id
),
{},
page
=
'idashboard'
)
'{instructor} requested progress page for {student} in {course}'
.
format
(
student
=
student_to_reset
,
instructor
=
request
.
user
,
course
=
course_id
),
{},
page
=
'idashboard'
)
msg
+=
"<a href='{0}' target='_blank'> Progress page for username: {1} with email address: {2}</a>."
.
format
(
progress_url
,
student_to_reset
.
username
,
student_to_reset
.
email
)
except
:
msg
+=
"<font color='red'>Couldn't find student with that username. </font>"
...
...
@@ -315,6 +313,7 @@ def instructor_dashboard(request, course_id):
msg2
,
rg_stud_data
=
_do_remote_gradebook
(
request
.
user
,
course
,
'get-membership'
)
datatable
=
{
'header'
:
[
'Student email'
,
'Match?'
]}
rg_students
=
[
x
[
'email'
]
for
x
in
rg_stud_data
[
'retdata'
]]
def
domatch
(
x
):
return
'<font color="green">yes</font>'
if
x
.
email
in
rg_students
else
'<font color="red">No</font>'
datatable
[
'data'
]
=
[[
x
.
email
,
domatch
(
x
)]
for
x
in
stud_data
[
'students'
]]
...
...
@@ -350,7 +349,6 @@ def instructor_dashboard(request, course_id):
msg2
,
_
=
_do_remote_gradebook
(
request
.
user
,
course
,
'post-grades'
,
files
=
files
)
msg
+=
msg2
#----------------------------------------
# Admin
...
...
@@ -416,6 +414,7 @@ def instructor_dashboard(request, course_id):
profkeys
=
[
'name'
,
'language'
,
'location'
,
'year_of_birth'
,
'gender'
,
'level_of_education'
,
'mailing_address'
,
'goals'
]
datatable
=
{
'header'
:
[
'username'
,
'email'
]
+
profkeys
}
def
getdat
(
u
):
p
=
u
.
profile
return
[
u
.
username
,
u
.
email
]
+
[
getattr
(
p
,
x
,
''
)
for
x
in
profkeys
]
...
...
@@ -424,9 +423,8 @@ def instructor_dashboard(request, course_id):
datatable
[
'title'
]
=
'Student profile data for course
%
s'
%
course_id
return
return_csv
(
'profiledata_
%
s.csv'
%
course_id
,
datatable
)
elif
'Download CSV of all responses to problem'
in
action
:
problem_to_dump
=
request
.
POST
.
get
(
'problem_to_dump'
,
''
)
problem_to_dump
=
request
.
POST
.
get
(
'problem_to_dump'
,
''
)
if
problem_to_dump
[
-
4
:]
==
".xml"
:
problem_to_dump
=
problem_to_dump
[:
-
4
]
...
...
@@ -444,7 +442,7 @@ def instructor_dashboard(request, course_id):
if
smdat
:
datatable
=
{
'header'
:
[
'username'
,
'state'
]}
datatable
[
'data'
]
=
[
[
x
.
student
.
username
,
x
.
state
]
for
x
in
smdat
]
datatable
[
'data'
]
=
[
[
x
.
student
.
username
,
x
.
state
]
for
x
in
smdat
]
datatable
[
'title'
]
=
'Student state for problem
%
s'
%
problem_to_dump
return
return_csv
(
'student_state_from_
%
s.csv'
%
problem_to_dump
,
datatable
)
...
...
@@ -481,7 +479,6 @@ def instructor_dashboard(request, course_id):
msg
+=
_list_course_forum_members
(
course_id
,
rolename
,
datatable
)
track
.
views
.
server_track
(
request
,
'list-{0}'
.
format
(
rolename
),
{},
page
=
'idashboard'
)
elif
action
==
'Remove forum admin'
:
uname
=
request
.
POST
[
'forumadmin'
]
msg
+=
_update_forum_role_membership
(
uname
,
course
,
FORUM_ROLE_ADMINISTRATOR
,
FORUM_ROLE_REMOVE
)
...
...
@@ -571,7 +568,6 @@ def instructor_dashboard(request, course_id):
ret
=
_do_enroll_students
(
course
,
course_id
,
students
,
overload
=
overload
)
datatable
=
ret
[
'datatable'
]
#----------------------------------------
# psychometrics
...
...
@@ -591,9 +587,9 @@ def instructor_dashboard(request, course_id):
logs and swallows errors.
"""
url
=
settings
.
ANALYTICS_SERVER_URL
+
\
"get?aname={}&course_id={}&apikey={}"
.
format
(
analytics_name
,
course_id
,
settings
.
ANALYTICS_API_KEY
)
"get?aname={}&course_id={}&apikey={}"
.
format
(
analytics_name
,
course_id
,
settings
.
ANALYTICS_API_KEY
)
try
:
res
=
requests
.
get
(
url
)
except
Exception
:
...
...
@@ -652,7 +648,7 @@ def instructor_dashboard(request, course_id):
'cohorts_ajax_url'
:
reverse
(
'cohorts'
,
kwargs
=
{
'course_id'
:
course_id
}),
'analytics_results'
:
analytics_results
,
}
}
return
render_to_response
(
'courseware/instructor_dashboard.html'
,
context
)
...
...
@@ -815,7 +811,7 @@ def _add_or_remove_user_group(request, username_or_email, group, group_title, ev
action
=
"Added"
if
do_add
else
"Removed"
prep
=
"to"
if
do_add
else
"from"
msg
=
'<font color="green">{action} {0} {prep} {1} group = {2}</font>'
.
format
(
user
,
group_title
,
group
.
name
,
action
=
action
,
prep
=
prep
)
action
=
action
,
prep
=
prep
)
if
do_add
:
user
.
groups
.
add
(
group
)
else
:
...
...
@@ -941,7 +937,7 @@ def gradebook(request, course_id):
'grade_summary'
:
student_grades
(
student
,
request
,
course
),
'realname'
:
student
.
profile
.
name
,
}
for
student
in
enrolled_students
]
for
student
in
enrolled_students
]
return
render_to_response
(
'courseware/gradebook.html'
,
{
'students'
:
student_info
,
...
...
@@ -1093,6 +1089,7 @@ def get_and_clean_student_list(students):
#-----------------------------------------------------------------------------
# answer distribution
def
get_answers_distribution
(
request
,
course_id
):
"""
Get the distribution of answers for all graded problems in the course.
...
...
@@ -1184,5 +1181,5 @@ def dump_grading_context(course):
msg
+=
"
%
s (format=
%
s, Assignment=
%
s
%
s)
\n
"
%
(
s
.
display_name
,
format
,
aname
,
notes
)
msg
+=
"all descriptors:
\n
"
msg
+=
"length=
%
d
\n
"
%
len
(
gc
[
'all_descriptors'
])
msg
=
'<pre>
%
s</pre>'
%
msg
.
replace
(
'<'
,
'<'
)
msg
=
'<pre>
%
s</pre>'
%
msg
.
replace
(
'<'
,
'<'
)
return
msg
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