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
6a54b1d6
Commit
6a54b1d6
authored
Feb 26, 2015
by
Clinton Blackburn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7126 from edx/django-upgrade/simplejson-to-json
Replaced simplejson with json
parents
3538074c
2fca3f03
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
39 deletions
+35
-39
lms/djangoapps/class_dashboard/tests/test_views.py
+6
-8
lms/djangoapps/class_dashboard/views.py
+18
-17
lms/djangoapps/django_comment_client/utils.py
+11
-14
No files found.
lms/djangoapps/class_dashboard/tests/test_views.py
View file @
6a54b1d6
"""
"""
Tests for class dashboard (Metrics tab in instructor dashboard)
Tests for class dashboard (Metrics tab in instructor dashboard)
"""
"""
from
django.test.utils
import
override_settings
import
json
from
django.test.client
import
RequestFactory
from
django.test.client
import
RequestFactory
from
django.utils
import
simplejson
from
mock
import
patch
from
mock
import
patch
from
xmodule.modulestore.tests.django_utils
import
TEST_DATA_MOCK_MODULESTORE
from
student.tests.factories
import
AdminFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
class_dashboard
import
views
from
class_dashboard
import
views
from
student.tests.factories
import
AdminFactory
class
TestViews
(
ModuleStoreTestCase
):
class
TestViews
(
ModuleStoreTestCase
):
...
@@ -35,7 +33,7 @@ class TestViews(ModuleStoreTestCase):
...
@@ -35,7 +33,7 @@ class TestViews(ModuleStoreTestCase):
has_access
.
return_value
=
True
has_access
.
return_value
=
True
response
=
views
.
all_problem_grade_distribution
(
self
.
request
,
'test/test/test'
)
response
=
views
.
all_problem_grade_distribution
(
self
.
request
,
'test/test/test'
)
self
.
assertEqual
(
simple
json
.
dumps
(
self
.
simple_data
),
response
.
content
)
self
.
assertEqual
(
json
.
dumps
(
self
.
simple_data
),
response
.
content
)
@patch
(
'class_dashboard.views.has_instructor_access_for_class'
)
@patch
(
'class_dashboard.views.has_instructor_access_for_class'
)
def
test_all_problem_grade_distribution_no_access
(
self
,
has_access
):
def
test_all_problem_grade_distribution_no_access
(
self
,
has_access
):
...
@@ -55,7 +53,7 @@ class TestViews(ModuleStoreTestCase):
...
@@ -55,7 +53,7 @@ class TestViews(ModuleStoreTestCase):
has_access
.
return_value
=
True
has_access
.
return_value
=
True
response
=
views
.
all_sequential_open_distrib
(
self
.
request
,
'test/test/test'
)
response
=
views
.
all_sequential_open_distrib
(
self
.
request
,
'test/test/test'
)
self
.
assertEqual
(
simple
json
.
dumps
(
self
.
simple_data
),
response
.
content
)
self
.
assertEqual
(
json
.
dumps
(
self
.
simple_data
),
response
.
content
)
@patch
(
'class_dashboard.views.has_instructor_access_for_class'
)
@patch
(
'class_dashboard.views.has_instructor_access_for_class'
)
def
test_all_sequential_open_distribution_no_access
(
self
,
has_access
):
def
test_all_sequential_open_distribution_no_access
(
self
,
has_access
):
...
@@ -75,7 +73,7 @@ class TestViews(ModuleStoreTestCase):
...
@@ -75,7 +73,7 @@ class TestViews(ModuleStoreTestCase):
has_access
.
return_value
=
True
has_access
.
return_value
=
True
response
=
views
.
section_problem_grade_distrib
(
self
.
request
,
'test/test/test'
,
'1'
)
response
=
views
.
section_problem_grade_distrib
(
self
.
request
,
'test/test/test'
,
'1'
)
self
.
assertEqual
(
simple
json
.
dumps
(
self
.
simple_data
),
response
.
content
)
self
.
assertEqual
(
json
.
dumps
(
self
.
simple_data
),
response
.
content
)
@patch
(
'class_dashboard.views.has_instructor_access_for_class'
)
@patch
(
'class_dashboard.views.has_instructor_access_for_class'
)
def
test_section_problem_grade_distribution_no_access
(
self
,
has_access
):
def
test_section_problem_grade_distribution_no_access
(
self
,
has_access
):
...
...
lms/djangoapps/class_dashboard/views.py
View file @
6a54b1d6
...
@@ -3,14 +3,15 @@ Handles requests for data, returning a json
...
@@ -3,14 +3,15 @@ Handles requests for data, returning a json
"""
"""
import
logging
import
logging
import
json
from
django.utils
import
simplejson
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
courseware.courses
import
get_course_with_access
from
courseware.courses
import
get_course_with_access
from
courseware.access
import
has_access
from
courseware.access
import
has_access
from
class_dashboard
import
dashboard_data
from
class_dashboard
import
dashboard_data
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -35,20 +36,20 @@ def all_sequential_open_distrib(request, course_id):
...
@@ -35,20 +36,20 @@ def all_sequential_open_distrib(request, course_id):
Returns the format in dashboard_data.get_d3_sequential_open_distrib
Returns the format in dashboard_data.get_d3_sequential_open_distrib
"""
"""
json
=
{}
data
=
{}
# Only instructor for this particular course can request this information
# Only instructor for this particular course can request this information
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
if
has_instructor_access_for_class
(
request
.
user
,
course_key
):
if
has_instructor_access_for_class
(
request
.
user
,
course_key
):
try
:
try
:
json
=
dashboard_data
.
get_d3_sequential_open_distrib
(
course_key
)
data
=
dashboard_data
.
get_d3_sequential_open_distrib
(
course_key
)
except
Exception
as
ex
:
# pylint: disable=broad-except
except
Exception
as
ex
:
# pylint: disable=broad-except
log
.
error
(
'Generating metrics failed with exception:
%
s'
,
ex
)
log
.
error
(
'Generating metrics failed with exception:
%
s'
,
ex
)
json
=
{
'error'
:
"error"
}
data
=
{
'error'
:
"error"
}
else
:
else
:
json
=
{
'error'
:
"Access Denied: User does not have access to this course's data"
}
data
=
{
'error'
:
"Access Denied: User does not have access to this course's data"
}
return
HttpResponse
(
simplejson
.
dumps
(
json
),
mimetype
=
"application/json"
)
return
HttpResponse
(
json
.
dumps
(
data
),
mimetype
=
"application/json"
)
def
all_problem_grade_distribution
(
request
,
course_id
):
def
all_problem_grade_distribution
(
request
,
course_id
):
...
@@ -61,20 +62,20 @@ def all_problem_grade_distribution(request, course_id):
...
@@ -61,20 +62,20 @@ def all_problem_grade_distribution(request, course_id):
Returns the format in dashboard_data.get_d3_problem_grade_distrib
Returns the format in dashboard_data.get_d3_problem_grade_distrib
"""
"""
json
=
{}
data
=
{}
# Only instructor for this particular course can request this information
# Only instructor for this particular course can request this information
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
if
has_instructor_access_for_class
(
request
.
user
,
course_key
):
if
has_instructor_access_for_class
(
request
.
user
,
course_key
):
try
:
try
:
json
=
dashboard_data
.
get_d3_problem_grade_distrib
(
course_key
)
data
=
dashboard_data
.
get_d3_problem_grade_distrib
(
course_key
)
except
Exception
as
ex
:
# pylint: disable=broad-except
except
Exception
as
ex
:
# pylint: disable=broad-except
log
.
error
(
'Generating metrics failed with exception:
%
s'
,
ex
)
log
.
error
(
'Generating metrics failed with exception:
%
s'
,
ex
)
json
=
{
'error'
:
"error"
}
data
=
{
'error'
:
"error"
}
else
:
else
:
json
=
{
'error'
:
"Access Denied: User does not have access to this course's data"
}
data
=
{
'error'
:
"Access Denied: User does not have access to this course's data"
}
return
HttpResponse
(
simplejson
.
dumps
(
json
),
mimetype
=
"application/json"
)
return
HttpResponse
(
json
.
dumps
(
data
),
mimetype
=
"application/json"
)
def
section_problem_grade_distrib
(
request
,
course_id
,
section
):
def
section_problem_grade_distrib
(
request
,
course_id
,
section
):
...
@@ -92,17 +93,17 @@ def section_problem_grade_distrib(request, course_id, section):
...
@@ -92,17 +93,17 @@ def section_problem_grade_distrib(request, course_id, section):
If this is requested multiple times quickly for the same course, it is better to call all_problem_grade_distribution
If this is requested multiple times quickly for the same course, it is better to call all_problem_grade_distribution
and pick out the sections of interest.
and pick out the sections of interest.
"""
"""
json
=
{}
data
=
{}
# Only instructor for this particular course can request this information
# Only instructor for this particular course can request this information
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
course_id
)
if
has_instructor_access_for_class
(
request
.
user
,
course_key
):
if
has_instructor_access_for_class
(
request
.
user
,
course_key
):
try
:
try
:
json
=
dashboard_data
.
get_d3_section_grade_distrib
(
course_key
,
section
)
data
=
dashboard_data
.
get_d3_section_grade_distrib
(
course_key
,
section
)
except
Exception
as
ex
:
# pylint: disable=broad-except
except
Exception
as
ex
:
# pylint: disable=broad-except
log
.
error
(
'Generating metrics failed with exception:
%
s'
,
ex
)
log
.
error
(
'Generating metrics failed with exception:
%
s'
,
ex
)
json
=
{
'error'
:
"error"
}
data
=
{
'error'
:
"error"
}
else
:
else
:
json
=
{
'error'
:
"Access Denied: User does not have access to this course's data"
}
data
=
{
'error'
:
"Access Denied: User does not have access to this course's data"
}
return
HttpResponse
(
simplejson
.
dumps
(
json
),
mimetype
=
"application/json"
)
return
HttpResponse
(
json
.
dumps
(
data
),
mimetype
=
"application/json"
)
lms/djangoapps/django_comment_client/utils.py
View file @
6a54b1d6
import
json
import
pytz
from
collections
import
defaultdict
from
collections
import
defaultdict
import
logging
from
datetime
import
datetime
from
datetime
import
datetime
import
json
import
logging
import
pytz
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.db
import
connection
from
django.db
import
connection
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.utils
import
simplejson
from
django.utils.timezone
import
UTC
from
django.utils.timezone
import
UTC
import
pystache_custom
as
pystache
from
opaque_keys.edx.locations
import
i4xEncoder
from
opaque_keys.edx.keys
import
CourseKey
from
xmodule.modulestore.django
import
modulestore
from
django_comment_common.models
import
Role
,
FORUM_ROLE_STUDENT
from
django_comment_common.models
import
Role
,
FORUM_ROLE_STUDENT
from
django_comment_client.permissions
import
check_permissions_by_view
,
cached_has_permission
from
django_comment_client.permissions
import
check_permissions_by_view
,
cached_has_permission
from
edxmako
import
lookup_template
from
edxmako
import
lookup_template
import
pystache_custom
as
pystache
from
courseware.access
import
has_access
from
courseware.access
import
has_access
from
openedx.core.djangoapps.course_groups.cohorts
import
get_cohort_by_id
,
get_cohort_id
,
is_commentable_cohorted
,
is_course_cohorted
from
openedx.core.djangoapps.course_groups.cohorts
import
get_cohort_by_id
,
get_cohort_id
,
is_commentable_cohorted
,
\
is_course_cohorted
from
openedx.core.djangoapps.course_groups.models
import
CourseUserGroup
from
openedx.core.djangoapps.course_groups.models
import
CourseUserGroup
from
opaque_keys.edx.locations
import
i4xEncoder
from
opaque_keys.edx.keys
import
CourseKey
from
xmodule.modulestore.django
import
modulestore
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -245,9 +244,7 @@ class JsonError(HttpResponse):
...
@@ -245,9 +244,7 @@ class JsonError(HttpResponse):
def
__init__
(
self
,
error_messages
=
[],
status
=
400
):
def
__init__
(
self
,
error_messages
=
[],
status
=
400
):
if
isinstance
(
error_messages
,
basestring
):
if
isinstance
(
error_messages
,
basestring
):
error_messages
=
[
error_messages
]
error_messages
=
[
error_messages
]
content
=
simplejson
.
dumps
({
'errors'
:
error_messages
},
content
=
json
.
dumps
({
'errors'
:
error_messages
},
indent
=
2
,
ensure_ascii
=
False
)
indent
=
2
,
ensure_ascii
=
False
)
super
(
JsonError
,
self
)
.
__init__
(
content
,
super
(
JsonError
,
self
)
.
__init__
(
content
,
mimetype
=
'application/json; charset=utf-8'
,
status
=
status
)
mimetype
=
'application/json; charset=utf-8'
,
status
=
status
)
...
...
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