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