Commit ef1c465d by Piotr Mitros

Video module set up to store last location. Several bug fixes too.

parent d989621b
...@@ -79,7 +79,9 @@ def id_tag(course): ...@@ -79,7 +79,9 @@ def id_tag(course):
if elem.get('id'): if elem.get('id'):
pass pass
elif elem.get(default_ids[elem.tag]): elif elem.get(default_ids[elem.tag]):
elem.set('id', elem.get(default_ids[elem.tag])) new_id = elem.get(default_ids[elem.tag]) # Convert to alphanumeric
new_id = "".join([a for a in new_id if a.isalnum()])
elem.set('id', new_id)
else: else:
elem.set('id', fasthash(etree.tostring(elem))) elem.set('id', fasthash(etree.tostring(elem)))
......
...@@ -94,7 +94,7 @@ def render_x_module(request, xml_module): ...@@ -94,7 +94,7 @@ def render_x_module(request, xml_module):
# Check if problem has an instance in DB # Check if problem has an instance in DB
module_type=xml_module.tag module_type=xml_module.tag
module_class=modx_modules[module_type] module_class=modx_modules[module_type]
module_id=xml_module.get(module_class.id_attribute) or "" # TODO: remove or "" module_id=xml_module.get('id') #module_class.id_attribute) or ""
# Grab state from database # Grab state from database
s = StudentModule.objects.filter(student=request.user, s = StudentModule.objects.filter(student=request.user,
......
from x_module import XModule from x_module import XModule
from lxml import etree
import json import json
...@@ -7,47 +8,55 @@ from django.conf import settings ...@@ -7,47 +8,55 @@ from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string from djangomako.shortcuts import render_to_response, render_to_string
class VideoModule(XModule): class VideoModule(XModule):
id_attribute = 'youtube' #id_attribute = 'youtube'
video_time = 0 video_time = 0
def handle_ajax(self, dispatch, get): def handle_ajax(self, dispatch, get):
if dispatch == 'time': print "GET", get
self.video_time = int(get['time']) print "DISPATCH", dispatch
print self.video_time if dispatch=='goto_position':
self.position = int(float(get['position']))
return json.dumps("True") print "NEW POSITION", self.position
return json.dumps({'success':True})
raise Http404()
def get_state(self): def get_state(self):
return json.dumps({ 'time':self.video_time }) print "STATE POSITION", self.position
return json.dumps({ 'position':self.position })
def get_xml_tags(): def get_xml_tags():
''' Tags in the courseware file guaranteed to correspond to the module ''' ''' Tags in the courseware file guaranteed to correspond to the module '''
return "video" return "video"
def video_list(self): def video_list(self):
l=self.item_id.split(',') l=self.youtube.split(',')
l=[i.split(":") for i in l] l=[i.split(":") for i in l]
return json.dumps(dict(l)) return json.dumps(dict(l))
def get_html(self): def get_html(self):
return render_to_string('video.html',{'streams':self.video_list(), return render_to_string('video.html',{'streams':self.video_list(),
'id':self.item_id, 'id':self.item_id,
'video_time':self.video_time}) 'position':self.position})
def get_init_js(self): def get_init_js(self):
''' JavaScript code to be run when problem is shown. Be aware ''' JavaScript code to be run when problem is shown. Be aware
that this may happen several times on the same page that this may happen several times on the same page
(e.g. student switching tabs). Common functions should be put (e.g. student switching tabs). Common functions should be put
in the main course .js files for now. ''' in the main course .js files for now. '''
print "INIT POSITION", self.position
return render_to_string('video_init.js',{'streams':self.video_list(), return render_to_string('video_init.js',{'streams':self.video_list(),
'id':self.item_id, 'id':self.item_id,
'video_time':self.video_time}) 'position':self.position})
def get_destroy_js(self): def get_destroy_js(self):
return "videoDestroy();" return "videoDestroy(\""+self.item_id+"\");"
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None, render_function = None, meta = None): def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None, render_function = None, meta = None):
XModule.__init__(self, xml, item_id, ajax_url, track_url, state, track_function, render_function) XModule.__init__(self, xml, item_id, ajax_url, track_url, state, track_function, render_function)
print state self.youtube = etree.XML(xml).get('youtube')
if state!=None and "time" not in json.loads(state): self.position = 0
self.video_time = 0 if state!=None:
state = json.loads(state)
if 'position' in state: self.position = int(float(state['position']))
print "POOSITION IN STATE"
print "LOAD POSITION", self.position
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment