diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 38f9e0211b..2924aec9df 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -103,8 +103,9 @@ def grade_histogram(module_id): 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 + if (len(grades) == 1 and grades[0][0] == None): + return [] return grades def render_x_module(user, request, xml_module, module_object_preload): @@ -144,12 +145,21 @@ def render_x_module(user, request, xml_module, module_object_preload): module_object_preload.append(smod) # Grab content content = instance.get_html() + init_js = instance.get_init_js() + destory_js = instance.get_destroy_js() if user.is_staff: + histogram = grade_histogram(module_id) + render_histogram = len(histogram) > 0 content=content+render_to_string("staff_problem_info.html", {'xml':etree.tostring(xml_module), - 'histogram':grade_histogram(module_id)}) + 'module_id' : module_id, + 'render_histogram' : render_histogram}) + if render_histogram: + init_js = init_js+render_to_string("staff_problem_histogram.js", {'histogram' : histogram, + 'module_id' : module_id}) + content = {'content':content, - "destroy_js":instance.get_destroy_js(), - 'init_js':instance.get_init_js(), + "destroy_js":destory_js, + 'init_js':init_js, 'type':module_type} return content diff --git a/templates/courseware.html b/templates/courseware.html index f64060b0f6..2b5b14ed0d 100644 --- a/templates/courseware.html +++ b/templates/courseware.html @@ -2,7 +2,12 @@ <%block name="bodyclass">courseware <%block name="title">Courseware – MITx 6.002x +<%block name="headextra"> + + + <%block name="js_extra"> +##Is there a reason this isn't in header_extra? Is it important that the javascript is at the bottom of the generated document?