diff --git a/cms/djangoapps/contentstore/__init__.py b/cms/djangoapps/contentstore/__init__.py index e8dccbbf60..8b13789179 100644 --- a/cms/djangoapps/contentstore/__init__.py +++ b/cms/djangoapps/contentstore/__init__.py @@ -1,3 +1 @@ -from xmodule.templates import update_templates -update_templates() diff --git a/cms/djangoapps/contentstore/management/commands/update_templates.py b/cms/djangoapps/contentstore/management/commands/update_templates.py new file mode 100644 index 0000000000..b30d30480a --- /dev/null +++ b/cms/djangoapps/contentstore/management/commands/update_templates.py @@ -0,0 +1,9 @@ +from xmodule.templates import update_templates +from django.core.management.base import BaseCommand + +class Command(BaseCommand): + help = \ +'''Imports and updates the Studio component templates from the code pack and put in the DB''' + + def handle(self, *args, **options): + update_templates() \ No newline at end of file diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 86ae673ae8..72196f92a2 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -316,6 +316,10 @@ class CourseDescriptor(SequenceDescriptor): if isinstance(value, time.struct_time): self.metadata['enrollment_end'] = stringify_time(value) + @property + def grader(self): + return grader_from_conf(self.raw_grader) + @property def raw_grader(self): return self._grading_policy['RAW_GRADER'] diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index 8068129559..e2a4524188 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -64,7 +64,11 @@ class CachingDescriptorSystem(MakoDescriptorSystem): location = Location(location) json_data = self.module_data.get(location) if json_data is None: - return self.modulestore.get_item(location) + module = self.modulestore.get_item(location) + if module is not None: + # update our own cache after going to the DB to get cache miss + self.module_data.update(module.system.module_data) + return module else: # load the module and apply the inherited metadata try: diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index 346ee75efc..ceb559d59e 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -307,6 +307,10 @@ def index(request, course_id, chapter=None, section=None, # Specifically asked-for section doesn't exist raise Http404 + # cdodge: this looks silly, but let's refetch the section_descriptor with depth=None + # which will prefetch the children more efficiently than doing a recursive load + section_descriptor = modulestore().get_instance(course.id, section_descriptor.location, depth=None) + # Load all descendants of the section, because we're going to display its # html, which in general will need all of its children section_module_cache = StudentModuleCache.cache_for_descriptor_descendents( diff --git a/lms/djangoapps/dashboard/views.py b/lms/djangoapps/dashboard/views.py index e74d462432..266e769db5 100644 --- a/lms/djangoapps/dashboard/views.py +++ b/lms/djangoapps/dashboard/views.py @@ -3,6 +3,7 @@ import json from datetime import datetime from django.http import Http404 from mitxmako.shortcuts import render_to_response +from django.db import connection from student.models import CourseEnrollment, CourseEnrollmentAllowed from django.contrib.auth.models import User @@ -12,16 +13,18 @@ def dictfetchall(cursor): '''Returns a list of all rows from a cursor as a column: result dict. Borrowed from Django documentation''' desc = cursor.description - table=[] + table = [] table.append([col[0] for col in desc]) - table = table + cursor.fetchall() - print "Table: " + str(table) + + # ensure response from db is a list, not a tuple (which is returned + # by MySQL backed django instances) + rows_from_cursor=cursor.fetchall() + table = table + [list(row) for row in rows_from_cursor] return table def SQL_query_to_list(cursor, query_string): cursor.execute(query_string) raw_result=dictfetchall(cursor) - print raw_result return raw_result def dashboard(request): @@ -50,7 +53,6 @@ def dashboard(request): results["scalars"]["Total Enrollments Across All Courses"]=CourseEnrollment.objects.count() # establish a direct connection to the database (for executing raw SQL) - from django.db import connection cursor = connection.cursor() # define the queries that will generate our user-facing tables diff --git a/rakefile b/rakefile index 15692d0d99..f62e75507c 100644 --- a/rakefile +++ b/rakefile @@ -440,6 +440,13 @@ namespace :cms do end end +namespace :cms do + desc "Imports all the templates from the code pack" + task :update_templates do + sh(django_admin(:cms, :dev, :update_templates)) + end +end + namespace :cms do desc "Import course data within the given DATA_DIR variable" task :xlint do