def toxml(self): question = makeTree(['question', ['statement'], ['parts'], ['advice'], ['notes'], ['variables'], ['functions'], ['preambles'], ['rulesets'] ]) question.attrib = {'name': strcons(self.name)} question.find('statement').append(makeContentNode(self.statement)) question.find('advice').append(makeContentNode(self.advice)) parts = question.find('parts') for part in self.parts: parts.append(part.toxml()) variables = question.find('variables') for variable in self.variables: variables.append(variable.toxml()) variables.attrib = { 'condition': strcons(self.variablesTest['condition']), 'maxRuns': strcons_fix(self.variablesTest['maxRuns']), } functions = question.find('functions') for function in self.functions: functions.append(function.toxml()) rules = question.find('rulesets') for name in self.rulesets.keys(): st = etree.Element('set',{'name':name}) for rule in self.rulesets[name]: if isinstance(rule,str): st.append(etree.Element('include',{'name':rule})) else: st.append(rule.toxml()) rules.append(st) preambles = question.find('preambles') css_preamble = etree.Element('preamble') css_preamble.attrib = { 'language': 'css' } css_preamble.text = strcons(self.preamble['css']) preambles.append(css_preamble) js_preamble = etree.Element('preamble') js_preamble.attrib = { 'language': 'js' } js_preamble.text = strcons(self.preamble['js']) preambles.append(js_preamble) preambles.attrib = { 'nosubvars': 'true' } return question
def toxml(self): part = Part.toxml(self) part.append(makeTree(['answer', ['correctanswer',['math']], ['checking', ['range'] ] ])) answer = part.find('answer') answer.attrib = { 'checkvariablenames': strcons_fix(self.checkVariableNames), 'showPreview': strcons_fix(self.showPreview), } correctAnswer = answer.find('correctanswer') correctAnswer.attrib = {'simplification': strcons(self.answerSimplification)} correctAnswer.find('math').text = strcons(self.answer) checking = answer.find('checking') checking.attrib = { 'type': strcons(self.checkingType), 'accuracy': strcons_fix(self.checkingAccuracy), 'failurerate': strcons_fix(self.failureRate) } checking.find('range').attrib = {'start': strcons_fix(self.vsetRangeStart), 'end': strcons_fix(self.vsetRangeEnd), 'points': strcons_fix(self.vsetRangePoints)} answer.append(self.maxLength.toxml()) answer.append(self.minLength.toxml()) answer.append(self.mustHave.toxml()) answer.append(self.notAllowed.toxml()) answer.append(self.expectedVariableNames.toxml()) return part
def toxml(self): part = super(NumberEntryPart,self).toxml() part.append(makeTree(['answer', ['precision','message'], ] )) answer = part.find('answer') answer.attrib = { 'checkingType': strcons(self.checkingType), 'inputstep': strcons_fix(self.inputStep), 'allowfractions': strcons_fix(self.allowFractions), 'showfractionhint': strcons_fix(self.showFractionHint), 'notationstyles': strcons_fix(','.join(self.notationStyles)), 'correctanswerfraction': strcons_fix(self.correctAnswerFraction), 'correctanswerstyle': strcons_fix(self.correctAnswerStyle), 'mustbereduced': strcons_fix(self.mustBeReduced), 'mustbereducedpc': strcons_fix(self.mustBeReducedPC)+'%' } if self.checkingType == 'range': answer.attrib['minvalue'] = strcons_fix(self.minvalue) answer.attrib['maxvalue'] = strcons_fix(self.maxvalue) else: answer.attrib['answer'] = strcons_fix(self.answer) answer.attrib['accuracy'] = strcons_fix(self.checkingAccuracy) answer.find('precision').attrib = { 'type': strcons(self.precisionType), 'precision': strcons_fix(self.precision), 'partialcredit': strcons_fix(self.precisionPartialCredit)+'%', 'strict': strcons_fix(self.strictPrecision), 'showprecisionhint': strcons_fix(self.showPrecisionHint), } answer.find('precision/message').append(makeContentNode(self.precisionMessage)) return part
def toxml(self): replacement = etree.Element('replace') replacement.attrib = { 'variable': strcons(self.variable), 'part': strcons(self.part), 'must_go_first': strcons_fix(self.must_go_first), } return replacement
def toxml(self): part = Part.toxml(self) appendMany(part,['displayanswer','correctanswer','case']) part.find('displayanswer').append(makeContentNode(self.displayAnswer)) part.find('correctanswer').text = strcons(self.answer) part.find('case').attrib = {'sensitive': strcons(self.caseSensitive), 'partialcredit': strcons(self.partialCredit)+'%'} return part
def toxml(self): part = makeTree(['part', ['prompt'], ['steps'], ['scripts'], ['adaptivemarking', ['variablereplacements'], ], ['markingalgorithm'], ]) part.attrib = { 'usecustomname': strcons_fix(self.useCustomName), 'customName': strcons_fix(self.customName), 'type': strcons(self.kind), 'marks': strcons_fix(self.marks), 'stepspenalty': strcons_fix(self.stepsPenalty), 'enableminimummarks': strcons_fix(self.enableMinimumMarks), 'minimummarks': strcons_fix(self.minimumMarks), 'showcorrectanswer': strcons_fix(self.showCorrectAnswer), 'showfeedbackicon': strcons_fix(self.showFeedbackIcon) } part.find('prompt').append(makeContentNode(self.prompt)) steps = part.find('steps') for step in self.steps: steps.append(step.toxml()) scripts = part.find('scripts') for name,script_dict in self.scripts.items(): script_element = etree.Element('script') script_element.attrib = { 'name': name, 'order': script_dict.get('order','instead') } script_element.text = strcons(script_dict.get('script','')) scripts.append(script_element) marking_algorithm = part.find('markingalgorithm') marking_algorithm.text = strcons(self.customMarkingAlgorithm) marking_algorithm.attrib = { 'extend': strcons_fix(self.extendBaseMarkingAlgorithm), } variable_replacements = part.find('adaptivemarking/variablereplacements') variable_replacements.attrib = { 'strategy': self.variableReplacementStrategy } for vr in self.variable_replacements: replacement = vr.toxml() variable_replacements.append(replacement) return part
def toxml(self): qg = makeTree(['question_group',['questions']]) qg.attrib = { 'name': strcons(self.name), 'pickingStrategy': strcons(self.pickingStrategy), 'pickQuestions': strcons(self.pickQuestions), } questions = qg.find('questions') for q in self.questions: questions.append(q.toxml()) return qg
def toxml(self): part = super(PatternMatchPart,self).toxml() appendMany(part,['displayanswer','correctanswer','case']) part.find('displayanswer').append(makeContentNode(self.displayAnswer)) part.find('correctanswer').text = strcons(self.answer) part.find('correctanswer').attrib = {'mode':strcons(self.matchMode)} part.find('case').attrib = {'sensitive': strcons_fix(self.caseSensitive), 'partialcredit': strcons_fix(self.partialCredit)+'%'} return part
def toxml(self): part = makeTree(['part',['prompt'],['steps']]) part.attrib = {'type': strcons(self.kind), 'marks': strcons(self.marks), 'stepspenalty': strcons(self.stepsPenalty), 'enableminimummarks': strcons(self.enableMinimumMarks), 'minimummarks': strcons(self.minimumMarks)} part.find('prompt').append(makeContentNode(self.prompt)) steps = part.find('steps') for step in self.steps: steps.append(step.toxml()) return part
def toxml(self): rule = makeTree(['ruledef', ['conditions'] ]) rule.attrib = { 'pattern': strcons(self.pattern), 'result': strcons(self.result) } conditions = rule.find('conditions') for condition in self.conditions: conditions.append(etree.fromstring('<condition>'+condition+'</condition>')) return rule
def toxml(self): part = makeTree(['part', ['prompt'], ['steps'], ['scripts'], ['adaptivemarking', ['variablereplacements'], ], ['markingalgorithm'], ]) part.attrib = { 'type': strcons(self.kind), 'marks': strcons_fix(self.marks), 'stepspenalty': strcons_fix(self.stepsPenalty), 'enableminimummarks': strcons_fix(self.enableMinimumMarks), 'minimummarks': strcons_fix(self.minimumMarks), 'showcorrectanswer': strcons_fix(self.showCorrectAnswer), 'showfeedbackicon': strcons_fix(self.showFeedbackIcon) } part.find('prompt').append(makeContentNode(self.prompt)) steps = part.find('steps') for step in self.steps: steps.append(step.toxml()) scripts = part.find('scripts') for name,script_dict in self.scripts.items(): script_element = etree.Element('script') script_element.attrib = { 'name': name, 'order': script_dict.get('order','instead') } script_element.text = strcons(script_dict.get('script','')) scripts.append(script_element) marking_algorithm = part.find('markingalgorithm') marking_algorithm.text = strcons(self.customMarkingAlgorithm) marking_algorithm.attrib = { 'extend': strcons_fix(self.extendBaseMarkingAlgorithm), } variable_replacements = part.find('adaptivemarking/variablereplacements') variable_replacements.attrib = { 'strategy': self.variableReplacementStrategy } for vr in self.variable_replacements: replacement = vr.toxml() variable_replacements.append(replacement) return part
def toxml(self): restriction = makeTree([self.name,'message']) restriction.attrib = {'partialcredit': strcons(self.partialCredit)+'%', 'showstrings': strcons(self.showStrings)} if self.length>=0: restriction.attrib['length'] = strcons(self.length) for s in self.strings: string = etree.Element('string') string.text = strcons(s) restriction.append(string) restriction.find('message').append(makeContentNode(self.message)) return restriction
def toxml(self): question = makeTree([ 'question', ['statement'], ['parts'], ['advice'], ['notes'], ['variables'], ['functions'], ['preambles'], ['rulesets'] ]) question.attrib = {'name': strcons(self.name)} question.find('statement').append(makeContentNode(self.statement)) question.find('advice').append(makeContentNode(self.advice)) parts = question.find('parts') for part in self.parts: parts.append(part.toxml()) variables = question.find('variables') for variable in self.variables: variables.append(variable.toxml()) variables.attrib = { 'condition': strcons(self.variablesTest['condition']), 'maxRuns': strcons_fix(self.variablesTest['maxRuns']), } functions = question.find('functions') for function in self.functions: functions.append(function.toxml()) rules = question.find('rulesets') for name in self.rulesets.keys(): st = etree.Element('set', {'name': name}) for rule in self.rulesets[name]: if isinstance(rule, str): st.append(etree.Element('include', {'name': rule})) else: st.append(rule.toxml()) rules.append(st) preambles = question.find('preambles') css_preamble = etree.Element('preamble') css_preamble.attrib = {'language': 'css'} css_preamble.text = strcons(self.preamble['css']) preambles.append(css_preamble) js_preamble = etree.Element('preamble') js_preamble.attrib = {'language': 'js'} js_preamble.text = strcons(self.preamble['js']) preambles.append(js_preamble) preambles.attrib = {'nosubvars': 'true'} return question
def toxml(self): part = super(JMEPart, self).toxml() part.append( makeTree([ 'answer', ['correctanswer', ['math']], [ 'checking', ['range'], ['valuegenerators'], ] ])) answer = part.find('answer') answer.attrib = { 'checkvariablenames': strcons_fix(self.checkVariableNames), 'showPreview': strcons_fix(self.showPreview), } correctAnswer = answer.find('correctanswer') correctAnswer.attrib = { 'simplification': strcons(self.answerSimplification) } correctAnswer.find('math').text = strcons(self.answer) checking = answer.find('checking') checking.attrib = { 'type': strcons(self.checkingType), 'accuracy': strcons_fix(self.checkingAccuracy), 'failurerate': strcons_fix(self.failureRate) } checking.find('range').attrib = { 'start': strcons_fix(self.vsetRangeStart), 'end': strcons_fix(self.vsetRangeEnd), 'points': strcons_fix(self.vsetRangePoints) } valueGenerators = checking.find('valuegenerators') for g in self.valueGenerators: generator = etree.Element('generator') generator.attrib = {'name': g['name'], 'value': g['value']} valueGenerators.append(generator) answer.append(self.maxLength.toxml()) answer.append(self.minLength.toxml()) answer.append(self.mustHave.toxml()) answer.append(self.notAllowed.toxml()) answer.append(self.mustMatchPattern.toxml()) return part
def toxml(self): part = Part.toxml(self) part.append(makeTree([ 'answer', ['precision', 'message'], ])) answer = part.find('answer') answer.attrib = { 'correctanswer': strcons(self.correctAnswer), 'correctanswerfractions': strcons_fix(self.correctAnswerFractions), 'rows': strcons_fix(self.numRows), 'columns': strcons_fix(self.numColumns), 'allowresize': strcons_fix(self.allowResize), 'tolerance': strcons_fix(self.tolerance), 'markpercell': strcons_fix(self.markPerCell), 'allowfractions': strcons_fix(self.allowFractions), } answer.find('precision').attrib = { 'type': strcons_fix(self.precisionType), 'precision': strcons_fix(self.precision), 'partialcredit': strcons_fix(self.precisionPartialCredit) + '%', 'strict': strcons_fix(self.strictPrecision) } answer.find('precision/message').append( makeContentNode(self.precisionMessage)) return part
def tostring(self): try: xml = self.toxml() indent(xml) return(etree.tostring(xml,encoding="UTF-8").decode('utf-8')) except etree.ParseError as err: raise ExamError('XML Error: %s' % strcons(err))
def tostring(self): try: xml = self.toxml() indent(xml) return (etree.tostring(xml, encoding="UTF-8").decode('utf-8')) except etree.ParseError as err: raise ExamError('XML Error: %s' % strcons(err))
def toxml(self): part = super(MatrixEntryPart,self).toxml() part.append(makeTree(['answer', ['precision','message'], ] )) answer = part.find('answer') answer.attrib = { 'correctanswer': strcons(self.correctAnswer), 'correctanswerfractions': strcons_fix(self.correctAnswerFractions), 'rows': strcons_fix(self.numRows), 'columns': strcons_fix(self.numColumns), 'allowresize': strcons_fix(self.allowResize), 'tolerance': strcons_fix(self.tolerance), 'markpercell': strcons_fix(self.markPerCell), 'allowfractions': strcons_fix(self.allowFractions), } answer.find('precision').attrib = { 'type': strcons_fix(self.precisionType), 'precision': strcons_fix(self.precision), 'partialcredit': strcons_fix(self.precisionPartialCredit)+'%', 'strict': strcons_fix(self.strictPrecision) } answer.find('precision/message').append(makeContentNode(self.precisionMessage)) return part
def toxml(self): function = makeTree(['function', ['parameters'] ]) function.attrib = { 'name': strcons(self.name), 'outtype': strcons(self.type), 'definition': strcons(self.definition), 'language': strcons(self.language) } parameters = function.find('parameters') for pname,ptype in self.parameters: parameter = etree.Element('parameter',{'name': pname, 'type': ptype}) parameters.append(parameter) return function
def toxml(self): part = makeTree(['part', ['prompt'], ['steps'], ['scripts'], ['adaptivemarking', ['variablereplacements'], ] ]) part.attrib = { 'type': strcons(self.kind), 'marks': strcons_fix(self.marks), 'stepspenalty': strcons_fix(self.stepsPenalty), 'enableminimummarks': strcons_fix(self.enableMinimumMarks), 'minimummarks': strcons_fix(self.minimumMarks), 'showcorrectanswer': strcons_fix(self.showCorrectAnswer) } part.find('prompt').append(makeContentNode(self.prompt)) steps = part.find('steps') for step in self.steps: steps.append(step.toxml()) scripts = part.find('scripts') for name,script_dict in self.scripts.items(): script_element = etree.Element('script') script_element.attrib = { 'name': name, 'order': script_dict.get('order','instead') } script_element.text = strcons(script_dict.get('script','')) scripts.append(script_element) variable_replacements = part.find('adaptivemarking/variablereplacements') variable_replacements.attrib = { 'strategy': self.variableReplacementStrategy } for vr in self.variable_replacements: replacement = vr.toxml() variable_replacements.append(replacement) return part
def makeTree(struct): if struct == list(struct): name = struct[0] elem = etree.Element(name) for x in struct[1:]: elem.append(makeTree(x)) return elem elif struct == strcons(struct): return etree.Element(struct) elif etree.iselement(struct): return struct
def toxml(self): restriction = super().toxml() restriction.attrib['showstrings'] = strcons_fix(self.showStrings) for s in self.strings: string = etree.Element('string') string.text = strcons(s) restriction.append(string) return restriction
def toxml(self): part = super(JMEPart,self).toxml() part.append(makeTree(['answer', ['correctanswer',['math']], ['checking', ['range'], ['valuegenerators'], ] ])) answer = part.find('answer') answer.attrib = { 'checkvariablenames': strcons_fix(self.checkVariableNames), 'showPreview': strcons_fix(self.showPreview), } correctAnswer = answer.find('correctanswer') correctAnswer.attrib = {'simplification': strcons(self.answerSimplification)} correctAnswer.find('math').text = strcons(self.answer) checking = answer.find('checking') checking.attrib = { 'type': strcons(self.checkingType), 'accuracy': strcons_fix(self.checkingAccuracy), 'failurerate': strcons_fix(self.failureRate) } checking.find('range').attrib = {'start': strcons_fix(self.vsetRangeStart), 'end': strcons_fix(self.vsetRangeEnd), 'points': strcons_fix(self.vsetRangePoints)} valueGenerators = checking.find('valuegenerators') for g in self.valueGenerators: generator = etree.Element('generator') generator.attrib = {'name': g['name'], 'value': g['value']} valueGenerators.append(generator) answer.append(self.maxLength.toxml()) answer.append(self.minLength.toxml()) answer.append(self.mustHave.toxml()) answer.append(self.notAllowed.toxml()) answer.append(self.mustMatchPattern.toxml()) return part
def toxml(self): part = Part.toxml(self) part.append( makeTree([ 'answer', ['allowonlyintegeranswers'], ['precision', 'message'], ])) answer = part.find('answer') answer.attrib = { 'checkingType': strcons(self.checkingType), 'inputstep': strcons_fix(self.inputStep), 'allowfractions': strcons_fix(self.allowFractions), 'notationstyles': strcons_fix(','.join(self.notationStyles)), 'correctanswerfraction': strcons_fix(self.correctAnswerFraction), 'correctanswerstyle': strcons_fix(self.correctAnswerStyle), } if self.checkingType == 'range': answer.attrib['minvalue'] = strcons_fix(self.minvalue) answer.attrib['maxvalue'] = strcons_fix(self.maxvalue) else: answer.attrib['answer'] = strcons_fix(self.answer) answer.attrib['accuracy'] = strcons_fix(self.checkingAccuracy) answer.find('allowonlyintegeranswers').attrib = { 'value': strcons_fix(self.integerAnswer), 'partialcredit': strcons_fix(self.integerPartialCredit) + '%' } answer.find('precision').attrib = { 'type': strcons(self.precisionType), 'precision': strcons_fix(self.precision), 'partialcredit': strcons_fix(self.precisionPartialCredit) + '%', 'strict': strcons_fix(self.strictPrecision), 'showprecisionhint': strcons_fix(self.showPrecisionHint), } answer.find('precision/message').append( makeContentNode(self.precisionMessage)) return part
def makeContentNode(s): s = strcons(s) s = removeHTMLEscapes(s) s = '<span>' + s + '</span>' try: content = etree.fromstring('<content>' + s + '</content>') except etree.ParseError as e: sys.stderr.write('Bad content:\n' + s + '\n\n') raise e for a in content.findall('.//a'): a.attrib.setdefault('target', '_blank') return content
def makeContentNode(s): s=strcons(s) s=removeHTMLEscapes(s) s='<span>'+s+'</span>' try: content = etree.fromstring('<content>'+s+'</content>') except etree.ParseError as e: sys.stderr.write('Bad content:\n'+s+'\n\n') raise e for a in content.findall('.//a'): a.attrib.setdefault('target','_blank') return content
def toxml(self): restriction = makeTree([self.name,'message']) restriction.attrib = {'partialcredit': strcons_fix(self.partialCredit)+'%', 'showstrings': strcons_fix(self.showStrings)} if int(self.length)>=0: restriction.attrib['length'] = strcons_fix(self.length) for s in self.strings: string = etree.Element('string') string.text = strcons(s) restriction.append(string) restriction.find('message').append(makeContentNode(self.message)) return restriction
def toxml(self): part = Part.toxml(self) part.append( makeTree([ 'answer', ['correctanswer', ['math']], ['checking', ['range']] ])) answer = part.find('answer') answer.attrib = { 'checkvariablenames': strcons_fix(self.checkVariableNames), 'showPreview': strcons_fix(self.showPreview), } correctAnswer = answer.find('correctanswer') correctAnswer.attrib = { 'simplification': strcons(self.answerSimplification) } correctAnswer.find('math').text = strcons(self.answer) checking = answer.find('checking') checking.attrib = { 'type': strcons(self.checkingType), 'accuracy': strcons_fix(self.checkingAccuracy), 'failurerate': strcons_fix(self.failureRate) } checking.find('range').attrib = { 'start': strcons_fix(self.vsetRangeStart), 'end': strcons_fix(self.vsetRangeEnd), 'points': strcons_fix(self.vsetRangePoints) } answer.append(self.maxLength.toxml()) answer.append(self.minLength.toxml()) answer.append(self.mustHave.toxml()) answer.append(self.notAllowed.toxml()) answer.append(self.expectedVariableNames.toxml()) return part
def toxml(self): part = Part.toxml(self) appendMany(part,['choices','answers',['marking','matrix','maxmarks','minmarks','distractors']]) choices = part.find('choices') choices.attrib = { 'minimumexpected': strcons(self.minAnswers), 'maximumexpected': strcons(self.maxAnswers), 'displaycolumns': strcons(self.displayColumns), 'order': 'random' if self.shuffleChoices else 'fixed', 'displaytype': strcons(self.displayType) } for choice in self.choices: choices.append(makeTree(['choice',makeContentNode(choice)])) answers = part.find('answers') answers.attrib = {'order': 'random' if self.shuffleAnswers else 'fixed'} for answer in self.answers: answers.append(makeTree(['answer',makeContentNode(answer)])) marking = part.find('marking') marking.find('maxmarks').attrib = {'enabled': strcons(self.maxMarksEnabled), 'value': strcons(self.maxMarks)} marking.find('minmarks').attrib = {'enabled': strcons(self.minMarksEnabled), 'value': strcons(self.minMarks)} matrix = marking.find('matrix') if isinstance(self.matrix,str): matrix.attrib = {'def': strcons(self.matrix)} else: for i in range(len(self.matrix)): for j in range(len(self.matrix[i])): mark = etree.Element('mark',{ 'answerindex': strcons(j), 'choiceindex': strcons(i), 'value': strcons(self.matrix[i][j]) }) matrix.append(mark) distractors = marking.find('distractors') for i in range(len(self.distractors)): for j in range(len(self.distractors[i])): distractor = etree.Element('distractor',{ 'choiceindex': strcons(i), 'answerindex': strcons(j) }) distractor.append(makeContentNode(self.distractors[i][j])) distractors.append(distractor) return part
def toxml(self): event = makeTree(['event']) event.attrib = {'type': strcons(self.kind), 'action': strcons(self.action)} event.append(makeContentNode(self.message)) return event
def toxml(self): part = super(MultipleChoicePart,self).toxml() appendMany(part,['choices','answers','layout',['marking','matrix','maxmarks','minmarks','distractors','warning']]) part.attrib['showcellanswerstate'] = strcons_fix(self.showCellAnswerState) choices = part.find('choices') choices.attrib = { 'minimumexpected': strcons_fix(self.minAnswers), 'maximumexpected': strcons_fix(self.maxAnswers), 'displaycolumns': strcons_fix(self.displayColumns), 'shuffle': strcons_fix(self.shuffleChoices), 'displaytype': strcons(self.displayType), } if isinstance(self.choices,str): choices.attrib['def'] = strcons(self.choices) else: for choice in self.choices: choices.append(makeTree(['choice',makeContentNode(choice)])) answers = part.find('answers') answers.attrib = {'shuffle': strcons_fix(self.shuffleAnswers)} if isinstance(self.answers,str): answers.attrib['def'] = strcons(self.answers) else: for answer in self.answers: answers.append(makeTree(['answer',makeContentNode(answer)])) layout = part.find('layout') layout.attrib = { 'type': self.layoutType, 'expression': self.layoutExpression, } marking = part.find('marking') marking.find('maxmarks').attrib = {'enabled': strcons_fix(self.maxMarksEnabled), 'value': strcons_fix(self.maxMarks)} marking.find('minmarks').attrib = {'enabled': strcons_fix(self.minMarksEnabled), 'value': strcons_fix(self.minMarks)} matrix = marking.find('matrix') if isinstance(self.matrix,str): matrix.attrib = {'def': strcons(self.matrix)} else: for i in range(len(self.matrix)): for j in range(len(self.matrix[i])): mark = etree.Element('mark',{ 'answerindex': strcons_fix(j), 'choiceindex': strcons_fix(i), 'value': strcons_fix(self.matrix[i][j]) }) matrix.append(mark) distractors = marking.find('distractors') for i in range(len(self.distractors)): for j in range(len(self.distractors[i])): distractor = etree.Element('distractor',{ 'choiceindex': strcons_fix(i), 'answerindex': strcons_fix(j) }) distractor.append(makeContentNode(self.distractors[i][j])) distractors.append(distractor) warning = marking.find('warning') warning.attrib = {'type': self.warningType} return part
def toxml(self): variable = makeTree(['variable', ['value']]) variable.attrib = {'name': strcons(self.name)} variable.find('value').text = strcons(self.definition) return variable
def toxml(self): root = makeTree(['exam', ['settings', ['navigation'], ['timing'], ['feedback', ['intro'], ['feedbackmessages'], ], ['rulesets'] ], ['functions'], ['variables'], ['question_groups'], ]) root.attrib = { 'name': strcons(self.name), 'percentPass': strcons_fix(self.percentPass)+'%', } settings = root.find('settings') nav = settings.find('navigation') nav.attrib = { 'allowregen': strcons_fix(self.navigation['allowregen']), 'reverse': strcons_fix(self.navigation['reverse']), 'browse': strcons_fix(self.navigation['browse']), 'showfrontpage': strcons_fix(self.navigation['showfrontpage']), 'showresultspage': strcons_fix(self.navigation['showresultspage']), 'preventleave': strcons_fix(self.navigation['preventleave']), 'startpassword': strcons_fix(self.navigation['startpassword']) } nav.append(self.navigation['onleave'].toxml()) timing = settings.find('timing') timing.attrib = { 'duration': strcons_fix(self.duration), 'allowPause': strcons_fix(self.timing['allowPause']), } timing.append(self.timing['timeout'].toxml()) timing.append(self.timing['timedwarning'].toxml()) feedback = settings.find('feedback') feedback.attrib = { 'showactualmark': strcons_fix(self.showactualmark), 'showtotalmark': strcons_fix(self.showtotalmark), 'showanswerstate': strcons_fix(self.showanswerstate), 'allowrevealanswer': strcons_fix(self.allowrevealanswer), 'showstudentname': strcons_fix(self.showstudentname), } feedback.find('intro').append(makeContentNode(self.intro)) feedbackmessages = feedback.find('feedbackmessages') for fm in self.feedbackMessages: feedbackmessages.append(fm.toxml()) rules = settings.find('rulesets') for name in self.rulesets.keys(): st = etree.Element('set',{'name':name}) for rule in self.rulesets[name]: if isinstance(rule,str): st.append(etree.Element('include',{'name':rule})) else: st.append(rule.toxml()) rules.append(st) variables = root.find('variables') for variable in self.variables: variables.append(variable.toxml()) functions = root.find('functions') for function in self.functions: functions.append(function.toxml()) question_groups = root.find('question_groups') question_groups.attrib = { 'showQuestionGroupNames': strcons(self.showQuestionGroupNames), } for qg in self.question_groups: question_groups.append(qg.toxml()) return root
def toxml(self): feedbackmessage = makeTree(['feedbackmessage']) feedbackmessage.attrib = {'threshold': strcons(self.threshold)} feedbackmessage.append(makeContentNode(self.message)) return feedbackmessage
def toxml(self): part = Part.toxml(self) appendMany(part, [ 'choices', 'answers', 'layout', [ 'marking', 'matrix', 'maxmarks', 'minmarks', 'distractors', 'warning' ] ]) choices = part.find('choices') choices.attrib = { 'minimumexpected': strcons_fix(self.minAnswers), 'maximumexpected': strcons_fix(self.maxAnswers), 'displaycolumns': strcons_fix(self.displayColumns), 'order': strcons('random' if self.shuffleChoices else 'fixed'), 'displaytype': strcons(self.displayType) } if isinstance(self.choices, str): choices.attrib['def'] = strcons(self.choices) else: for choice in self.choices: choices.append(makeTree(['choice', makeContentNode(choice)])) answers = part.find('answers') answers.attrib = { 'order': 'random' if self.shuffleAnswers else 'fixed' } if isinstance(self.answers, str): answers.attrib['def'] = strcons(self.answers) else: for answer in self.answers: answers.append(makeTree(['answer', makeContentNode(answer)])) layout = part.find('layout') layout.attrib = { 'type': self.layoutType, 'expression': self.layoutExpression, } marking = part.find('marking') marking.find('maxmarks').attrib = { 'enabled': strcons_fix(self.maxMarksEnabled), 'value': strcons_fix(self.maxMarks) } marking.find('minmarks').attrib = { 'enabled': strcons_fix(self.minMarksEnabled), 'value': strcons_fix(self.minMarks) } matrix = marking.find('matrix') if isinstance(self.matrix, str): matrix.attrib = {'def': strcons(self.matrix)} else: for i in range(len(self.matrix)): for j in range(len(self.matrix[i])): mark = etree.Element( 'mark', { 'answerindex': strcons_fix(j), 'choiceindex': strcons_fix(i), 'value': strcons_fix(self.matrix[i][j]) }) matrix.append(mark) distractors = marking.find('distractors') for i in range(len(self.distractors)): for j in range(len(self.distractors[i])): distractor = etree.Element('distractor', { 'choiceindex': strcons_fix(i), 'answerindex': strcons_fix(j) }) distractor.append(makeContentNode(self.distractors[i][j])) distractors.append(distractor) warning = marking.find('warning') warning.attrib = {'type': self.warningType} return part
def toxml(self): root = makeTree([ 'exam', [ 'settings', ['navigation'], ['timing'], [ 'feedback', ['advice'], ['intro'], ['feedbackmessages'], ], ['rulesets'] ], ['functions'], ['variables'], ['question_groups'], ]) root.attrib = { 'name': strcons(self.name), 'percentPass': strcons_fix(self.percentPass) + '%', } settings = root.find('settings') nav = settings.find('navigation') nav.attrib = { 'allowregen': strcons_fix(self.navigation['allowregen']), 'reverse': strcons_fix(self.navigation['reverse']), 'browse': strcons_fix(self.navigation['browse']), 'showfrontpage': strcons_fix(self.navigation['showfrontpage']), 'showresultspage': strcons_fix(self.navigation['showresultspage']), 'preventleave': strcons_fix(self.navigation['preventleave']) } nav.append(self.navigation['onleave'].toxml()) timing = settings.find('timing') timing.attrib = { 'duration': strcons_fix(self.duration), 'allowPause': strcons_fix(self.timing['allowPause']), } timing.append(self.timing['timeout'].toxml()) timing.append(self.timing['timedwarning'].toxml()) feedback = settings.find('feedback') feedback.attrib = { 'showactualmark': strcons_fix(self.showactualmark), 'showtotalmark': strcons_fix(self.showtotalmark), 'showanswerstate': strcons_fix(self.showanswerstate), 'allowrevealanswer': strcons_fix(self.allowrevealanswer), 'showstudentname': strcons_fix(self.showstudentname), } feedback.find('advice').attrib = { 'type': strcons(self.adviceType), 'threshold': strcons_fix(self.adviceGlobalThreshold) } feedback.find('intro').append(makeContentNode(self.intro)) feedbackmessages = feedback.find('feedbackmessages') for fm in self.feedbackMessages: feedbackmessages.append(fm.toxml()) rules = settings.find('rulesets') for name in self.rulesets.keys(): st = etree.Element('set', {'name': name}) for rule in self.rulesets[name]: if isinstance(rule, str): st.append(etree.Element('include', {'name': rule})) else: st.append(rule.toxml()) rules.append(st) variables = root.find('variables') for variable in self.variables: variables.append(variable.toxml()) functions = root.find('functions') for function in self.functions: functions.append(function.toxml()) question_groups = root.find('question_groups') question_groups.attrib = { 'showQuestionGroupNames': strcons(self.showQuestionGroupNames), } for qg in self.question_groups: question_groups.append(qg.toxml()) return root
def toxml(self): root = makeTree(['exam', ['settings', ['navigation'], ['timing'], ['feedback', ['advice'] ], ['rulesets'] ], ['functions'], ['variables'], ['questions'] ]) root.attrib = { 'name': strcons(self.name), 'percentPass': strcons(self.percentPass)+'%', 'shuffleQuestions': strcons(self.shuffleQuestions), } settings = root.find('settings') nav = settings.find('navigation') nav.attrib = { 'allowregen': strcons(self.navigation['allowregen']), 'reverse': strcons(self.navigation['reverse']), 'browse': strcons(self.navigation['browse']), 'showfrontpage': strcons(self.navigation['showfrontpage']), 'preventleave': strcons(self.navigation['preventleave']) } nav.append(self.navigation['onleave'].toxml()) timing = settings.find('timing') timing.attrib = { 'duration': strcons(self.duration), 'allowPause': strcons(self.timing['allowPause']), } timing.append(self.timing['timeout'].toxml()) timing.append(self.timing['timedwarning'].toxml()) feedback = settings.find('feedback') feedback.attrib = { 'showactualmark': strcons(self.showactualmark), 'showtotalmark': strcons(self.showtotalmark), 'showanswerstate': strcons(self.showanswerstate), 'allowrevealanswer': strcons(self.allowrevealanswer) } feedback.find('advice').attrib = {'type': strcons(self.adviceType), 'threshold': strcons(self.adviceGlobalThreshold)} rules = settings.find('rulesets') for name in self.rulesets.keys(): st = etree.Element('set',{'name':name}) for rule in self.rulesets[name]: if isinstance(rule,str): st.append(etree.Element('include',{'name':rule})) else: st.append(rule.toxml()) rules.append(st) variables = root.find('variables') for variable in self.variables: variables.append(variable.toxml()) functions = root.find('functions') for function in self.functions: functions.append(function.toxml()) questions = root.find('questions') for q in self.questions: questions.append(q.toxml()) return root
def toxml(self): part = Part.toxml(self) part.append(makeTree(['answer', ['allowonlyintegeranswers'], ['precision','message'], ] )) answer = part.find('answer') answer.attrib = { 'checkingType': strcons(self.checkingType), 'inputstep': strcons(self.inputStep) } if self.checkingType == 'range': answer.attrib['minvalue'] = strcons(self.minvalue) answer.attrib['maxvalue'] = strcons(self.maxvalue) else: answer.attrib['answer'] = strcons(self.answer) answer.attrib['accuracy'] = strcons(self.checkingAccuracy) answer.find('allowonlyintegeranswers').attrib = {'value': strcons(self.integerAnswer), 'partialcredit': strcons(self.integerPartialCredit)+'%'} answer.find('precision').attrib = { 'type': strcons(self.precisionType), 'precision': strcons(self.precision), 'partialcredit': strcons(self.precisionPartialCredit)+'%', 'strict': strcons(self.strictPrecision) } answer.find('precision/message').append(makeContentNode(self.precisionMessage)) return part
def toxml(self): variable = makeTree(['variable',['value']]) variable.attrib = {'name': strcons(self.name)} variable.find('value').text = strcons(self.definition) return variable