# Copyright (C) 2013 Bradley N. Miller, Barabara Ericson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
__author__ = 'bmiller'
from docutils import nodes
from docutils.parsers.rst import directives
from docutils.parsers.rst import Directive
from assessbase import *
import json
import random
class MChoiceNode(nodes.General, nodes.Element):
def __init__(self,content):
"""
Arguments:
- `self`:
- `content`:
"""
super(MChoiceNode,self).__init__()
self.mc_options = content
def visit_mc_node(self,node):
res = ""
res = node.template_start % node.mc_options
self.body.append(res)
def depart_mc_node(self,node):
res = node.template_form_start % node.mc_options
feedbackStr = "["
currFeedback = ""
# Add all of the possible answers
okeys = node.mc_options.keys()
okeys.sort()
for k in okeys:
if 'answer_' in k:
x,label = k.split('_')
node.mc_options['alabel'] = label
node.mc_options['atext'] = node.mc_options[k]
res += node.template_option % node.mc_options
currFeedback = "feedback_" + label
feedbackStr = feedbackStr + "'" + escapejs(node.mc_options[currFeedback]) + "', "
# store the feedback array with key feedback minus last comma
node.mc_options['feedback'] = feedbackStr[0:-2] + "]"
res += node.template_end % node.mc_options
self.body.append(res)
#####################
# multiple choice question with multiple feedback
# author - Barb Ericson
# author - Anusha
class MChoiceMF(Assessment):
required_arguments = 1
optional_arguments = 1
final_argument_whitespace = True
has_content = True
option_spec = {'answer_a':directives.unchanged,
'answer_b':directives.unchanged,
'answer_c':directives.unchanged,
'answer_d':directives.unchanged,
'answer_e':directives.unchanged,
'correct':directives.unchanged,
'feedback_a':directives.unchanged,
'feedback_b':directives.unchanged,
'feedback_c':directives.unchanged,
'feedback_d':directives.unchanged,
'feedback_e':directives.unchanged,
'iscode':directives.flag
}
def run(self):
"""
process the multiplechoice directive and generate html for output.
:param self:
:return:
.. mcmfstorage:: qname
:iscode: boolean
:answer_a: possible answer -- what follows _ is label
:answer_b: possible answer
...
:answer_e: possible answer
:correct: leter of correct answer
:feedback_a: displayed if a is picked
:feedback_b: displayed if b is picked
:feedback_c: displayed if c is picked
:feedback_d: displayed if d is picked
:feedback_e: displayed if e is picked
Question text
...
"""
TEMPLATE_START = '''