From c06c6104cada968d33fd48069589da5588a899df Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Tue, 10 Apr 2012 08:03:26 -0400 Subject: [PATCH] Grading histogram --- djangoapps/courseware/module_render.py | 15 ++++++++++++++- templates/staff_problem_info.html | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 0f96b8802f..e685361e8f 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -87,6 +87,18 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): # Return whatever the module wanted to return to the client/caller return HttpResponse(ajax_return) +def grade_histogram(module_id): + print module_id + from django.db import connection, transaction + cursor = connection.cursor() + + cursor.execute("select courseware_studentmodule.grade,COUNT(courseware_studentmodule.student_id) from courseware_studentmodule where courseware_studentmodule.module_id=%s group by courseware_studentmodule.grade", [module_id]) + + grades = list(cursor.fetchall()) + print grades + grades.sort(key=lambda x:x[0]) # Probably not necessary + return grades + def render_x_module(user, request, xml_module, module_object_preload): ''' Generic module for extensions. This renders to HTML. ''' # Check if problem has an instance in DB @@ -125,7 +137,8 @@ def render_x_module(user, request, xml_module, module_object_preload): # Grab content content = instance.get_html() if user.is_staff: - content=content+render_to_string("staff_problem_info.html", {'xml':etree.tostring(xml_module)}) + content=content+render_to_string("staff_problem_info.html", {'xml':etree.tostring(xml_module), + 'histogram':grade_histogram(module_id)}) content = {'content':content, "destroy_js":instance.get_destroy_js(), 'init_js':instance.get_init_js(), diff --git a/templates/staff_problem_info.html b/templates/staff_problem_info.html index e617584a17..560713eaa6 100644 --- a/templates/staff_problem_info.html +++ b/templates/staff_problem_info.html @@ -1,3 +1,6 @@
${xml | h}
+
+${ str(histogram) } +