Commit 91b306b3 by Calen Pennington

Moving capa and xmodule out of djangoapps/courseware, and removing django references from them

parent 5ba03130
# #
# File: courseware/capa/capa_problem.py # File: capa/capa_problem.py
# #
''' '''
Main module which shows problems (of "capa" type). Main module which shows problems (of "capa" type).
...@@ -31,7 +31,7 @@ from responsetypes import NumericalResponse, FormulaResponse, CustomResponse, Sc ...@@ -31,7 +31,7 @@ from responsetypes import NumericalResponse, FormulaResponse, CustomResponse, Sc
import calc import calc
import eia import eia
log = logging.getLogger("mitx.courseware") log = logging.getLogger(__name__)
response_types = {'numericalresponse':NumericalResponse, response_types = {'numericalresponse':NumericalResponse,
'formularesponse':FormulaResponse, 'formularesponse':FormulaResponse,
...@@ -231,9 +231,8 @@ class LoncapaProblem(object): ...@@ -231,9 +231,8 @@ class LoncapaProblem(object):
code = unescape(code,XMLESC) code = unescape(code,XMLESC)
try: try:
exec code in context, context # use "context" for global context; thus defs in code are global within code exec code in context, context # use "context" for global context; thus defs in code are global within code
except Exception,err: except Exception:
log.exception("[courseware.capa.capa_problem.extract_context] error %s" % err) log.exception("Error while execing code: " + code)
log.exception("in doing exec of this code: %s" % code)
return context return context
def get_html(self): def get_html(self):
...@@ -273,9 +272,6 @@ class LoncapaProblem(object): ...@@ -273,9 +272,6 @@ class LoncapaProblem(object):
else: else:
msg = '' msg = ''
#if settings.DEBUG:
# print "[courseware.capa.capa_problem.extract_html] msg = ",msg
# do the rendering # do the rendering
# This should be broken out into a helper function # This should be broken out into a helper function
# that handles all input objects # that handles all input objects
......
...@@ -25,9 +25,6 @@ Each input type takes the xml tree as 'element', the previous answer as 'value', ...@@ -25,9 +25,6 @@ Each input type takes the xml tree as 'element', the previous answer as 'value',
import re import re
import shlex # for splitting quoted strings import shlex # for splitting quoted strings
from django.conf import settings
from lxml.etree import Element
from lxml import etree from lxml import etree
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string
...@@ -166,8 +163,6 @@ def optioninput(element, value, status, msg=''): ...@@ -166,8 +163,6 @@ def optioninput(element, value, status, msg=''):
# osetdict = dict([('option_%s_%s' % (eid,x),oset[x]) for x in range(len(oset)) ]) # make dict with IDs # osetdict = dict([('option_%s_%s' % (eid,x),oset[x]) for x in range(len(oset)) ]) # make dict with IDs
osetdict = dict([(oset[x],oset[x]) for x in range(len(oset)) ]) # make dict with key,value same osetdict = dict([(oset[x],oset[x]) for x in range(len(oset)) ]) # make dict with key,value same
if settings.DEBUG:
print '[courseware.capa.inputtypes.optioninput] osetdict=',osetdict
context={'id':eid, context={'id':eid,
'value':value, 'value':value,
...@@ -383,7 +378,5 @@ def imageinput(element, value, status, msg=''): ...@@ -383,7 +378,5 @@ def imageinput(element, value, status, msg=''):
'state' : status, # to change 'state' : status, # to change
'msg': msg, # to change 'msg': msg, # to change
} }
if settings.DEBUG:
print '[courseware.capa.inputtypes.imageinput] context=',context
html=render_to_string("imageinput.html", context) html=render_to_string("imageinput.html", context)
return etree.XML(html) return etree.XML(html)
...@@ -21,12 +21,11 @@ import abc ...@@ -21,12 +21,11 @@ import abc
# specific library imports # specific library imports
from calc import evaluator, UndefinedVariable from calc import evaluator, UndefinedVariable
from django.conf import settings
from util import contextualize_text from util import contextualize_text
from lxml import etree from lxml import etree
from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME? from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME?
log = logging.getLogger("mitx.courseware") log = logging.getLogger(__name__)
def compare_with_tolerance(v1, v2, tol): def compare_with_tolerance(v1, v2, tol):
''' Compare v1 to v2 with maximum tolerance tol ''' Compare v1 to v2 with maximum tolerance tol
...@@ -144,8 +143,6 @@ class OptionResponse(GenericResponse): ...@@ -144,8 +143,6 @@ class OptionResponse(GenericResponse):
def __init__(self, xml, context, system=None): def __init__(self, xml, context, system=None):
self.xml = xml self.xml = xml
self.answer_fields = xml.findall('optioninput') self.answer_fields = xml.findall('optioninput')
if settings.DEBUG:
print '[courseware.capa.responsetypes.OR.init] answer_fields=%s' % (self.answer_fields)
self.context = context self.context = context
def get_score(self, student_answers): def get_score(self, student_answers):
...@@ -274,7 +271,7 @@ def sympy_check2(): ...@@ -274,7 +271,7 @@ def sympy_check2():
# ie the comparison function is defined in the <script>...</script> stanza instead # ie the comparison function is defined in the <script>...</script> stanza instead
cfn = xml.get('cfn') cfn = xml.get('cfn')
if cfn: if cfn:
if settings.DEBUG: log.info("[courseware.capa.responsetypes] cfn = %s" % cfn) if settings.DEBUG: log.info("cfn = %s" % cfn)
if cfn in context: if cfn in context:
self.code = context[cfn] self.code = context[cfn]
else: else:
...@@ -779,8 +776,6 @@ class ImageResponse(GenericResponse): ...@@ -779,8 +776,6 @@ class ImageResponse(GenericResponse):
correct_map[aid] = 'correct' correct_map[aid] = 'correct'
else: else:
correct_map[aid] = 'incorrect' correct_map[aid] = 'incorrect'
if settings.DEBUG:
print "[capamodule.capa.responsetypes.imageinput] correct_map=",correct_map
return correct_map return correct_map
def get_answers(self): def get_answers(self):
......
...@@ -19,7 +19,7 @@ from lxml import etree ...@@ -19,7 +19,7 @@ from lxml import etree
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string
from x_module import XModule, XModuleDescriptor from x_module import XModule, XModuleDescriptor
from courseware.capa.capa_problem import LoncapaProblem, StudentInputError from capa.capa_problem import LoncapaProblem, StudentInputError
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
from multicourse import multicourse_settings from multicourse import multicourse_settings
......
import json import json
## TODO: Abstract out from Django
from django.conf import settings
from mitxmako.shortcuts import render_to_response, render_to_string
from x_module import XModule, XModuleDescriptor from x_module import XModule, XModuleDescriptor
class ModuleDescriptor(XModuleDescriptor): class ModuleDescriptor(XModuleDescriptor):
......
import json import json
import os
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_string
from x_module import XModule, XModuleDescriptor from x_module import XModule, XModuleDescriptor
from lxml import etree from lxml import etree
...@@ -15,15 +14,7 @@ class Module(XModule): ...@@ -15,15 +14,7 @@ class Module(XModule):
@classmethod @classmethod
def get_xml_tags(c): def get_xml_tags(c):
## TODO: Abstract out from filesystem and Django return ['customtag']
## HACK: For now, this lets us import without abstracting out
try:
from django.conf import settings
tags = os.listdir(settings.DATA_DIR+'/custom_tags')
except:
print "Could not open tags directory."
tags = []
return tags
def get_html(self): def get_html(self):
return self.html return self.html
...@@ -31,6 +22,6 @@ class Module(XModule): ...@@ -31,6 +22,6 @@ class Module(XModule):
def __init__(self, system, xml, item_id, state=None): def __init__(self, system, xml, item_id, state=None):
XModule.__init__(self, system, xml, item_id, state) XModule.__init__(self, system, xml, item_id, state)
xmltree = etree.fromstring(xml) xmltree = etree.fromstring(xml)
filename = xmltree.tag filename = xmltree[0].text
params = dict(xmltree.items()) params = dict(xmltree.items())
self.html = render_to_string(filename, params, namespace = 'custom_tags') self.html = render_to_string(filename, params, namespace = 'custom_tags')
...@@ -25,6 +25,7 @@ try: # This lets us do __name__ == ='__main__' ...@@ -25,6 +25,7 @@ try: # This lets us do __name__ == ='__main__'
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string
from util.cache import cache from util.cache import cache
from multicourse import multicourse_settings from multicourse import multicourse_settings
import xmodule
except: except:
print "Could not import/content_parser" print "Could not import/content_parser"
settings = None settings = None
...@@ -103,8 +104,7 @@ def item(l, default="", process=lambda x:x): ...@@ -103,8 +104,7 @@ def item(l, default="", process=lambda x:x):
def id_tag(course): def id_tag(course):
''' Tag all course elements with unique IDs ''' ''' Tag all course elements with unique IDs '''
import courseware.modules default_ids = xmodule.get_default_ids()
default_ids = courseware.modules.get_default_ids()
# Tag elements with unique IDs # Tag elements with unique IDs
elements = course.xpath("|".join(['//'+c for c in default_ids])) elements = course.xpath("|".join(['//'+c for c in default_ids]))
...@@ -166,11 +166,20 @@ def user_groups(user): ...@@ -166,11 +166,20 @@ def user_groups(user):
# return [u.name for u in UserTestGroup.objects.raw("select * from auth_user, student_usertestgroup, student_usertestgroup_users where auth_user.id = student_usertestgroup_users.user_id and student_usertestgroup_users.usertestgroup_id = student_usertestgroup.id and auth_user.id = %s", [user.id])] # return [u.name for u in UserTestGroup.objects.raw("select * from auth_user, student_usertestgroup, student_usertestgroup_users where auth_user.id = student_usertestgroup_users.user_id and student_usertestgroup_users.usertestgroup_id = student_usertestgroup.id and auth_user.id = %s", [user.id])]
def replace_custom_tags(tree):
tags = os.listdir(settings.DATA_DIR+'/custom_tags')
for tag in tags:
for element in tree.iter(tag):
element.tag = 'customtag'
impl = etree.SubElement(element, 'impl')
impl.text = tag
def course_xml_process(tree): def course_xml_process(tree):
''' Do basic pre-processing of an XML tree. Assign IDs to all ''' Do basic pre-processing of an XML tree. Assign IDs to all
items without. Propagate due dates, grace periods, etc. to child items without. Propagate due dates, grace periods, etc. to child
items. items.
''' '''
replace_custom_tags(tree)
id_tag(tree) id_tag(tree)
propogate_downward_tag(tree, "due") propogate_downward_tag(tree, "due")
propogate_downward_tag(tree, "graded") propogate_downward_tag(tree, "graded")
......
...@@ -29,7 +29,7 @@ from courseware import graders ...@@ -29,7 +29,7 @@ from courseware import graders
from courseware.graders import Score from courseware.graders import Score
from models import StudentModule from models import StudentModule
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
import courseware.modules import xmodule
_log = logging.getLogger("mitx.courseware") _log = logging.getLogger("mitx.courseware")
...@@ -197,7 +197,7 @@ def get_score(user, problem, cache, coursename=None): ...@@ -197,7 +197,7 @@ def get_score(user, problem, cache, coursename=None):
## HACK 2: Backwards-compatibility: This should be written when a grade is saved, and removed from the system ## HACK 2: Backwards-compatibility: This should be written when a grade is saved, and removed from the system
from module_render import I4xSystem from module_render import I4xSystem
system = I4xSystem(None, None, None, coursename=coursename) system = I4xSystem(None, None, None, coursename=coursename)
total=float(courseware.modules.capa_module.Module(system, etree.tostring(problem), "id").max_score()) total=float(xmodule.capa_module.Module(system, etree.tostring(problem), "id").max_score())
response.max_grade = total response.max_grade = total
response.save() response.save()
......
...@@ -8,7 +8,7 @@ from django.contrib.auth.models import User ...@@ -8,7 +8,7 @@ from django.contrib.auth.models import User
from courseware.content_parser import course_file from courseware.content_parser import course_file
import courseware.module_render import courseware.module_render
import courseware.modules import xmodule
class Command(BaseCommand): class Command(BaseCommand):
help = "Does basic validity tests on course.xml." help = "Does basic validity tests on course.xml."
...@@ -25,7 +25,7 @@ class Command(BaseCommand): ...@@ -25,7 +25,7 @@ class Command(BaseCommand):
check = False check = False
print "Confirming all modules render. Nothing should print during this step. " print "Confirming all modules render. Nothing should print during this step. "
for module in course.xpath('//problem|//html|//video|//vertical|//sequential|/tab'): for module in course.xpath('//problem|//html|//video|//vertical|//sequential|/tab'):
module_class = courseware.modules.modx_modules[module.tag] module_class = xmodule.modx_modules[module.tag]
# TODO: Abstract this out in render_module.py # TODO: Abstract this out in render_module.py
try: try:
module_class(etree.tostring(module), module_class(etree.tostring(module),
......
...@@ -6,19 +6,18 @@ from lxml import etree ...@@ -6,19 +6,18 @@ from lxml import etree
from django.http import Http404 from django.http import Http404
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.template import Context
from django.template import Context, loader
from fs.osfs import OSFS from fs.osfs import OSFS
from django.conf import settings from django.conf import settings
from mitxmako.shortcuts import render_to_string from mitxmako.shortcuts import render_to_string, render_to_response
from models import StudentModule from models import StudentModule
from multicourse import multicourse_settings from multicourse import multicourse_settings
from util.views import accepts
import courseware.modules
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
import xmodule
log = logging.getLogger("mitx.courseware") log = logging.getLogger("mitx.courseware")
...@@ -90,7 +89,7 @@ def grade_histogram(module_id): ...@@ -90,7 +89,7 @@ def grade_histogram(module_id):
def get_module(user, request, xml_module, module_object_preload, position=None): def get_module(user, request, xml_module, module_object_preload, position=None):
module_type=xml_module.tag module_type=xml_module.tag
module_class=courseware.modules.get_module_class(module_type) module_class=xmodule.get_module_class(module_type)
module_id=xml_module.get('id') #module_class.id_attribute) or "" module_id=xml_module.get('id') #module_class.id_attribute) or ""
# Grab state from database # Grab state from database
...@@ -231,7 +230,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -231,7 +230,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
) )
try: try:
instance=courseware.modules.get_module_class(module)(system, instance=xmodule.get_module_class(module)(system,
xml, xml,
id, id,
state=oldstate) state=oldstate)
......
...@@ -10,9 +10,9 @@ import os ...@@ -10,9 +10,9 @@ import os
import numpy import numpy
import courseware.modules import xmodule
import courseware.capa.calc as calc import capa.calc as calc
import courseware.capa.capa_problem as lcp import capa.capa_problem as lcp
import courseware.graders as graders import courseware.graders as graders
from courseware.graders import Score, CourseGrader, WeightedSubsectionsGrader, SingleSectionGrader, AssignmentFormatGrader from courseware.graders import Score, CourseGrader, WeightedSubsectionsGrader, SingleSectionGrader, AssignmentFormatGrader
from courseware.grades import aggregate_scores from courseware.grades import aggregate_scores
...@@ -41,10 +41,10 @@ class ModelsTest(unittest.TestCase): ...@@ -41,10 +41,10 @@ class ModelsTest(unittest.TestCase):
pass pass
def test_get_module_class(self): def test_get_module_class(self):
vc = courseware.modules.get_module_class('video') vc = xmodule.get_module_class('video')
vc_str = "<class 'courseware.modules.video_module.Module'>" vc_str = "<class 'xmodule.video_module.Module'>"
self.assertEqual(str(vc), vc_str) self.assertEqual(str(vc), vc_str)
video_id = courseware.modules.get_default_ids()['video'] video_id = xmodule.get_default_ids()['video']
self.assertEqual(video_id, 'youtube') self.assertEqual(video_id, 'youtube')
def test_calc(self): def test_calc(self):
......
...@@ -20,9 +20,9 @@ from module_render import render_x_module, make_track_function, I4xSystem ...@@ -20,9 +20,9 @@ from module_render import render_x_module, make_track_function, I4xSystem
from models import StudentModule from models import StudentModule
from student.models import UserProfile from student.models import UserProfile
from multicourse import multicourse_settings from multicourse import multicourse_settings
import xmodule
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
import courseware.modules
import courseware.grades as grades import courseware.grades as grades
...@@ -288,4 +288,3 @@ def jump_to(request, probname=None): ...@@ -288,4 +288,3 @@ def jump_to(request, probname=None):
position = parent.index(pxml)+1 # position in sequence position = parent.index(pxml)+1 # position in sequence
return index(request,course=coursename,chapter=chapter,section=section,position=position) return index(request,course=coursename,chapter=chapter,section=section,position=position)
import datetime
import json
import sys
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from mitxmako.shortcuts import render_to_response
from django.core.context_processors import csrf
from django.core.mail import send_mail
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string
import courseware.capa.calc
import track.views
from multicourse import multicourse_settings from multicourse import multicourse_settings
def mitxhome(request): def mitxhome(request):
......
...@@ -47,6 +47,7 @@ GENERATE_PROFILE_SCORES = False ...@@ -47,6 +47,7 @@ GENERATE_PROFILE_SCORES = False
############################# SET PATH INFORMATION ############################# ############################# SET PATH INFORMATION #############################
PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/lms PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /mitx/lms
COMMON_ROOT = PROJECT_ROOT.dirname() / "common"
ENV_ROOT = PROJECT_ROOT.dirname().dirname() # virtualenv dir /mitx is in ENV_ROOT = PROJECT_ROOT.dirname().dirname() # virtualenv dir /mitx is in
ASKBOT_ROOT = ENV_ROOT / "askbot-devel" ASKBOT_ROOT = ENV_ROOT / "askbot-devel"
COURSES_ROOT = ENV_ROOT / "data" COURSES_ROOT = ENV_ROOT / "data"
...@@ -59,6 +60,7 @@ sys.path.append(ASKBOT_ROOT) ...@@ -59,6 +60,7 @@ sys.path.append(ASKBOT_ROOT)
sys.path.append(ASKBOT_ROOT / "askbot" / "deps") sys.path.append(ASKBOT_ROOT / "askbot" / "deps")
sys.path.append(PROJECT_ROOT / 'djangoapps') sys.path.append(PROJECT_ROOT / 'djangoapps')
sys.path.append(PROJECT_ROOT / 'lib') sys.path.append(PROJECT_ROOT / 'lib')
sys.path.append(COMMON_ROOT / 'lib')
################################## MITXWEB ##################################### ################################## MITXWEB #####################################
# This is where we stick our compiled template files. Most of the app uses Mako # This is where we stick our compiled template files. Most of the app uses Mako
......
...@@ -11,14 +11,14 @@ from django.http import HttpResponse ...@@ -11,14 +11,14 @@ from django.http import HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_response, render_to_string
import courseware.capa.calc import capa.calc
import track.views import track.views
def calculate(request): def calculate(request):
''' Calculator in footer of every page. ''' ''' Calculator in footer of every page. '''
equation = request.GET['equation'] equation = request.GET['equation']
try: try:
result = courseware.capa.calc.evaluator({}, {}, equation) result = capa.calc.evaluator({}, {}, equation)
except: except:
event = {'error':map(str,sys.exc_info()), event = {'error':map(str,sys.exc_info()),
'equation':equation} 'equation':equation}
......
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