Unstable state; need to merge from master

This commit is contained in:
Piotr Mitros
2012-05-31 13:44:45 -04:00
parent 9fdbdd3b73
commit 34dc32e5aa
11 changed files with 147 additions and 92 deletions

View File

@@ -31,6 +31,9 @@ class ComplexEncoder(json.JSONEncoder):
return "{real:.7g}{imag:+.7g}*j".format(real = obj.real,imag = obj.imag)
return json.JSONEncoder.default(self, obj)
class ModuleDescriptor(XModuleDescriptor):
pass
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

View File

@@ -5,6 +5,9 @@ from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
id_attribute = 'filename'

View File

@@ -6,6 +6,9 @@ from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
id_attribute = 'id'

View File

@@ -10,6 +10,9 @@ from x_module import XModule
# OBSOLETE: This obsoletes 'type'
class_priority = ['video', 'problem']
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
''' Layout module which lays out content in a temporal sequence
'''
@@ -66,8 +69,7 @@ class Module(XModule):
self.titles = json.dumps(["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") != None]) \
for e in self.xmltree])
self.contents = [j(self.render_function(e)) \
for e in self.xmltree]
self.contents = self.rendered_children(self)
print self.titles

View File

@@ -6,6 +6,9 @@ from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
def get_state(self):
return json.dumps({ })

View File

@@ -5,6 +5,9 @@ from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
id_attribute = 'id'

View File

@@ -9,6 +9,9 @@ from x_module import XModule
log = logging.getLogger("mitx.courseware.modules")
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
id_attribute = 'youtube'
video_time = 0

View File

@@ -24,6 +24,21 @@ class XModule(object):
or a CAPA input type '''
return ['xmodule']
def get_name():
name = self.__xmltree.get(name)
if name:
return name
else:
raise "We should iterate through children and find a default name"
def rendered_children(self):
'''
Render all children.
This really ought to return a list of xmodules, instead of dictionaries
'''
children = [render_function(e) for e in self.__xmltree]
return children
def __init__(self, system = None, xml = None, item_id = None,
json = None, track_url=None, state=None):
''' In most cases, you must pass state or xml'''
@@ -38,6 +53,8 @@ class XModule(object):
self.json = json
self.item_id = item_id
self.state = state
self.__xmltree = etree.fromstring(xml) # PRIVATE
if system:
## These are temporary; we really should go
@@ -102,14 +119,24 @@ class XModule(object):
get is a dictionary-like object '''
return ""
### Functions used in the CMS
class XModuleDescriptor(object):
def __init__(self, xml = None, json = None):
if not xml and not json:
raise "XModuleDescriptor must be initalized with XML or JSON"
if not xml:
raise NotImplementedError("Code does not have support for JSON yet")
self.xml = xml
self.json = json
def get_xml(self):
''' For conversions between JSON and legacy XML representations.
'''
if self.xml:
return self.xml
else:
raise NotImplementedError
raise NotImplementedError("JSON->XML Translation not implemented")
def get_json(self):
''' For conversions between JSON and legacy XML representations.
@@ -118,14 +145,14 @@ class XModule(object):
raise NotImplementedError
return self.json # TODO: Return context as well -- files, etc.
else:
raise NotImplementedError
raise NotImplementedError("XML->JSON Translation not implemented")
def handle_cms_json(self):
raise NotImplementedError
#def handle_cms_json(self):
# raise NotImplementedError
def render(self, size):
''' Size: [thumbnail, small, full]
Small ==> what we drag around
Full ==> what we edit
'''
raise NotImplementedError
#def render(self, size):
# ''' Size: [thumbnail, small, full]
# Small ==> what we drag around
# Full ==> what we edit
# '''
# raise NotImplementedError