Commit 16ab1bb5 by Piotr Mitros

Vertical Module is now an x_module

parent 837e87e1
......@@ -18,6 +18,7 @@ import urllib
import courseware.modules.capa_module
import courseware.modules.video_module
import courseware.modules.vertical_module
import courseware.modules.html_module
import courseware.modules.schematic_module
......@@ -38,6 +39,7 @@ import uuid
modx_modules={'problem':courseware.modules.capa_module.LoncapaModule,
'video':courseware.modules.video_module.VideoModule,
'html':courseware.modules.html_module.HtmlModule,
'vertical':courseware.modules.vertical_module.VerticalModule,
'schematic':courseware.modules.schematic_module.SchematicModule}
def make_track_function(request):
......@@ -81,19 +83,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
# Return whatever the module wanted to return to the client/caller
return HttpResponse(ajax_return)
def vertical_module(request, module):
''' Layout module which lays out content vertically.
'''
contents=[(e.get("name"),render_module(request, e)) \
for e in module]
init_js="".join([e[1]['init_js'] for e in contents if 'init_js' in e[1]])
destroy_js="".join([e[1]['destroy_js'] for e in contents if 'destroy_js' in e[1]])
return {'init_js':init_js,
'destroy_js':destroy_js,
'content':render_to_string('vert_module.html',{'items':contents}),
'type':'vertical'}
def seq_module(request, module):
''' Layout module which lays out content in a temporal sequence
'''
......@@ -163,7 +152,9 @@ def render_x_module(request, xml_module):
module_id,
ajax_url=ajax_url,
state=state,
track_function = make_track_function(request))
track_function = make_track_function(request),
render_function = render_module,
meta = request)
# If instance wasn't already in the database, create it
if len(s) == 0:
......@@ -184,7 +175,7 @@ def render_x_module(request, xml_module):
module_types={'video':render_x_module,
'html':render_x_module,
'tab':seq_module,
'vertical':vertical_module,
'vertical':render_x_module,
'sequential':seq_module,
'problem':render_x_module,
'schematic':render_x_module
......
......@@ -108,8 +108,8 @@ class LoncapaModule(XModule):
return html
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None):
XModule.__init__(self, xml, item_id, ajax_url, track_url, state, track_function)
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)
self.attempts = 0
self.max_attempts = None
......
......@@ -25,8 +25,8 @@ class HtmlModule(XModule):
textlist=[i for i in textlist if type(i)==str]
return "".join(textlist)
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None):
XModule.__init__(self, xml, item_id, ajax_url, track_url, state, track_function)
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.filename = None
filename_l=xmltree.xpath("/html/@filename")
......
......@@ -18,6 +18,6 @@ class SchematicModule(XModule):
def get_html(self):
return '<input type="hidden" class="schematic" name="{item_id}" height="480" width="640">'.format(item_id=self.item_id)
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)
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, render_function = None, meta = None):
XModule.__init__(self, xml, item_id, ajax_url, track_url, state, render_function)
from x_module import XModule
from lxml import etree
import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
class VerticalModule(XModule):
id_attribute = 'id'
def get_state(self):
return json.dumps({ })
def get_xml_tags():
return "vertical"
def get_html(self):
return render_to_string('vert_module.html',{'items':self.contents})
def get_init_js(self):
return self.init_js_text
def get_destroy_js(self):
return self.destroy_js_text
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.filename = None
filename_l=xmltree.xpath("/html/@filename")
if len(filename_l)>0:
self.filename=str(filename_l[0])
self.contents=[(e.get("name"),self.render_function(meta, e)) \
for e in xmltree]
self.init_js_text="".join([e[1]['init_js'] for e in self.contents if 'init_js' in e[1]])
self.destroy_js_text="".join([e[1]['destroy_js'] for e in self.contents if 'destroy_js' in e[1]])
......@@ -46,8 +46,8 @@ class VideoModule(XModule):
def get_destroy_js(self):
return "videoDestroy();"
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None):
XModule.__init__(self, xml, item_id, ajax_url, track_url, state, track_function)
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)
print state
if state!=None and "time" not in json.loads(state):
self.video_time = 0
......@@ -39,11 +39,13 @@ class XModule(object):
get is a dictionary-like object '''
return ""
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None):
def __init__(self, xml, item_id, ajax_url=None, track_url=None, state=None, track_function=None, render_function = None, meta = None):
''' In most cases, you must pass state or xml'''
self.xml=xml
self.item_id=item_id
self.ajax_url=ajax_url
self.track_url=track_url
self.state=state
self.tracker=track_function
self.xml = xml
self.item_id = item_id
self.ajax_url = ajax_url
self.track_url = track_url
self.state = state
self.tracker = track_function
self.render_function = render_function
self.meta = meta
......@@ -133,9 +133,13 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
module=render_module(request, module)
print "Here",module['init_js']
if 'init_js' not in module:
module['init_js']=''
context={'init':accordion['init_js']+module['init_js'],
'accordion':accordion['content'],
'content':module['content'],
......
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