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
2c586ddb
Commit
2c586ddb
authored
Dec 17, 2014
by
Chris Rossi
Committed by
cewing
Apr 10, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MIT: CCX. Code Quality fixes
parent
e66fe2b3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
24 deletions
+49
-24
lms/djangoapps/pocs/tests/factories.py
+1
-0
lms/djangoapps/pocs/tests/test_utils.py
+0
-1
lms/djangoapps/pocs/tests/test_views.py
+3
-1
lms/djangoapps/pocs/views.py
+45
-22
No files found.
lms/djangoapps/pocs/tests/factories.py
View file @
2c586ddb
...
...
@@ -13,5 +13,6 @@ class PocMembershipFactory(DjangoModelFactory):
FACTORY_FOR
=
PocMembership
active
=
False
class
PocFutureMembershipFactory
(
DjangoModelFactory
):
FACTORY_FOR
=
PocFutureMembership
lms/djangoapps/pocs/tests/test_utils.py
View file @
2c586ddb
...
...
@@ -308,7 +308,6 @@ class TestEnrollEmail(ModuleStoreTestCase):
# ensure there are still no emails in the outbox now
self
.
assertEqual
(
len
(
self
.
outbox
),
0
)
def
test_enroll_non_member_no_email
(
self
):
"""register a non-member but send no email"""
self
.
create_user
()
...
...
lms/djangoapps/pocs/tests/test_views.py
View file @
2c586ddb
...
...
@@ -502,7 +502,7 @@ class TestPocGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
grades
=
response
.
mako_context
[
'grade_summary'
]
self
.
assertEqual
(
grades
[
'percent'
],
0.5
)
self
.
assertEqual
(
grades
[
'grade_breakdown'
][
0
][
'percent'
],
0.5
)
self
.
assertEqual
(
grades
[
'grade_breakdown'
][
0
][
'percent'
],
0.5
)
self
.
assertEqual
(
len
(
grades
[
'section_breakdown'
]),
4
)
...
...
@@ -524,8 +524,10 @@ def iter_blocks(course):
yield
descendant
return
visit
(
course
)
def
visible_children
(
block
):
block_get_children
=
block
.
get_children
def
get_children
():
def
iter_children
():
for
child
in
block_get_children
():
...
...
lms/djangoapps/pocs/views.py
View file @
2c586ddb
"""
Views related to the Personal Online Courses feature.
"""
import
csv
import
datetime
import
functools
...
...
@@ -40,7 +43,7 @@ from .overrides import (
from
.utils
import
enroll_email
,
unenroll_email
log
=
logging
.
getLogger
(
__name__
)
today
=
datetime
.
datetime
.
today
# for patching in tests
TODAY
=
datetime
.
datetime
.
today
# for patching in tests
def
coach_dashboard
(
view
):
...
...
@@ -51,6 +54,10 @@ def coach_dashboard(view):
"""
@functools.wraps
(
view
)
def
wrapper
(
request
,
course_id
):
"""
Wraps the view function, performing access check, loading the course,
and modifying the view's call signature.
"""
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
role
=
CoursePocCoachRole
(
course_key
)
if
not
role
.
has_user
(
request
.
user
):
...
...
@@ -79,7 +86,7 @@ def dashboard(request, course):
'gradebook_url'
:
reverse
(
'poc_gradebook'
,
kwargs
=
{
'course_id'
:
course
.
id
}),
'grades_csv_url'
:
reverse
(
'poc_grades_csv'
,
kwargs
=
{
'course_id'
:
course
.
id
}),
kwargs
=
{
'course_id'
:
course
.
id
}),
}
if
not
poc
:
context
[
'create_poc_url'
]
=
reverse
(
...
...
@@ -102,7 +109,7 @@ def create_poc(request, course):
poc
.
save
()
# Make sure start/due are overridden for entire course
start
=
today
()
.
replace
(
tzinfo
=
pytz
.
UTC
)
start
=
TODAY
()
.
replace
(
tzinfo
=
pytz
.
UTC
)
override_field_for_poc
(
poc
,
course
,
'start'
,
start
)
override_field_for_poc
(
poc
,
course
,
'due'
,
None
)
...
...
@@ -124,11 +131,16 @@ def create_poc(request, course):
@coach_dashboard
def
save_poc
(
request
,
course
):
"""
Save changes to POC
Save changes to POC
.
"""
poc
=
get_poc_for_coach
(
course
,
request
.
user
)
def
override_fields
(
parent
,
data
,
earliest
=
None
):
"""
Recursively apply POC schedule data to POC by overriding the
`visible_to_staff_only`, `start` and `due` fields for units in the
course.
"""
blocks
=
{
str
(
child
.
location
):
child
for
child
in
parent
.
get_children
()}
...
...
@@ -163,16 +175,17 @@ def save_poc(request, course):
content_type
=
'application/json'
)
def
parse_date
(
s
):
if
s
:
try
:
date
,
time
=
s
.
split
(
' '
)
year
,
month
,
day
=
map
(
int
,
date
.
split
(
'-'
))
hour
,
minute
=
map
(
int
,
time
.
split
(
':'
))
return
datetime
.
datetime
(
year
,
month
,
day
,
hour
,
minute
,
tzinfo
=
pytz
.
UTC
)
except
:
log
.
warn
(
"Unable to parse date: "
+
s
)
def
parse_date
(
datestring
):
"""
Generate a UTC datetime.datetime object from a string of the form
'YYYY-MM-DD HH:MM'. If string is empty or `None`, returns `None`.
"""
if
datestring
:
date
,
time
=
datestring
.
split
(
' '
)
year
,
month
,
day
=
map
(
int
,
date
.
split
(
'-'
))
hour
,
minute
=
map
(
int
,
time
.
split
(
':'
))
return
datetime
.
datetime
(
year
,
month
,
day
,
hour
,
minute
,
tzinfo
=
pytz
.
UTC
)
return
None
...
...
@@ -192,8 +205,12 @@ def get_poc_for_coach(course, coach):
def
get_poc_schedule
(
course
,
poc
):
"""
Generate a JSON serializable POC schedule.
"""
def
visit
(
node
,
depth
=
1
):
"""
Recursive generator function which yields POC schedule nodes.
"""
for
child
in
node
.
get_children
():
start
=
get_override_for_poc
(
poc
,
child
,
'start'
,
None
)
if
start
:
...
...
@@ -301,8 +318,11 @@ def poc_gradebook(request, course):
poc
=
get_poc_for_coach
(
course
,
request
.
user
)
with
poc_context
(
poc
):
course
.
_field_data_cache
=
{}
course
.
set_grading_policy
(
course
.
grading_policy
)
# this is so awful
# The grading policy for the MOOC is probably already cached. We need
# to make sure we have the POC grading policy loaded.
course
.
_field_data_cache
=
{}
# pylint: disable=protected-access
course
.
set_grading_policy
(
course
.
grading_policy
)
enrolled_students
=
User
.
objects
.
filter
(
pocmembership__poc
=
poc
,
pocmembership__active
=
1
...
...
@@ -343,8 +363,11 @@ def poc_grades_csv(request, course):
poc
=
get_poc_for_coach
(
course
,
request
.
user
)
with
poc_context
(
poc
):
course
.
_field_data_cache
=
{}
course
.
set_grading_policy
(
course
.
grading_policy
)
# this is so awful
# The grading policy for the MOOC is probably already cached. We need
# to make sure we have the POC grading policy loaded.
course
.
_field_data_cache
=
{}
# pylint: disable=protected-access
course
.
set_grading_policy
(
course
.
grading_policy
)
enrolled_students
=
User
.
objects
.
filter
(
pocmembership__poc
=
poc
,
pocmembership__active
=
1
...
...
@@ -353,7 +376,7 @@ def poc_grades_csv(request, course):
header
=
None
rows
=
[]
for
student
,
gradeset
,
err_msg
in
grades
:
for
student
,
gradeset
,
__
in
grades
:
if
gradeset
:
# We were able to successfully grade this student for this
# course.
...
...
@@ -374,9 +397,9 @@ def poc_grades_csv(request, course):
rows
.
append
([
student
.
id
,
student
.
email
,
student
.
username
,
gradeset
[
'percent'
]]
+
row_percents
)
buf
fer
=
StringIO
()
writer
=
csv
.
writer
(
buf
fer
)
buf
=
StringIO
()
writer
=
csv
.
writer
(
buf
)
for
row
in
rows
:
writer
.
writerow
(
row
)
return
HttpResponse
(
buf
fer
.
getvalue
(),
content_type
=
'text/plain'
)
return
HttpResponse
(
buf
.
getvalue
(),
content_type
=
'text/plain'
)
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