Commit 9818cc7c by David Adams

Fixes some stuff in metrics tab

  Fixes some 500s after opaque-keys
  Adds a test which would have caught the 500s
  Fixes Transifex problem on the string % of students
parent b56e12ff
......@@ -558,7 +558,7 @@ def post_metrics_data_csv(request):
header = [_("Section").encode('utf-8'), _("Subsection").encode('utf-8'), _("Opened by this number of students").encode('utf-8')]
filename = sanitize_filename(_('subsections') + '_' + course_id)
elif data_type == 'problem':
header = [_("Section").encode('utf-8'), _("Problem").encode('utf-8'), _("Name").encode('utf-8'), _("Count of Students").encode('utf-8'), _("% of Students").encode('utf-8'), _("Score").encode('utf-8')]
header = [_("Section").encode('utf-8'), _("Problem").encode('utf-8'), _("Name").encode('utf-8'), _("Count of Students").encode('utf-8'), _("Percent of Students").encode('utf-8'), _("Score").encode('utf-8')]
filename = sanitize_filename(_('problems') + '_' + course_id)
for index, section in enumerate(sections):
......
......@@ -2,15 +2,21 @@
Tests for class dashboard (Metrics tab in instructor dashboard)
"""
from mock import patch
from django.test.utils import override_settings
from django.test import TestCase
from django.test.client import RequestFactory
from xmodule.modulestore.tests.factories import CourseFactory
from student.tests.factories import AdminFactory
from django.utils import simplejson
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from class_dashboard import views
class TestViews(TestCase):
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class TestViews(ModuleStoreTestCase):
"""
Tests related to class_dashboard/views.py
"""
......@@ -81,3 +87,18 @@ class TestViews(TestCase):
response = views.section_problem_grade_distrib(self.request, 'test/test/test', '1')
self.assertEqual("{\"error\": \"Access Denied: User does not have access to this course\'s data\"}", response.content)
def test_sending_deprecated_id(self):
course = CourseFactory.create()
instructor = AdminFactory.create()
self.request.user = instructor
response = views.all_sequential_open_distrib(self.request, course.id.to_deprecated_string())
self.assertEqual('[]', response.content)
response = views.all_problem_grade_distribution(self.request, course.id.to_deprecated_string())
self.assertEqual('[]', response.content)
response = views.section_problem_grade_distrib(self.request, course.id.to_deprecated_string(), 'no section')
self.assertEqual('{"error": "error"}', response.content)
......@@ -10,6 +10,7 @@ from django.http import HttpResponse
from courseware.courses import get_course_with_access
from courseware.access import has_access
from class_dashboard import dashboard_data
from xmodule.modulestore.locations import SlashSeparatedCourseKey
log = logging.getLogger(__name__)
......@@ -37,9 +38,10 @@ def all_sequential_open_distrib(request, course_id):
json = {}
# Only instructor for this particular course can request this information
if has_instructor_access_for_class(request.user, course_id):
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_id)
json = 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"}
......@@ -62,9 +64,10 @@ def all_problem_grade_distribution(request, course_id):
json = {}
# Only instructor for this particular course can request this information
if has_instructor_access_for_class(request.user, course_id):
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_id)
json = 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"}
......@@ -92,9 +95,10 @@ def section_problem_grade_distrib(request, course_id, section):
json = {}
# Only instructor for this particular course can request this information
if has_instructor_access_for_class(request.user, course_id):
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_id, section)
json = 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"}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment