Commit d989621b by Piotr Mitros

Series remembers last spot

parent 29d23d15
...@@ -18,7 +18,7 @@ TODO: Shift everything from xml.dom.minidom to XPath (or XQuery) ...@@ -18,7 +18,7 @@ TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
def fasthash(string): def fasthash(string):
m = hashlib.new("md4") m = hashlib.new("md4")
m.update(string) m.update(string)
return m.hexdigest() return "id"+m.hexdigest()
def xpath(xml, query_string, **args): def xpath(xml, query_string, **args):
''' Safe xpath query into an xml tree: ''' Safe xpath query into an xml tree:
......
...@@ -52,11 +52,12 @@ def make_track_function(request): ...@@ -52,11 +52,12 @@ def make_track_function(request):
def modx_dispatch(request, module=None, dispatch=None, id=None): def modx_dispatch(request, module=None, dispatch=None, id=None):
''' Generic view for extensions. ''' ''' Generic view for extensions. '''
# Grab the student information for the module from the database # Grab the student information for the module from the database
print module, request.user, id
s = StudentModule.objects.filter(module_type=module, s = StudentModule.objects.filter(module_type=module,
student=request.user, student=request.user,
module_id=id) module_id=id)
if len(s) == 0: if len(s) == 0:
print "ls404" print "ls404", module, request.user, id
raise Http404 raise Http404
s=s[0] s=s[0]
...@@ -75,11 +76,14 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -75,11 +76,14 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
s.module_id, s.module_id,
ajax_url=ajax_url, ajax_url=ajax_url,
state=s.state, state=s.state,
track_function = make_track_function(request)) track_function = make_track_function(request),
render_function = render_module,
meta = request)
# Let the module handle the AJAX # Let the module handle the AJAX
ajax_return=instance.handle_ajax(dispatch, request.POST) ajax_return=instance.handle_ajax(dispatch, request.POST)
# Save the state back to the database # Save the state back to the database
s.state=instance.get_state() s.state=instance.get_state()
if instance.get_score() != None:
s.grade=instance.get_score()['score'] s.grade=instance.get_score()['score']
s.save() s.save()
# Return whatever the module wanted to return to the client/caller # Return whatever the module wanted to return to the client/caller
......
from x_module import XModule from x_module import XModule
from lxml import etree from lxml import etree
from django.http import Http404
import json import json
...@@ -13,7 +14,7 @@ class SequentialModule(XModule): ...@@ -13,7 +14,7 @@ class SequentialModule(XModule):
id_attribute = 'id' id_attribute = 'id'
def get_state(self): def get_state(self):
return json.dumps({ }) return json.dumps({ 'position':self.position })
def get_xml_tags(): def get_xml_tags():
return ["sequential", 'tab'] return ["sequential", 'tab']
...@@ -27,10 +28,24 @@ class SequentialModule(XModule): ...@@ -27,10 +28,24 @@ class SequentialModule(XModule):
def get_destroy_js(self): def get_destroy_js(self):
return self.destroy_js return self.destroy_js
def handle_ajax(self, dispatch, get):
print "GET", get
print "DISPATCH", dispatch
if dispatch=='goto_position':
self.position = int(get['position'])
return json.dumps({'success':True})
raise Http404()
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)
xmltree=etree.fromstring(xml) xmltree=etree.fromstring(xml)
self.position = 1
if state!=None:
state = json.loads(state)
if 'position' in state: self.position = int(state['position'])
def j(m): def j(m):
''' jsonify contents so it can be embedded in a js array ''' jsonify contents so it can be embedded in a js array
We also need to split </script> tags so they don't break We also need to split </script> tags so they don't break
...@@ -51,7 +66,8 @@ class SequentialModule(XModule): ...@@ -51,7 +66,8 @@ class SequentialModule(XModule):
js="" js=""
params={'items':contents, params={'items':contents,
'id':"seq"} 'id':item_id,
'position': self.position}
# TODO/BUG: Destroy JavaScript should only be called for the active view # TODO/BUG: Destroy JavaScript should only be called for the active view
# This calls it for all the views # This calls it for all the views
......
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