From 261948f38a7709e1972d5a140f2fd6b7470d3351 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 17 Sep 2012 13:19:24 -0400 Subject: [PATCH 1/5] Make textbooks in the course definition be stored as data, rather than objects, and turn them into objects during module instatiation --- common/lib/xmodule/xmodule/course_module.py | 28 +++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 7aa904205d..5ea0c13d65 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -22,9 +22,6 @@ class CourseDescriptor(SequenceDescriptor): self.book_url = book_url self.table_of_contents = self._get_toc_from_s3() - @classmethod - def from_xml_object(cls, xml_object): - return cls(xml_object.get('title'), xml_object.get('book_url')) @property def table_of_contents(self): @@ -57,10 +54,18 @@ class CourseDescriptor(SequenceDescriptor): return table_of_contents - def __init__(self, system, definition=None, **kwargs): super(CourseDescriptor, self).__init__(system, definition, **kwargs) - self.textbooks = self.definition['data']['textbooks'] + + self.textbooks = [] + for title, book_url in self.definition['data']['textbooks']: + try: + self.textbooks.append(self.Textbook(title, book_url)) + except: + # If we can't get to S3 (e.g. on a train with no internet), don't break + # the rest of the courseware. + log.exception("Couldn't load textbook ({0}, {1})".format(title, book_url)) + continue self.wiki_slug = self.definition['data']['wiki_slug'] or self.location.course @@ -82,7 +87,6 @@ class CourseDescriptor(SequenceDescriptor): # disable the syllabus content for courses that do not provide a syllabus self.syllabus_present = self.system.resources_fs.exists(path('syllabus')) - def set_grading_policy(self, policy_str): """Parse the policy specified in policy_str, and save it""" try: @@ -94,19 +98,11 @@ class CourseDescriptor(SequenceDescriptor): # the error log. self._grading_policy = {} - @classmethod def definition_from_xml(cls, xml_object, system): textbooks = [] for textbook in xml_object.findall("textbook"): - try: - txt = cls.Textbook.from_xml_object(textbook) - except: - # If we can't get to S3 (e.g. on a train with no internet), don't break - # the rest of the courseware. - log.exception("Couldn't load textbook") - continue - textbooks.append(txt) + textbooks = (textbook.get('title'), textbook.get('book_url')) xml_object.remove(textbook) #Load the wiki tag if it exists @@ -116,7 +112,7 @@ class CourseDescriptor(SequenceDescriptor): wiki_slug = wiki_tag.attrib.get("slug", default=None) xml_object.remove(wiki_tag) - definition = super(CourseDescriptor, cls).definition_from_xml(xml_object, system) + definition = super(CourseDescriptor, cls).definition_from_xml(xml_object, system) definition.setdefault('data', {})['textbooks'] = textbooks definition['data']['wiki_slug'] = wiki_slug From 34541b5e7c4b597b5f87231345640c64602398cb Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 17 Sep 2012 13:49:42 -0400 Subject: [PATCH 2/5] Make a list of textbooks, don't just store a single one --- common/lib/xmodule/xmodule/course_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 5ea0c13d65..3af65d1bd6 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -102,7 +102,7 @@ class CourseDescriptor(SequenceDescriptor): def definition_from_xml(cls, xml_object, system): textbooks = [] for textbook in xml_object.findall("textbook"): - textbooks = (textbook.get('title'), textbook.get('book_url')) + textbooks.append((textbook.get('title'), textbook.get('book_url'))) xml_object.remove(textbook) #Load the wiki tag if it exists From 0a55e1eae13789cc3cad1f693cfc072351f44af5 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 17 Sep 2012 13:51:33 -0400 Subject: [PATCH 3/5] Add sub-environments for the lms that is running alongside the lms for debugging --- lms/envs/cms/__init__.py | 0 lms/envs/{with_cms.py => cms/aws.py} | 0 lms/envs/cms/dev.py | 19 +++++++++++++++++++ rakefile | 4 ++-- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 lms/envs/cms/__init__.py rename lms/envs/{with_cms.py => cms/aws.py} (100%) create mode 100644 lms/envs/cms/dev.py diff --git a/lms/envs/cms/__init__.py b/lms/envs/cms/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lms/envs/with_cms.py b/lms/envs/cms/aws.py similarity index 100% rename from lms/envs/with_cms.py rename to lms/envs/cms/aws.py diff --git a/lms/envs/cms/dev.py b/lms/envs/cms/dev.py new file mode 100644 index 0000000000..6e4697cccb --- /dev/null +++ b/lms/envs/cms/dev.py @@ -0,0 +1,19 @@ +""" +Settings for the LMS that runs alongside the CMS on AWS +""" + +from ..dev import * + +MODULESTORE = { + 'default': { + 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', + 'OPTIONS': { + 'default_class': 'xmodule.raw_module.RawDescriptor', + 'host': 'localhost', + 'db': 'xmodule', + 'collection': 'modulestore', + 'fs_root': DATA_DIR, + 'render_template': 'mitxmako.shortcuts.render_to_string', + } + } +} diff --git a/rakefile b/rakefile index 9e0bbcbfa4..be5ef1d9e7 100644 --- a/rakefile +++ b/rakefile @@ -125,8 +125,8 @@ TEST_TASKS = [] end # Per environment tasks - Dir["#{system}/envs/*.py"].each do |env_file| - env = File.basename(env_file).gsub(/\.py/, '') + Dir["#{system}/envs/**/*.py"].each do |env_file| + env = env_file.gsub("#{system}/envs/", '').gsub(/\.py/, '').gsub('/', '.') desc "Attempt to import the settings file #{system}.envs.#{env} and report any errors" task "#{system}:check_settings:#{env}" => :predjango do sh("echo 'import #{system}.envs.#{env}' | #{django_admin(system, env, 'shell')}") From d17e2aada90f69e30940345037f87d76d3c1b033 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 17 Sep 2012 14:19:07 -0400 Subject: [PATCH 4/5] Remove trailing '/' from ajax_urls --- cms/djangoapps/contentstore/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index d701db33a3..505b897497 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -207,7 +207,7 @@ def preview_module_system(request, preview_id, descriptor): descriptor: An XModuleDescriptor """ return ModuleSystem( - ajax_url=reverse('preview_dispatch', args=[preview_id, descriptor.location.url(), '']), + ajax_url=reverse('preview_dispatch', args=[preview_id, descriptor.location.url(), '']).rstrip('/'), # TODO (cpennington): Do we want to track how instructors are using the preview problems? track_function=lambda type, event: None, filestore=descriptor.system.resources_fs, From c0ed79397647f90458fb80a7552f1980fd2679d3 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 17 Sep 2012 14:19:23 -0400 Subject: [PATCH 5/5] Add an empty get_errored_courses function for the mongo modulestore --- common/lib/xmodule/xmodule/modulestore/mongo.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index 7aa05e474f..33901947a6 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -316,3 +316,9 @@ class MongoModuleStore(ModuleStoreBase): {'_id': True}) return [i['_id'] for i in items] + def get_errored_courses(self): + """ + This function doesn't make sense for the mongo modulestore, as courses + are loaded on demand, rather than up front + """ + return {}