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