This commit is contained in:
Victor Shnayder
2013-02-14 12:49:14 -05:00
422 changed files with 39228 additions and 5204 deletions

View File

@@ -2,6 +2,9 @@ import json
import logging
import pyparsing
import sys
import static_replace
from functools import partial
from django.conf import settings
from django.contrib.auth.models import User
@@ -18,7 +21,6 @@ from courseware.access import has_access
from mitxmako.shortcuts import render_to_string
from models import StudentModule, StudentModuleCache
from psychometrics.psychoanalyze import make_psychometrics_data_update_handler
from static_replace import replace_urls
from student.models import unique_id_for_user
from xmodule.errortracker import exc_info_to_str
from xmodule.exceptions import NotFoundError
@@ -89,7 +91,7 @@ def toc_for_course(user, request, course, active_chapter, active_section):
chapters = list()
for chapter in course_module.get_display_items():
hide_from_toc = chapter.metadata.get('hide_from_toc','false').lower() == 'true'
hide_from_toc = chapter.metadata.get('hide_from_toc', 'false').lower() == 'true'
if hide_from_toc:
continue
@@ -164,6 +166,7 @@ def get_module_for_descriptor(user, request, descriptor, student_module_cache, c
return _get_module(user, request, descriptor, student_module_cache, course_id,
position=position, wrap_xmodule_display=wrap_xmodule_display)
def _get_module(user, request, descriptor, student_module_cache, course_id,
position=None, wrap_xmodule_display=True):
"""
@@ -244,7 +247,11 @@ def _get_module(user, request, descriptor, student_module_cache, course_id,
# TODO (cpennington): This should be removed when all html from
# a module is coming through get_html and is therefore covered
# by the replace_static_urls code below
replace_urls=replace_urls,
replace_urls=partial(
static_replace.replace_static_urls,
data_directory=descriptor.metadata.get('data_dir', ''),
course_namespace=descriptor.location._replace(category=None, name=None),
),
node_path=settings.NODE_PATH,
anonymous_student_id=unique_id_for_user(user),
course_id=course_id,
@@ -280,8 +287,8 @@ def _get_module(user, request, descriptor, student_module_cache, course_id,
module.get_html = replace_static_urls(
_get_html,
module.metadata['data_dir'] if 'data_dir' in module.metadata else '',
course_namespace = module.location._replace(category=None, name=None))
module.metadata.get('data_dir', ''),
course_namespace=module.location._replace(category=None, name=None))
# Allow URLs of the form '/course/' refer to the root of multicourse directory
# hierarchy of this course
@@ -294,6 +301,8 @@ def _get_module(user, request, descriptor, student_module_cache, course_id,
return module
# TODO (vshnayder): Rename this? It's very confusing.
def get_instance_module(course_id, user, module, student_module_cache):
"""
Returns the StudentModule specific to this module for this student,
@@ -323,6 +332,7 @@ def get_instance_module(course_id, user, module, student_module_cache):
else:
return None
def get_shared_instance_module(course_id, user, module, student_module_cache):
"""
Return shared_module is a StudentModule specific to all modules with the same
@@ -353,6 +363,7 @@ def get_shared_instance_module(course_id, user, module, student_module_cache):
else:
return None
@csrf_exempt
def xqueue_callback(request, course_id, userid, id, dispatch):
'''
@@ -409,8 +420,8 @@ def xqueue_callback(request, course_id, userid, id, dispatch):
instance_module.save()
#Bin score into range and increment stats
score_bucket=get_score_bucket(instance_module.grade, instance_module.max_grade)
org, course_num, run=course_id.split("/")
score_bucket = get_score_bucket(instance_module.grade, instance_module.max_grade)
org, course_num, run = course_id.split("/")
statsd.increment("lms.courseware.question_answered",
tags=["org:{0}".format(org),
"course:{0}".format(course_num),
@@ -450,9 +461,9 @@ def modx_dispatch(request, dispatch, location, course_id):
return HttpResponse(json.dumps({'success': too_many_files_msg}))
for inputfile in inputfiles:
if inputfile.size > settings.STUDENT_FILEUPLOAD_MAX_SIZE: # Bytes
if inputfile.size > settings.STUDENT_FILEUPLOAD_MAX_SIZE: # Bytes
file_too_big_msg = 'Submission aborted! Your file "%s" is too large (max size: %d MB)' %\
(inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE/(1000**2))
(inputfile.name, settings.STUDENT_FILEUPLOAD_MAX_SIZE / (1000 ** 2))
return HttpResponse(json.dumps({'success': file_too_big_msg}))
p[fileinput_id] = inputfiles
@@ -493,7 +504,7 @@ def modx_dispatch(request, dispatch, location, course_id):
# Don't track state for anonymous users (who don't have student modules)
if instance_module is not None:
instance_module.state = instance.get_instance_state()
instance_module.max_grade=instance.max_score()
instance_module.max_grade = instance.max_score()
if instance.get_score():
instance_module.grade = instance.get_score()['score']
if (instance_module.grade != oldgrade or
@@ -502,8 +513,8 @@ def modx_dispatch(request, dispatch, location, course_id):
instance_module.save()
#Bin score into range and increment stats
score_bucket=get_score_bucket(instance_module.grade, instance_module.max_grade)
org, course_num, run=course_id.split("/")
score_bucket = get_score_bucket(instance_module.grade, instance_module.max_grade)
org, course_num, run = course_id.split("/")
statsd.increment("lms.courseware.question_answered",
tags=["org:{0}".format(org),
"course:{0}".format(course_num),
@@ -520,6 +531,7 @@ def modx_dispatch(request, dispatch, location, course_id):
# Return whatever the module wanted to return to the client/caller
return HttpResponse(ajax_return)
def preview_chemcalc(request):
"""
Render an html preview of a chemical formula or equation. The fact that
@@ -538,7 +550,7 @@ def preview_chemcalc(request):
raise Http404
result = {'preview': '',
'error': '' }
'error': ''}
formula = request.GET.get('formula')
if formula is None:
result['error'] = "No formula specified."
@@ -557,17 +569,15 @@ def preview_chemcalc(request):
return HttpResponse(json.dumps(result))
def get_score_bucket(grade,max_grade):
def get_score_bucket(grade, max_grade):
"""
Function to split arbitrary score ranges into 3 buckets.
Used with statsd tracking.
"""
score_bucket="incorrect"
if(grade>0 and grade<max_grade):
score_bucket="partial"
elif(grade==max_grade):
score_bucket="correct"
score_bucket = "incorrect"
if(grade > 0 and grade < max_grade):
score_bucket = "partial"
elif(grade == max_grade):
score_bucket = "correct"
return score_bucket