From 34dc32e5aaecd73f151a0cc65d36baff95df3cf4 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Thu, 31 May 2012 13:44:45 -0400 Subject: [PATCH 1/8] Unstable state; need to merge from master --- djangoapps/courseware/module_render.py | 90 +++++++++++++++++-- djangoapps/courseware/modules/capa_module.py | 3 + djangoapps/courseware/modules/html_module.py | 3 + .../courseware/modules/schematic_module.py | 3 + djangoapps/courseware/modules/seq_module.py | 6 +- .../courseware/modules/template_module.py | 3 + .../courseware/modules/vertical_module.py | 3 + djangoapps/courseware/modules/video_module.py | 3 + djangoapps/courseware/modules/x_module.py | 49 +++++++--- djangoapps/courseware/views.py | 74 +-------------- run.sh | 2 +- 11 files changed, 147 insertions(+), 92 deletions(-) diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 278d19fd2c..ed3429d747 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -78,9 +78,8 @@ def grade_histogram(module_id): return [] return grades -def render_x_module(user, request, xml_module, module_object_preload): - ''' Generic module for extensions. This renders to HTML. ''' - # Check if problem has an instance in DB + +def get_module(user, request, xml_module, module_object_preload): module_type=xml_module.tag module_class=courseware.modules.get_module_class(module_type) module_id=xml_module.get('id') #module_class.id_attribute) or "" @@ -128,6 +127,15 @@ def render_x_module(user, request, xml_module, module_object_preload): smod.save() module_object_preload.append(smod) + return smod + +def render_x_module(user, request, xml_module, module_object_preload): + ''' Generic module for extensions. This renders to HTML. ''' + if module==None : + return {"content":""} + + smod = get_module(user, request, xml_module, module_object_preload) + # Grab content content = instance.get_html() init_js = instance.get_init_js() @@ -153,6 +161,78 @@ def render_x_module(user, request, xml_module, module_object_preload): def render_module(user, request, module, module_object_preload): ''' Generic dispatch for internal modules. ''' - if module==None : - return {"content":""} return render_x_module(user, request, module, module_object_preload) + + +def modx_dispatch(request, module=None, dispatch=None, id=None): + ''' Generic view for extensions. ''' + if not request.user.is_authenticated(): + return redirect('/') + + # Grab the student information for the module from the database + s = StudentModule.objects.filter(student=request.user, + module_id=id) + #s = StudentModule.get_with_caching(request.user, id) + if len(s) == 0 or s is None: + log.debug("Couldnt find module for user and id " + str(module) + " " + str(request.user) + " "+ str(id)) + raise Http404 + s = s[0] + + oldgrade = s.grade + oldstate = s.state + + dispatch=dispatch.split('?')[0] + + ajax_url = settings.MITX_ROOT_URL + '/modx/'+module+'/'+id+'/' + + # get coursename if stored + coursename = multicourse_settings.get_coursename_from_request(request) + + if coursename and settings.ENABLE_MULTICOURSE: + xp = multicourse_settings.get_course_xmlpath(coursename) # path to XML for the course + data_root = settings.DATA_DIR + xp + else: + data_root = settings.DATA_DIR + + # Grab the XML corresponding to the request from course.xml + try: + xml = content_parser.module_xml(request.user, module, 'id', id, coursename) + except: + log.exception("Unable to load module during ajax call") + if accepts(request, 'text/html'): + return render_to_response("module-error.html", {}) + else: + response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"})) + return response + + # Create the module + system = I4xSystem(track_function = make_track_function(request), + render_function = None, + ajax_url = ajax_url, + filestore = OSFS(data_root), + ) + + try: + instance=courseware.modules.get_module_class(module)(system, + xml, + id, + state=oldstate) + except: + log.exception("Unable to load module instance during ajax call") + if accepts(request, 'text/html'): + return render_to_response("module-error.html", {}) + else: + response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"})) + return response + + # Let the module handle the AJAX + ajax_return=instance.handle_ajax(dispatch, request.POST) + # Save the state back to the database + s.state=instance.get_state() + if instance.get_score(): + s.grade=instance.get_score()['score'] + if s.grade != oldgrade or s.state != oldstate: + s.save() + # Return whatever the module wanted to return to the client/caller + return HttpResponse(ajax_return) + diff --git a/djangoapps/courseware/modules/capa_module.py b/djangoapps/courseware/modules/capa_module.py index 7d42cfb250..058b5f5454 100644 --- a/djangoapps/courseware/modules/capa_module.py +++ b/djangoapps/courseware/modules/capa_module.py @@ -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 diff --git a/djangoapps/courseware/modules/html_module.py b/djangoapps/courseware/modules/html_module.py index 77bcbb4bbc..3b62df0390 100644 --- a/djangoapps/courseware/modules/html_module.py +++ b/djangoapps/courseware/modules/html_module.py @@ -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' diff --git a/djangoapps/courseware/modules/schematic_module.py b/djangoapps/courseware/modules/schematic_module.py index 5fef265e01..1643737e4a 100644 --- a/djangoapps/courseware/modules/schematic_module.py +++ b/djangoapps/courseware/modules/schematic_module.py @@ -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' diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index af41d0e8da..42508295db 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -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 diff --git a/djangoapps/courseware/modules/template_module.py b/djangoapps/courseware/modules/template_module.py index a8899f985c..c779691cc1 100644 --- a/djangoapps/courseware/modules/template_module.py +++ b/djangoapps/courseware/modules/template_module.py @@ -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({ }) diff --git a/djangoapps/courseware/modules/vertical_module.py b/djangoapps/courseware/modules/vertical_module.py index e57a58e33e..519ed755ea 100644 --- a/djangoapps/courseware/modules/vertical_module.py +++ b/djangoapps/courseware/modules/vertical_module.py @@ -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' diff --git a/djangoapps/courseware/modules/video_module.py b/djangoapps/courseware/modules/video_module.py index c678838f2b..12136cf7f2 100644 --- a/djangoapps/courseware/modules/video_module.py +++ b/djangoapps/courseware/modules/video_module.py @@ -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 diff --git a/djangoapps/courseware/modules/x_module.py b/djangoapps/courseware/modules/x_module.py index b475fd0280..ae6822da1d 100644 --- a/djangoapps/courseware/modules/x_module.py +++ b/djangoapps/courseware/modules/x_module.py @@ -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 diff --git a/djangoapps/courseware/views.py b/djangoapps/courseware/views.py index 014f759ed1..228a33461b 100644 --- a/djangoapps/courseware/views.py +++ b/djangoapps/courseware/views.py @@ -16,7 +16,7 @@ from django.views.decorators.cache import cache_control from lxml import etree -from module_render import render_module, make_track_function, I4xSystem +from module_render import render_module, make_track_function, I4xSystem, modx_dispatch from models import StudentModule from student.models import UserProfile from util.views import accepts @@ -237,78 +237,6 @@ def index(request, course=None, chapter="Using the System", section="Hints"): return result -def modx_dispatch(request, module=None, dispatch=None, id=None): - ''' Generic view for extensions. ''' - if not request.user.is_authenticated(): - return redirect('/') - - # Grab the student information for the module from the database - s = StudentModule.objects.filter(student=request.user, - module_id=id) - #s = StudentModule.get_with_caching(request.user, id) - if len(s) == 0 or s is None: - log.debug("Couldnt find module for user and id " + str(module) + " " + str(request.user) + " "+ str(id)) - raise Http404 - s = s[0] - - oldgrade = s.grade - oldstate = s.state - - dispatch=dispatch.split('?')[0] - - ajax_url = settings.MITX_ROOT_URL + '/modx/'+module+'/'+id+'/' - - # get coursename if stored - coursename = multicourse_settings.get_coursename_from_request(request) - - if coursename and settings.ENABLE_MULTICOURSE: - xp = multicourse_settings.get_course_xmlpath(coursename) # path to XML for the course - data_root = settings.DATA_DIR + xp - else: - data_root = settings.DATA_DIR - - # Grab the XML corresponding to the request from course.xml - try: - xml = content_parser.module_xml(request.user, module, 'id', id, coursename) - except: - log.exception("Unable to load module during ajax call") - if accepts(request, 'text/html'): - return render_to_response("module-error.html", {}) - else: - response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"})) - return response - - # Create the module - system = I4xSystem(track_function = make_track_function(request), - render_function = None, - ajax_url = ajax_url, - filestore = OSFS(data_root), - ) - - try: - instance=courseware.modules.get_module_class(module)(system, - xml, - id, - state=oldstate) - except: - log.exception("Unable to load module instance during ajax call") - if accepts(request, 'text/html'): - return render_to_response("module-error.html", {}) - else: - response = HttpResponse(json.dumps({'success': "We're sorry, this module is temporarily unavailable. Our staff is working to fix it as soon as possible"})) - return response - - # Let the module handle the AJAX - ajax_return=instance.handle_ajax(dispatch, request.POST) - # Save the state back to the database - s.state=instance.get_state() - if instance.get_score(): - s.grade=instance.get_score()['score'] - if s.grade != oldgrade or s.state != oldstate: - s.save() - # Return whatever the module wanted to return to the client/caller - return HttpResponse(ajax_return) - def quickedit(request, id=None): ''' quick-edit capa problem. diff --git a/run.sh b/run.sh index d63ed291f0..0c65a4a72c 100755 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -django-admin.py runserver --settings=envs.dev --pythonpath=. +django-admin runserver --settings=envs.dev --pythonpath=. From 98d8f4b55bb6ca17e0545ce262213f15cff0f2bf Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Thu, 31 May 2012 21:12:08 -0400 Subject: [PATCH 2/8] Unstable commit; syncing computers --- djangoapps/courseware/module_render.py | 6 +++--- djangoapps/courseware/modules/capa_module.py | 2 +- djangoapps/courseware/modules/html_module.py | 2 +- djangoapps/courseware/modules/schematic_module.py | 2 +- djangoapps/courseware/modules/seq_module.py | 4 ++-- djangoapps/courseware/modules/template_module.py | 2 +- djangoapps/courseware/modules/vertical_module.py | 2 +- djangoapps/courseware/modules/video_module.py | 2 +- djangoapps/courseware/modules/x_module.py | 4 +++- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 1e12e182cd..e9303bb18b 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -128,14 +128,14 @@ def get_module(user, request, xml_module, module_object_preload): smod.save() module_object_preload.append(smod) - return smod + return (instance, smod) def render_x_module(user, request, xml_module, module_object_preload): ''' Generic module for extensions. This renders to HTML. ''' - if module==None : + if xml_module==None : return {"content":""} - smod = get_module(user, request, xml_module, module_object_preload) + (instance, smod) = get_module(user, request, xml_module, module_object_preload) # Grab content content = instance.get_html() diff --git a/djangoapps/courseware/modules/capa_module.py b/djangoapps/courseware/modules/capa_module.py index 3c357ee47e..9e2a62aca0 100644 --- a/djangoapps/courseware/modules/capa_module.py +++ b/djangoapps/courseware/modules/capa_module.py @@ -18,7 +18,7 @@ from lxml import etree ## TODO: Abstract out from Django from mitxmako.shortcuts import render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor from courseware.capa.capa_problem import LoncapaProblem, StudentInputError import courseware.content_parser as content_parser from multicourse import multicourse_settings diff --git a/djangoapps/courseware/modules/html_module.py b/djangoapps/courseware/modules/html_module.py index 3b62df0390..bf60174e18 100644 --- a/djangoapps/courseware/modules/html_module.py +++ b/djangoapps/courseware/modules/html_module.py @@ -2,7 +2,7 @@ import json from mitxmako.shortcuts import render_to_response, render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor from lxml import etree class ModuleDescriptor(XModuleDescriptor): diff --git a/djangoapps/courseware/modules/schematic_module.py b/djangoapps/courseware/modules/schematic_module.py index 1643737e4a..a6459b5e6e 100644 --- a/djangoapps/courseware/modules/schematic_module.py +++ b/djangoapps/courseware/modules/schematic_module.py @@ -4,7 +4,7 @@ import json from django.conf import settings from mitxmako.shortcuts import render_to_response, render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor class ModuleDescriptor(XModuleDescriptor): pass diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index 648582a166..f8ab6b9166 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -4,7 +4,7 @@ from lxml import etree from mitxmako.shortcuts import render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor # HACK: This shouldn't be hard-coded to two types # OBSOLETE: This obsoletes 'type' @@ -57,7 +57,7 @@ class Module(XModule): titles = ["\n".join([i.get("name").strip() for i in e.iter() if i.get("name") != None]) \ for e in self.xmltree] - self.contents = self.rendered_children(self) + self.contents = self.rendered_children() for contents, title in zip(self.contents, titles): contents['title'] = title diff --git a/djangoapps/courseware/modules/template_module.py b/djangoapps/courseware/modules/template_module.py index c779691cc1..938b5c4497 100644 --- a/djangoapps/courseware/modules/template_module.py +++ b/djangoapps/courseware/modules/template_module.py @@ -3,7 +3,7 @@ import os from mitxmako.shortcuts import render_to_response, render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor from lxml import etree class ModuleDescriptor(XModuleDescriptor): diff --git a/djangoapps/courseware/modules/vertical_module.py b/djangoapps/courseware/modules/vertical_module.py index 5f208bb796..0819fb9f1b 100644 --- a/djangoapps/courseware/modules/vertical_module.py +++ b/djangoapps/courseware/modules/vertical_module.py @@ -2,7 +2,7 @@ import json from mitxmako.shortcuts import render_to_response, render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor from lxml import etree class ModuleDescriptor(XModuleDescriptor): diff --git a/djangoapps/courseware/modules/video_module.py b/djangoapps/courseware/modules/video_module.py index 0f80a79e41..95c7102fed 100644 --- a/djangoapps/courseware/modules/video_module.py +++ b/djangoapps/courseware/modules/video_module.py @@ -5,7 +5,7 @@ from lxml import etree from mitxmako.shortcuts import render_to_response, render_to_string -from x_module import XModule +from x_module import XModule, XModuleDescriptor log = logging.getLogger("mitx.courseware.modules") diff --git a/djangoapps/courseware/modules/x_module.py b/djangoapps/courseware/modules/x_module.py index e77f4e36f6..93489fab04 100644 --- a/djangoapps/courseware/modules/x_module.py +++ b/djangoapps/courseware/modules/x_module.py @@ -1,3 +1,5 @@ +from lxml import etree + import courseware.progress def dummy_track(event_type, event): @@ -36,7 +38,7 @@ class XModule(object): Render all children. This really ought to return a list of xmodules, instead of dictionaries ''' - children = [render_function(e) for e in self.__xmltree] + children = [self.render_function(e) for e in self.__xmltree] return children def __init__(self, system = None, xml = None, item_id = None, From 7567e5ebf9a49ebfbdb5a9e7b8f409afae170811 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Fri, 1 Jun 2012 10:29:12 -0400 Subject: [PATCH 3/8] Working snapshot. Simple get_children. get_module taken out of render_module. --- djangoapps/courseware/module_render.py | 5 +++-- djangoapps/courseware/modules/seq_module.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index e9303bb18b..26948023dd 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -18,6 +18,7 @@ from models import StudentModule from multicourse import multicourse_settings import courseware.modules +import courseware.content_parser as content_parser log = logging.getLogger("mitx.courseware") @@ -128,14 +129,14 @@ def get_module(user, request, xml_module, module_object_preload): smod.save() module_object_preload.append(smod) - return (instance, smod) + return (instance, smod, module_type) def render_x_module(user, request, xml_module, module_object_preload): ''' Generic module for extensions. This renders to HTML. ''' if xml_module==None : return {"content":""} - (instance, smod) = get_module(user, request, xml_module, module_object_preload) + (instance, smod, module_type) = get_module(user, request, xml_module, module_object_preload) # Grab content content = instance.get_html() diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index f8ab6b9166..8726df2e41 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -58,6 +58,7 @@ class Module(XModule): for e in self.xmltree] self.contents = self.rendered_children() + self.contents = [j(m) for m in self.contents] for contents, title in zip(self.contents, titles): contents['title'] = title From be1e308dc9e4c18ec70a581774103e4574c1eb99 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Fri, 1 Jun 2012 12:56:20 -0400 Subject: [PATCH 4/8] Cale's fix for eval/extra json encode --- djangoapps/courseware/modules/seq_module.py | 15 +++------------ static/coffee/src/modules/sequence.coffee | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index 8726df2e41..1c97d6d006 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -41,11 +41,9 @@ class Module(XModule): if self.rendered: return def j(m): - ''' jsonify contents so it can be embedded in a js array - We also need to split tags so they don't break - mid-string''' - content=json.dumps(m['content']) - content=content.replace('', '<"+"/script>') + ''' Split tags -- browsers handle this as end + of script, even if it occurs mid-string''' + content=m['content'].replace('', '<"+"/script>') return {'content':content, 'type': m['type']} @@ -76,13 +74,6 @@ class Module(XModule): 'titles':titles, 'tag':self.xmltree.tag} - # TODO/BUG: Destroy JavaScript should only be called for the active view - # This calls it for all the views - # - # To fix this, we'd probably want to have some way of assigning unique - # IDs to sequences. - destroy_js="".join([e['destroy_js'] for e in self.contents if 'destroy_js' in e]) - if self.xmltree.tag in ['sequential', 'videosequence']: self.content=render_to_string('seq_module.html',params) if self.xmltree.tag == 'tab': diff --git a/static/coffee/src/modules/sequence.coffee b/static/coffee/src/modules/sequence.coffee index 0789c7c7f0..56a9b551bf 100644 --- a/static/coffee/src/modules/sequence.coffee +++ b/static/coffee/src/modules/sequence.coffee @@ -39,7 +39,7 @@ class @Sequence $.postWithPrefix "/modx/#{@tag}/#{@id}/goto_position", position: new_position @mark_active new_position - @$('#seq_content').html eval(@elements[new_position - 1].content) + @$('#seq_content').html @elements[new_position - 1].content MathJax.Hub.Queue(["Typeset", MathJax.Hub]) @position = new_position From 0a8a7795ff14abff49dc45bf8cc196847a16a932 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Fri, 1 Jun 2012 16:02:23 -0400 Subject: [PATCH 5/8] Fixed run script --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 0c65a4a72c..3e273657dc 100755 --- a/run.sh +++ b/run.sh @@ -1 +1 @@ -django-admin runserver --settings=envs.dev --pythonpath=. +django-admin.py runserver --settings=envs.dev --pythonpath=. || django-admin runserver --settings=envs.dev --pythonpath=. \ No newline at end of file From 794022733df0f6d865b1cbc823f31e3b08fc34b0 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 1 Jun 2012 16:34:00 -0400 Subject: [PATCH 6/8] Do json dumping and replacement as close to the template as possible --- djangoapps/courseware/modules/seq_module.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/djangoapps/courseware/modules/seq_module.py b/djangoapps/courseware/modules/seq_module.py index 5abe56231c..3604fa0a6a 100644 --- a/djangoapps/courseware/modules/seq_module.py +++ b/djangoapps/courseware/modules/seq_module.py @@ -40,15 +40,6 @@ class Module(XModule): def render(self): if self.rendered: return - def j(m): - ''' Split tags -- browsers handle this as end - of script, even if it occurs mid-string''' - content=m['content'].replace('', '<"+"/script>') - - return {'content':content, - 'type': m['type']} - - ## Returns a set of all types of all sub-children child_classes = [set([i.tag for i in e.iter()]) for e in self.xmltree] @@ -56,7 +47,6 @@ class Module(XModule): for e in self.xmltree] self.contents = self.rendered_children() - self.contents = [j(m) for m in self.contents] for contents, title in zip(self.contents, titles): contents['title'] = title @@ -68,7 +58,10 @@ class Module(XModule): new_class = c content['type'] = new_class - params={'items':self.contents, + # Split tags -- browsers handle this as end + # of script, even if it occurs mid-string. Do this after json.dumps()ing + # so that we can be sure of the quotations being used + params={'items':json.dumps(self.contents).replace('', '<"+"/script>'), 'id':self.item_id, 'position': self.position, 'titles':titles, From d49d0b9119f7b8b39df04775971ddbe1d240461d Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 1 Jun 2012 16:37:03 -0400 Subject: [PATCH 7/8] Remove render_module in favor of render_x_module --- djangoapps/courseware/module_render.py | 6 +----- djangoapps/courseware/views.py | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/djangoapps/courseware/module_render.py b/djangoapps/courseware/module_render.py index 88e464be59..de8364b752 100644 --- a/djangoapps/courseware/module_render.py +++ b/djangoapps/courseware/module_render.py @@ -110,7 +110,7 @@ def get_module(user, request, xml_module, module_object_preload): ajax_url = settings.MITX_ROOT_URL + '/modx/'+module_type+'/'+module_id+'/' system = I4xSystem(track_function = make_track_function(request), - render_function = lambda x: render_module(user, request, x, module_object_preload), + render_function = lambda x: render_x_module(user, request, x, module_object_preload), ajax_url = ajax_url, filestore = OSFS(data_root), ) @@ -155,10 +155,6 @@ def render_x_module(user, request, xml_module, module_object_preload): return content -def render_module(user, request, module, module_object_preload): - ''' Generic dispatch for internal modules. ''' - return render_x_module(user, request, module, module_object_preload) - def modx_dispatch(request, module=None, dispatch=None, id=None): ''' Generic view for extensions. ''' diff --git a/djangoapps/courseware/views.py b/djangoapps/courseware/views.py index a098753728..869b3f96ae 100644 --- a/djangoapps/courseware/views.py +++ b/djangoapps/courseware/views.py @@ -16,7 +16,7 @@ from django.views.decorators.cache import cache_control from lxml import etree -from module_render import render_module, make_track_function, I4xSystem, modx_dispatch +from module_render import render_x_module, make_track_function, I4xSystem from models import StudentModule from student.models import UserProfile from util.views import accepts @@ -129,7 +129,7 @@ def render_section(request, section): module_object_preload = [] try: - module = render_module(user, request, dom, module_object_preload) + module = render_x_module(user, request, dom, module_object_preload) except: log.exception("Unable to load module") context.update({ @@ -219,7 +219,7 @@ def index(request, course=None, chapter="Using the System", section="Hints"): } try: - module = render_module(user, request, module, module_object_preload) + module = render_x_module(user, request, module, module_object_preload) except: log.exception("Unable to load module") context.update({ From b2477de7b490abacbc2b3bbf3d8f338aedeb7646 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 1 Jun 2012 16:37:11 -0400 Subject: [PATCH 8/8] Remove unused imports --- djangoapps/courseware/views.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/djangoapps/courseware/views.py b/djangoapps/courseware/views.py index 869b3f96ae..8b34e8b26d 100644 --- a/djangoapps/courseware/views.py +++ b/djangoapps/courseware/views.py @@ -1,6 +1,5 @@ import logging import urllib -import json from fs.osfs import OSFS @@ -8,7 +7,7 @@ from django.conf import settings from django.core.context_processors import csrf from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required -from django.http import Http404, HttpResponse +from django.http import Http404 from django.shortcuts import redirect from mitxmako.shortcuts import render_to_response, render_to_string #from django.views.decorators.csrf import ensure_csrf_cookie @@ -19,7 +18,6 @@ from lxml import etree from module_render import render_x_module, make_track_function, I4xSystem from models import StudentModule from student.models import UserProfile -from util.views import accepts from multicourse import multicourse_settings import courseware.content_parser as content_parser