From a7b5433c36b81989d6413e550273b7c83b942e11 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Tue, 27 Dec 2011 19:35:40 -0500 Subject: [PATCH] Minor cleanups. Javascript only called once. Hidden sections now work --- courseware/capa_module.py | 13 +------------ courseware/content_parser.py | 3 +-- courseware/html_module.py | 1 + courseware/module_render.py | 3 +-- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/courseware/capa_module.py b/courseware/capa_module.py index 8436670ec7..5120b07878 100644 --- a/courseware/capa_module.py +++ b/courseware/capa_module.py @@ -102,34 +102,26 @@ class LoncapaModule(XModule): self.max_attempts = None self.due_date = None - #dom=parseString(xml) - #dom2 = libxml2.parseMemory(xml, len(xml)) dom2 = etree.fromstring(xml) - #node=dom.childNodes[0] - - #self.due_date=node.getAttribute("due") - self.due_date=content_parser.item(dom2.xpath('/problem/@due'))#dom2.xpathEval('/problem/@due')) + self.due_date=content_parser.item(dom2.xpath('/problem/@due')) if len(self.due_date)>0: self.due_date=dateutil.parser.parse(self.due_date) else: self.due_date=None - #self.max_attempts=node.getAttribute("attempts") self.max_attempts=content_parser.item(dom2.xpath('/problem/@attempts')) if len(self.max_attempts)>0: self.max_attempts=int(self.max_attempts) else: self.max_attempts=None - #self.show_answer=node.getAttribute("showanswer") self.show_answer=content_parser.item(dom2.xpath('/problem/@showanswer')) if self.show_answer=="": self.show_answer="closed" self.rerandomize=content_parser.item(dom2.xpath('/problem/@rerandomize')) - #self.rerandomize=node.getAttribute("rerandomize") if self.rerandomize=="": self.rerandomize=True elif self.rerandomize=="false": @@ -145,10 +137,7 @@ class LoncapaModule(XModule): self.attempts=state['attempts'] self.filename=content_parser.item(dom2.xpath('/problem/@filename')) - #self.filename=node.getAttribute("filename") - #print self.filename filename=settings.DATA_DIR+"problems/"+self.filename+".xml" - #self.name=node.getAttribute("name") self.name=content_parser.item(dom2.xpath('/problem/@name')) self.lcp=LoncapaProblem(filename, self.item_id, state) diff --git a/courseware/content_parser.py b/courseware/content_parser.py index d1ebd36cd4..bfeab1db6f 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -27,7 +27,6 @@ def course_file(user): def module_xml(coursefile, module, id_tag, module_id): ''' Get XML for a module based on module and module_id. Assumes module occurs once in courseware XML file.. ''' - #doc = libxml2.parseFile(coursefile) doc = etree.parse(coursefile) # Sanitize input @@ -35,7 +34,7 @@ def module_xml(coursefile, module, id_tag, module_id): raise Exception("Module is not alphanumeric") if not module_id.isalnum(): raise Exception("Module ID is not alphanumeric") - xpath_search='//*/{module}[@{id_tag} = "{id}"]'.format(module=module, + xpath_search='//*/{module}[(@{id_tag} = "{id}") or (@id = "{id}")]'.format(module=module, id_tag=id_tag, id=module_id) #result_set=doc.xpathEval(xpath_search) diff --git a/courseware/html_module.py b/courseware/html_module.py index 2035116146..b2f0c0a002 100644 --- a/courseware/html_module.py +++ b/courseware/html_module.py @@ -21,3 +21,4 @@ class HtmlModule(XModule): 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) + print xml diff --git a/courseware/module_render.py b/courseware/module_render.py index 8976bc6965..22d8c14f7c 100644 --- a/courseware/module_render.py +++ b/courseware/module_render.py @@ -51,7 +51,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ajax_url = '/modx/'+module+'/'+id+'/' id_tag=modx_modules[module].id_attribute - #print "X",s.xml, "Y",content_parser.module_xml(module, id_tag, id) xml = content_parser.module_xml(content_parser.course_file(request.user), module, id_tag, id) @@ -97,7 +96,7 @@ def seq_module(request, module): for e in module.childNodes \ if e.nodeType==1] - js="".join([e[1]['init_js'] for e in contents if 'init_js' in e[1]]) + js="" iid=uuid.uuid1().hex