0

I was able to write a python script to check an edx problem between tags. However I would like to include a python function from a file, in order to reuse the code in several problems. I tried the following code:

<problem>
  <script type="loncapa/python" src="/static/textinput.py" />

  <customresponse cfn="check_function">
    <script type="loncapa/python">
<![CDATA[
import json

def check_function(e, ans):

# ... my code ...

    </script>

    <jsinput
      gradefn="getGrade"
      get_statefn="getState"
      set_statefn="setState"
             initial_state='{"selectedChoice": "[]"}'
      width="600"
      html_file="/static/Ex1_3 v2.html"
      title="Problem"
      sop="false"/>
  </customresponse>
</problem>

I get the following error when saving the problem:

Problem block-v1:Casal+Basic1+1701+type@problem+block@55479f8087e64d2395b730037cbe83c3 has an error: cannot create LoncapaProblem block-v1:Casal+Basic1+1701+type@problem+block@55479f8087e64d2395b730037cbe83c3: 'NoneType' object has no attribute 'replace'

Traceback (most recent call last):
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/capa_base.py", line 234, in init
self.lcp = self.new_lcp(self.get_state_for_lcp())
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/capa_base.py", line 328, in new_lcp
capa_module=self, # njp File "/edx/app/edxapp/edx-platform/common/lib/capa/capa/capa_problem.py", line 192, in init
self.context = self._extract_context(self.tree)
Files "/edx/app/edxapp/edx-platform/common/lib/capa/capa/capa_problem.py", line 728, in _extract_context
code = unescape(script.text, XMLESC)
File "/usr/lib/python2.7/xml/sax/saxutils.py", line 46, in unescape
data = data.replace("<", "<")

Is it possible to do this? If so, is it correct to use the tag:? Of course the file textinput.py is uploaded and works well in python.

<script type="loncapa/python" src="/static/textinput.py" />

stovfl
  • 14,998
  • 7
  • 24
  • 51

0 Answers0