Files
edx-platform/djangoapps/courseware/modules/html_module.py
Calen Pennington 8575ed439d Merge branch 'master' into dogfood
Conflicts:
	djangoapps/courseware/capa/responsetypes.py
	djangoapps/courseware/module_render.py
	djangoapps/courseware/modules/html_module.py
	djangoapps/courseware/modules/seq_module.py
	djangoapps/courseware/modules/x_module.py
	djangoapps/courseware/views.py
	templates/main.html
	templates/problem.js
	templates/textbox.html
2012-06-05 14:38:49 -04:00

47 lines
1.5 KiB
Python

import json
import logging
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule, XModuleDescriptor
from lxml import etree
log = logging.getLogger("mitx.courseware")
#-----------------------------------------------------------------------------
class ModuleDescriptor(XModuleDescriptor):
pass
class Module(XModule):
id_attribute = 'filename'
def get_state(self):
return json.dumps({ })
@classmethod
def get_xml_tags(c):
return ["html"]
def get_html(self):
if self.filename==None:
xmltree=etree.fromstring(self.xml)
textlist=[xmltree.text]+[etree.tostring(i) for i in xmltree]+[xmltree.tail]
textlist=[i for i in textlist if type(i)==str]
return "".join(textlist)
try:
filename="html/"+self.filename
return self.filestore.open(filename).read()
except: # For backwards compatibility. TODO: Remove
if self.DEBUG:
log.info('[courseware.modules.html_module] filename=%s' % self.filename)
#return render_to_string(self.filename, {'id': self.item_id})
return render_to_string(self.filename, {'id': self.item_id},namespace='course')
def __init__(self, system, xml, item_id, state=None):
XModule.__init__(self, system, xml, item_id, state)
xmltree=etree.fromstring(xml)
self.filename = None
filename_l=xmltree.xpath("/html/@filename")
if len(filename_l)>0:
self.filename=str(filename_l[0])