Commit bd2a44ad by David Ormsbee

Merge pull request #90 from MITx/cpennington/capa_django_deps

Removing references to django.conf.settings from capa/responsetypes.py
parents 2991eba1 c3e730a0
...@@ -23,6 +23,7 @@ log = logging.getLogger('capa.checker') ...@@ -23,6 +23,7 @@ log = logging.getLogger('capa.checker')
class DemoSystem(object): class DemoSystem(object):
def __init__(self): def __init__(self):
self.lookup = TemplateLookup(directories=[path(__file__).dirname() / 'templates']) self.lookup = TemplateLookup(directories=[path(__file__).dirname() / 'templates'])
self.DEBUG = True
def render_template(self, template_filename, dictionary, context=None): def render_template(self, template_filename, dictionary, context=None):
if context is None: if context is None:
......
...@@ -277,14 +277,14 @@ def sympy_check2(): ...@@ -277,14 +277,14 @@ def sympy_check2():
print "can't find cfn in context = ",context print "can't find cfn in context = ",context
if not self.code: if not self.code:
if not answer: if answer is None:
# raise Exception,"[courseware.capa.responsetypes.customresponse] missing code checking script! id=%s" % self.myid # raise Exception,"[courseware.capa.responsetypes.customresponse] missing code checking script! id=%s" % self.myid
print "[courseware.capa.responsetypes.customresponse] missing code checking script! id=%s" % self.myid print "[courseware.capa.responsetypes.customresponse] missing code checking script! id=%s" % self.myid
self.code = '' self.code = ''
else: else:
answer_src = answer.get('src') answer_src = answer.get('src')
if answer_src is not None: if answer_src is not None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read() self.code = self.system.filesystem.open('src/'+answer_src).read()
else: else:
self.code = answer.text self.code = answer.text
...@@ -329,8 +329,7 @@ def sympy_check2(): ...@@ -329,8 +329,7 @@ def sympy_check2():
}) })
# pass self.system.debug to cfn # pass self.system.debug to cfn
# if hasattr(self.system,'debug'): self.context['debug'] = self.system.debug self.context['debug'] = self.system.DEBUG
self.context['debug'] = settings.DEBUG
# exec the check function # exec the check function
if type(self.code)==str: if type(self.code)==str:
...@@ -492,7 +491,7 @@ main() ...@@ -492,7 +491,7 @@ main()
answer_src = answer.get('src') answer_src = answer.get('src')
if answer_src is not None: if answer_src is not None:
self.code = open(settings.DATA_DIR+'src/'+answer_src).read() self.code = self.system.filesystem.open('src/'+answer_src).read()
else: else:
self.code = answer.text self.code = answer.text
...@@ -522,7 +521,7 @@ main() ...@@ -522,7 +521,7 @@ main()
log.error(msg) log.error(msg)
raise Exception, msg raise Exception, msg
if settings.DEBUG: log.info('response = %s' % r.text) if self.system.DEBUG: log.info('response = %s' % r.text)
if (not r.text ) or (not r.text.strip()): if (not r.text ) or (not r.text.strip()):
raise Exception,'Error: no response from external server url=%s' % self.url raise Exception,'Error: no response from external server url=%s' % self.url
...@@ -551,7 +550,7 @@ main() ...@@ -551,7 +550,7 @@ main()
rxml = self.do_external_request('get_score',extra_payload) rxml = self.do_external_request('get_score',extra_payload)
except Exception, err: except Exception, err:
log.error('Error %s' % err) log.error('Error %s' % err)
if settings.DEBUG: if self.system.DEBUG:
correct_map = dict(zip(sorted(self.answer_ids), ['incorrect'] * len(self.answer_ids) )) correct_map = dict(zip(sorted(self.answer_ids), ['incorrect'] * len(self.answer_ids) ))
correct_map['msg_%s' % self.answer_ids[0]] = '<font color="red" size="+2">%s</font>' % str(err).replace('<','&lt;') correct_map['msg_%s' % self.answer_ids[0]] = '<font color="red" size="+2">%s</font>' % str(err).replace('<','&lt;')
return correct_map return correct_map
...@@ -581,7 +580,7 @@ main() ...@@ -581,7 +580,7 @@ main()
exans = json.loads(rxml.find('expected').text) exans = json.loads(rxml.find('expected').text)
except Exception,err: except Exception,err:
log.error('Error %s' % err) log.error('Error %s' % err)
if settings.DEBUG: if self.system.DEBUG:
msg = '<font color=red size=+2>%s</font>' % str(err).replace('<','&lt;') msg = '<font color=red size=+2>%s</font>' % str(err).replace('<','&lt;')
exans = [''] * len(self.answer_ids) exans = [''] * len(self.answer_ids)
exans[0] = msg exans[0] = msg
......
...@@ -11,7 +11,8 @@ from datetime import timedelta ...@@ -11,7 +11,8 @@ from datetime import timedelta
from lxml import etree from lxml import etree
from x_module import XModule, XModuleDescriptor from x_module import XModule, XModuleDescriptor
from capa.capa_problem import LoncapaProblem, StudentInputError from capa.capa_problem import LoncapaProblem
from capa.responsetypes import StudentInputError
log = logging.getLogger("mitx.courseware") log = logging.getLogger("mitx.courseware")
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
......
...@@ -70,7 +70,8 @@ MAKO_TEMPLATES = {} ...@@ -70,7 +70,8 @@ MAKO_TEMPLATES = {}
MAKO_TEMPLATES['course'] = [DATA_DIR] MAKO_TEMPLATES['course'] = [DATA_DIR]
MAKO_TEMPLATES['sections'] = [DATA_DIR / 'sections'] MAKO_TEMPLATES['sections'] = [DATA_DIR / 'sections']
MAKO_TEMPLATES['custom_tags'] = [DATA_DIR / 'custom_tags'] MAKO_TEMPLATES['custom_tags'] = [DATA_DIR / 'custom_tags']
MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates', MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates',
COMMON_ROOT / 'lib' / 'capa' / 'templates',
DATA_DIR / 'info', DATA_DIR / 'info',
DATA_DIR / 'problems'] DATA_DIR / 'problems']
......
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