Semi-generic registration mechanism for modules. Still need to clean up references in content_parser
--HG-- branch : pmitros-mod-template
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
import os.path
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
import capa_module
|
||||
import html_module
|
||||
import schematic_module
|
||||
import seq_module
|
||||
import template_module
|
||||
import vertical_module
|
||||
import video_module
|
||||
|
||||
# Import all files in modules directory, excluding backups (# and . in name)
|
||||
# and __init__
|
||||
#
|
||||
# Stick them in a list
|
||||
modx_module_list = []
|
||||
|
||||
for f in os.listdir(os.path.dirname(__file__)):
|
||||
if f!='__init__.py' and \
|
||||
f[-3:] == ".py" and \
|
||||
"." not in f[:-3] \
|
||||
and '#' not in f:
|
||||
mod_path = 'courseware.modules.'+f[:-3]
|
||||
mod = __import__(mod_path, fromlist = "courseware.modules")
|
||||
if 'Module' in mod.__dict__:
|
||||
modx_module_list.append(mod)
|
||||
|
||||
# Convert list to a dictionary for lookup by tag
|
||||
modx_modules = {}
|
||||
for module in modx_module_list:
|
||||
for tag in module.Module.get_xml_tags():
|
||||
modx_modules[tag] = module.Module
|
||||
|
||||
def get_module_class(tag):
|
||||
return modx_modules[tag]
|
||||
|
||||
|
||||
@@ -26,15 +26,18 @@ import courseware.content_parser as content_parser
|
||||
|
||||
log = logging.getLogger("mitx.courseware")
|
||||
|
||||
class LoncapaModule(XModule):
|
||||
class Module(XModule):
|
||||
''' Interface between capa_problem and x_module. Originally a hack
|
||||
meant to be refactored out, but it seems to be serving a useful
|
||||
prupose now. We can e.g .destroy and create the capa_problem on a
|
||||
reset.
|
||||
'''
|
||||
xml_tags = ["problem"]
|
||||
|
||||
id_attribute = "filename"
|
||||
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
return ["problem"]
|
||||
|
||||
def get_state(self):
|
||||
state = self.lcp.get_state()
|
||||
|
||||
@@ -7,14 +7,15 @@ from mitxmako.shortcuts import render_to_response, render_to_string
|
||||
from x_module import XModule
|
||||
from lxml import etree
|
||||
|
||||
class HtmlModule(XModule):
|
||||
class Module(XModule):
|
||||
id_attribute = 'filename'
|
||||
|
||||
def get_state(self):
|
||||
return json.dumps({ })
|
||||
|
||||
def get_xml_tags():
|
||||
return "html"
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
return ["html"]
|
||||
|
||||
def get_html(self):
|
||||
if self.filename==None:
|
||||
|
||||
@@ -6,14 +6,15 @@ from mitxmako.shortcuts import render_to_response, render_to_string
|
||||
|
||||
from x_module import XModule
|
||||
|
||||
class SchematicModule(XModule):
|
||||
class Module(XModule):
|
||||
id_attribute = 'id'
|
||||
|
||||
def get_state(self):
|
||||
return json.dumps({ })
|
||||
|
||||
def get_xml_tags():
|
||||
return "schematic"
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
return ["schematic"]
|
||||
|
||||
def get_html(self):
|
||||
return '<input type="hidden" class="schematic" name="{item_id}" height="480" width="640">'.format(item_id=self.item_id)
|
||||
|
||||
@@ -13,7 +13,7 @@ from x_module import XModule
|
||||
# OBSOLETE: This obsoletes 'type'
|
||||
class_priority = ['video', 'problem']
|
||||
|
||||
class SequentialModule(XModule):
|
||||
class Module(XModule):
|
||||
''' Layout module which lays out content in a temporal sequence
|
||||
'''
|
||||
id_attribute = 'id'
|
||||
@@ -21,7 +21,8 @@ class SequentialModule(XModule):
|
||||
def get_state(self):
|
||||
return json.dumps({ 'position':self.position })
|
||||
|
||||
def get_xml_tags():
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
return ["sequential", 'tab']
|
||||
|
||||
def get_html(self):
|
||||
|
||||
@@ -7,14 +7,15 @@ from mitxmako.shortcuts import render_to_response, render_to_string
|
||||
from x_module import XModule
|
||||
from lxml import etree
|
||||
|
||||
class VerticalModule(XModule):
|
||||
class Module(XModule):
|
||||
id_attribute = 'id'
|
||||
|
||||
def get_state(self):
|
||||
return json.dumps({ })
|
||||
|
||||
def get_xml_tags():
|
||||
return "vertical"
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
return ["vertical"]
|
||||
|
||||
def get_html(self):
|
||||
return render_to_string('vert_module.html',{'items':self.contents})
|
||||
|
||||
@@ -11,7 +11,7 @@ from x_module import XModule
|
||||
|
||||
log = logging.getLogger("mitx.courseware.modules")
|
||||
|
||||
class VideoModule(XModule):
|
||||
class Module(XModule):
|
||||
#id_attribute = 'youtube'
|
||||
video_time = 0
|
||||
|
||||
@@ -28,9 +28,10 @@ class VideoModule(XModule):
|
||||
log.debug(u"STATE POSITION {0}".format(self.position))
|
||||
return json.dumps({ 'position':self.position })
|
||||
|
||||
def get_xml_tags():
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
'''Tags in the courseware file guaranteed to correspond to the module'''
|
||||
return "video"
|
||||
return ["video"]
|
||||
|
||||
def video_list(self):
|
||||
l = self.youtube.split(',')
|
||||
|
||||
@@ -10,7 +10,8 @@ class XModule(object):
|
||||
'''
|
||||
id_attribute='name' # An attribute guaranteed to be unique
|
||||
|
||||
def get_xml_tags():
|
||||
@classmethod
|
||||
def get_xml_tags(c):
|
||||
''' Tags in the courseware file guaranteed to correspond to the module '''
|
||||
return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user