diff --git a/courseware/capa_module.py b/courseware/capa_module.py index 5b62b57faf..f841e764e4 100644 --- a/courseware/capa_module.py +++ b/courseware/capa_module.py @@ -28,7 +28,7 @@ class LoncapaModule(XModule): return self.lcp.get_score() def max_score(self): - return len(lcp.questions) + return len(self.lcp.questions) def get_html(self, encapsulate=True): html = self.lcp.get_html() @@ -40,6 +40,9 @@ class LoncapaModule(XModule): html = '
'.format(id=self.item_id)+html+"
" return html + def get_js(self): + return "" + def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None): XModule.__init__(self, xml, item_id, ajax_url, track_url, state) dom=parseString(xml) diff --git a/courseware/static/js/video_player.js b/courseware/static/js/video_player.js index 4e6a41ca0f..299b18ecd7 100644 --- a/courseware/static/js/video_player.js +++ b/courseware/static/js/video_player.js @@ -71,7 +71,7 @@ function updateHTML(elmId, value) { } function setytplayerState(newState) { - updateHTML("playerstate", newState); + // updateHTML("playerstate", newState); } function onYouTubePlayerReady(playerId) { @@ -143,10 +143,10 @@ function updateytplayerInfo() { update_captions(getCurrentTime()); } - updateHTML("videoduration", getDuration()); - updateHTML("videotime", getCurrentTime()); - updateHTML("startbytes", getStartBytes()); - updateHTML("volume", getVolume()); + // updateHTML("videoduration", getDuration()); + // updateHTML("videotime", getCurrentTime()); + // updateHTML("startbytes", getStartBytes()); + // updateHTML("volume", getVolume()); } // functions for the api calls diff --git a/courseware/views.py b/courseware/views.py index 3d788e89fb..7fbab1cedc 100644 --- a/courseware/views.py +++ b/courseware/views.py @@ -17,6 +17,7 @@ from django.http import Http404 import urllib import capa_module +import video_module from models import StudentModule @@ -55,7 +56,7 @@ def profile(request): correct=response.grade else: correct=0 - total=capa_module.LoncapaModule(p, id=id).max_score() + total=capa_module.LoncapaModule(p.toxml(), "id").max_score() # TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores? scores.append((int(correct),total)) score={'course':course.getAttribute('name'), 'section':s.getAttribute("name"), @@ -71,7 +72,8 @@ def profile(request): 'location':user_info.location, 'language':user_info.language, 'email':request.user.email, - 'homeworks':hw + 'homeworks':hw, + 'csrf':csrf(request)['csrf_token'] } return render_to_response('profile.html', context) @@ -94,12 +96,12 @@ def render_accordion(request,course,chapter,section): return {'js':render_to_string('accordion_init.js',context), 'content':render_to_string('accordion.html',context)} -def video_module(request, module): +def video_mod(request, module): ''' Shows a video, with subtitles. ''' id=module.getAttribute('youtube') return {'js':render_to_string('video_init.js',{'id':id}), - 'content':render_to_string('video.html',{})} + 'content':render_to_string('video.html',{'id':id})} def html_module(request, module): ''' Show basic text @@ -150,33 +152,36 @@ def seq_module(request, module): 'content':render_to_string('seq_module.html',{'items':contents})} -modx_modules={'problem':capa_module.LoncapaModule} +modx_modules={'problem':capa_module.LoncapaModule}#, 'video1':video_module.VideoModule} def render_x_module(request, xml_module): ''' Generic module for extensions. This renders to HTML. ''' # Check if problem has an instance in DB - module_id=xml_module.getAttribute(capa_module.LoncapaModule.id_attribute) + module_type=xml_module.nodeName + module_class=modx_modules[module_type] + module_id=xml_module.getAttribute(module_class.id_attribute) s = StudentModule.objects.filter(student=request.user, module_id=module_id) if len(s) == 0: # If not, create one, and save it - problem=capa_module.LoncapaModule(xml_module.toxml(), module_id) + instance=module_class(xml_module.toxml(), module_id) smod=StudentModule(student=request.user, module_id=module_id, - state=problem.get_state(), - xml=problem.xml) + state=instance.get_state(), + xml=instance.xml) smod.save() elif len(s) == 1: # If so, render it s=s[0] - problem=capa_module.LoncapaModule(xml_module.toxml(), - module_id, - state=s.state) - s.state=problem.get_state() + instance=module_class(xml_module.toxml(), + module_id, + state=s.state) + s.state=instance.get_state() s.save() else: raise Exception("Database is inconsistent (1).") - return {'content':problem.get_html()} + return {'content':instance.get_html(), + 'js':instance.get_js()} def modx_dispatch(request, module=None, dispatch=None, id=None): ''' Generic module for extensions. This handles AJAX. ''' @@ -187,14 +192,14 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): s=s[0] dispatch=dispatch.split('?')[0] - problem=modx_modules[module](s.xml, s.module_id, state=s.state) - html=problem.handle_ajax(dispatch, request.GET) - s.state=problem.get_state() - s.grade=problem.get_score()['score'] + instance=modx_modules[module](s.xml, s.module_id, state=s.state) + html=instance.handle_ajax(dispatch, request.GET) + s.state=instance.get_state() + s.grade=instance.get_score()['score'] s.save() return HttpResponse(html) -module_types={'video':video_module, +module_types={'video':video_mod, 'html':html_module, 'tab':tab_module, 'vertical':vertical_module, diff --git a/courseware/x_module.py b/courseware/x_module.py index c867128d1e..e881a3d8e3 100644 --- a/courseware/x_module.py +++ b/courseware/x_module.py @@ -23,6 +23,13 @@ class XModule: def get_html(self): return "Unimplemented" + def get_js(self): + ''' JavaScript code to be run when problem is shown. Be aware + that this may happen several times on the same page + (e.g. student switching tabs). Common functions should be put + in the main course .js files for now. ''' + return "" + def handle_ajax(self, dispatch, get): ''' dispatch is last part of the URL. get is a dictionary-like object '''