From b09ab3a702013f010cd44f8f742b4592683b6eea Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Thu, 15 Dec 2011 07:51:44 -0500 Subject: [PATCH] Missed a file --- courseware/video_module.py | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 courseware/video_module.py diff --git a/courseware/video_module.py b/courseware/video_module.py new file mode 100644 index 0000000000..d8a19be474 --- /dev/null +++ b/courseware/video_module.py @@ -0,0 +1,59 @@ +# For calculator: +# http://pyparsing.wikispaces.com/file/view/fourFn.py + +from x_module import XModule + +from xml.dom.minidom import parse, parseString + +import json + +## TODO: Abstract out from Django +from django.conf import settings +from djangomako.shortcuts import render_to_response, render_to_string + +class VideoModule(XModule): + ''' Implements a generic learning module. + Initialized on access with __init__, first time with state=None, and + then with state + ''' + id_attribute = 'youtube' + video_time = 0 + + def handle_ajax(self, dispatch, get): + if dispatch == 'time': + self.video_time = int(get['time']) + print self.video_time + + return json.dumps("True") + + def get_state(self): + return json.dumps({ 'time':self.video_time }) + + def get_xml_tags(): + ''' Tags in the courseware file guaranteed to correspond to the module ''' + return "video1" + + def get_id_attribute(): + ''' An attribute in the XML scheme that is guaranteed unique. ''' + return "youtube" + + def get_html(self): + return render_to_string('video.html',{'id':self.item_id, + 'time':self.video_time}) + + def get_init_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 render_to_string('video_init.js',{'id':self.item_id, + 'video_time':self.video_time}) + + def get_destroy_js(self): + return "videoDestroy();" + + 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) + print state + if state!=None and "time" not in json.loads(state): + self.video_time = 0