Commit c7f95695 by Calen Pennington

Fix check_course command

parent 3a26b980
......@@ -193,50 +193,6 @@ def replace_custom_tags(tree):
replace_custom_tags_dir(tree, settings.DATA_DIR+'/custom_tags')
def course_file(user, coursename=None):
''' Given a user, return an xml tree object for the course file.
Handles getting the right file, and processing it depending on the
groups the user is in. Does caching of the xml strings.
'''
if user.is_authenticated():
# use user.profile_cache.courseware?
filename = UserProfile.objects.get(user=user).courseware
else:
filename = 'guest_course.xml'
# if a specific course is specified, then use multicourse to get
# the right path to the course XML directory
if coursename and settings.ENABLE_MULTICOURSE:
xp = multicourse_settings.get_course_xmlpath(coursename)
filename = xp + filename # prefix the filename with the path
groups = user_groups(user)
options = get_options(user)
# Try the cache...
cache_key = "{0}_processed?dev_content:{1}&groups:{2}".format(
filename,
options['dev_content'],
sorted(groups))
if "dev" in settings.DEFAULT_GROUPS:
tree_string = None
else:
tree_string = cache.get(cache_key)
if tree_string:
tree = etree.XML(tree_string)
else:
tree = parse_course_file(filename, options, namespace='course')
# Cache it
tree_string = etree.tostring(tree)
cache.set(cache_key, tree_string, 60)
return tree
def sections_dir(coursename=None):
''' Get directory where sections information is stored.
'''
......
......@@ -6,50 +6,36 @@ from django.core.management.base import BaseCommand
from django.conf import settings
from django.contrib.auth.models import User
from courseware.content_parser import course_file
import courseware.module_render
import xmodule
import mitxmako.middleware as middleware
middleware.MakoMiddleware()
from keystore.django import keystore
from courseware.models import StudentModuleCache
from courseware.module_render import get_module
def check_names(user, course):
'''
Complain if any problems have non alphanumeric names.
TODO (vshnayder): there are some in 6.002x that don't. Is that actually a problem?
'''
all_ok = True
print "Confirming all problems have alphanumeric names"
for problem in course.xpath('//problem'):
filename = problem.get('filename')
if not filename.isalnum():
print "==============> Invalid (non-alphanumeric) filename", filename
all_ok = False
return all_ok
def check_rendering(user, course):
def check_rendering(module):
'''Check that all modules render'''
all_ok = True
print "Confirming all modules render. Nothing should print during this step. "
for module in course.xpath('//problem|//html|//video|//vertical|//sequential|/tab'):
module_class = xmodule.modx_modules[module.tag]
# TODO: Abstract this out in render_module.py
try:
module_class(etree.tostring(module),
module.get('id'),
ajax_url='',
state=None,
track_function = lambda x,y,z:None,
render_function = lambda x: {'content':'','type':'video'})
def _check_module(module):
try:
module.get_html()
except Exception as ex:
print "==============> Error in ", etree.tostring(module)
print "==============> Error in ", module.id
print ""
print ex
all_ok = False
for child in module.get_children():
_check_module(child)
_check_module(module)
print "Module render check finished"
return all_ok
def check_sections(user, course):
def check_sections(course):
all_ok = True
sections_dir = settings.DATA_DIR + "/sections"
print "Checking that all sections exist and parse properly"
......@@ -69,11 +55,13 @@ def check_sections(user, course):
all_ok = False
print "checked all sections"
else:
print "Skipping check of include files -- no section includes dir ("+sections_dir+")"
print "Skipping check of include files -- no section includes dir (" + sections_dir + ")"
return all_ok
class Command(BaseCommand):
help = "Does basic validity tests on course.xml."
def handle(self, *args, **options):
all_ok = True
......@@ -86,22 +74,25 @@ class Command(BaseCommand):
sample_user = User.objects.all()[0]
print "Attempting to load courseware"
course = course_file(sample_user)
to_run = [check_names,
# TODO (vshnayder) : make check_rendering work (use module_render.py),
# turn it on
# check_rendering,
check_sections,
]
# TODO (cpennington): Get coursename in a legitimate way
course_location = 'i4x://edx/6002xs12/course/6.002_Spring_2012'
student_module_cache = StudentModuleCache(sample_user, keystore().get_item(course_location))
(course, _, _, _) = get_module(sample_user, None, course_location, student_module_cache)
to_run = [
#TODO (vshnayder) : make check_rendering work (use module_render.py),
# turn it on
check_rendering,
check_sections,
]
for check in to_run:
all_ok = check(sample_user, course) and all_ok
all_ok = check(course) and all_ok
# TODO: print "Checking course properly annotated with preprocess.py"
if all_ok:
print 'Courseware passes all checks!'
else:
else:
print "Courseware fails some checks"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment