Replaced simplejson with json
simplejson has been removed from future versions of Django (which we will eventually use).
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
"""
|
||||
Tests for class dashboard (Metrics tab in instructor dashboard)
|
||||
"""
|
||||
from django.test.utils import override_settings
|
||||
from django.test.client import RequestFactory
|
||||
from django.utils import simplejson
|
||||
from mock import patch
|
||||
import json
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import TEST_DATA_MOCK_MODULESTORE
|
||||
from student.tests.factories import AdminFactory
|
||||
from django.test.client import RequestFactory
|
||||
from mock import patch
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
|
||||
from class_dashboard import views
|
||||
from student.tests.factories import AdminFactory
|
||||
|
||||
|
||||
class TestViews(ModuleStoreTestCase):
|
||||
@@ -35,7 +33,7 @@ class TestViews(ModuleStoreTestCase):
|
||||
has_access.return_value = True
|
||||
response = views.all_problem_grade_distribution(self.request, 'test/test/test')
|
||||
|
||||
self.assertEqual(simplejson.dumps(self.simple_data), response.content)
|
||||
self.assertEqual(json.dumps(self.simple_data), response.content)
|
||||
|
||||
@patch('class_dashboard.views.has_instructor_access_for_class')
|
||||
def test_all_problem_grade_distribution_no_access(self, has_access):
|
||||
@@ -55,7 +53,7 @@ class TestViews(ModuleStoreTestCase):
|
||||
has_access.return_value = True
|
||||
response = views.all_sequential_open_distrib(self.request, 'test/test/test')
|
||||
|
||||
self.assertEqual(simplejson.dumps(self.simple_data), response.content)
|
||||
self.assertEqual(json.dumps(self.simple_data), response.content)
|
||||
|
||||
@patch('class_dashboard.views.has_instructor_access_for_class')
|
||||
def test_all_sequential_open_distribution_no_access(self, has_access):
|
||||
@@ -75,7 +73,7 @@ class TestViews(ModuleStoreTestCase):
|
||||
has_access.return_value = True
|
||||
response = views.section_problem_grade_distrib(self.request, 'test/test/test', '1')
|
||||
|
||||
self.assertEqual(simplejson.dumps(self.simple_data), response.content)
|
||||
self.assertEqual(json.dumps(self.simple_data), response.content)
|
||||
|
||||
@patch('class_dashboard.views.has_instructor_access_for_class')
|
||||
def test_section_problem_grade_distribution_no_access(self, has_access):
|
||||
|
||||
@@ -3,14 +3,15 @@ Handles requests for data, returning a json
|
||||
"""
|
||||
|
||||
import logging
|
||||
import json
|
||||
|
||||
from django.utils import simplejson
|
||||
from django.http import HttpResponse
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
|
||||
from courseware.courses import get_course_with_access
|
||||
from courseware.access import has_access
|
||||
from class_dashboard import dashboard_data
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -35,20 +36,20 @@ def all_sequential_open_distrib(request, course_id):
|
||||
Returns the format in dashboard_data.get_d3_sequential_open_distrib
|
||||
"""
|
||||
|
||||
json = {}
|
||||
data = {}
|
||||
|
||||
# Only instructor for this particular course can request this information
|
||||
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
|
||||
if has_instructor_access_for_class(request.user, course_key):
|
||||
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
|
||||
log.error('Generating metrics failed with exception: %s', ex)
|
||||
json = {'error': "error"}
|
||||
data = {'error': "error"}
|
||||
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):
|
||||
@@ -61,20 +62,20 @@ def all_problem_grade_distribution(request, course_id):
|
||||
|
||||
Returns the format in dashboard_data.get_d3_problem_grade_distrib
|
||||
"""
|
||||
json = {}
|
||||
data = {}
|
||||
|
||||
# Only instructor for this particular course can request this information
|
||||
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
|
||||
if has_instructor_access_for_class(request.user, course_key):
|
||||
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
|
||||
log.error('Generating metrics failed with exception: %s', ex)
|
||||
json = {'error': "error"}
|
||||
data = {'error': "error"}
|
||||
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):
|
||||
@@ -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
|
||||
and pick out the sections of interest.
|
||||
"""
|
||||
json = {}
|
||||
data = {}
|
||||
|
||||
# Only instructor for this particular course can request this information
|
||||
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
|
||||
if has_instructor_access_for_class(request.user, course_key):
|
||||
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
|
||||
log.error('Generating metrics failed with exception: %s', ex)
|
||||
json = {'error': "error"}
|
||||
data = {'error': "error"}
|
||||
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")
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
import json
|
||||
import pytz
|
||||
from collections import defaultdict
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
|
||||
import pytz
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import connection
|
||||
from django.http import HttpResponse
|
||||
from django.utils import simplejson
|
||||
from django.utils.timezone import UTC
|
||||
|
||||
from django_comment_common.models import Role, FORUM_ROLE_STUDENT
|
||||
from django_comment_client.permissions import check_permissions_by_view, cached_has_permission
|
||||
|
||||
from edxmako import lookup_template
|
||||
import pystache_custom as pystache
|
||||
|
||||
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.models import CourseUserGroup
|
||||
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_client.permissions import check_permissions_by_view, cached_has_permission
|
||||
from edxmako import lookup_template
|
||||
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.models import CourseUserGroup
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -245,9 +244,7 @@ class JsonError(HttpResponse):
|
||||
def __init__(self, error_messages=[], status=400):
|
||||
if isinstance(error_messages, basestring):
|
||||
error_messages = [error_messages]
|
||||
content = simplejson.dumps({'errors': error_messages},
|
||||
indent=2,
|
||||
ensure_ascii=False)
|
||||
content = json.dumps({'errors': error_messages}, indent=2, ensure_ascii=False)
|
||||
super(JsonError, self).__init__(content,
|
||||
mimetype='application/json; charset=utf-8', status=status)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user