Newer
Older

Jan Maximilian Michal
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import xml.etree.ElementTree as et
### static methods #############################################################
def simple_elemet(name, text=None, attrib={}):
if not text:
return et.Element(name, attrib=attrib)
node = et.Element(name, attrib=attrib)
node.text = text
return node
def qtimetadatafield(label, entry):
root = et.Element('qtimetadatafield')
root.append(simple_elemet('fieldlabel', text=label))
root.append(simple_elemet('fieldentry', text=entry))
return root
def material(content):
material = et.Element('material')
material.append(simple_elemet(
'mattext',
text=content,
attrib={'texttype': 'text/xhtml'}
))
return material
def response_label(content, count):
response_label = et.Element('response_label', attrib={'ident': str(count)})
response_label.append(material(content))
return response_label
def respcondition(points, count, correct=True):
root = et.Element('respcondition', attrib={'continue': 'Yes'})
conditionvar = et.Element('conditionvar')
varequal = simple_elemet(
'varequal',
text=str(count),
attrib={'respident': 'MCMR'}
)
if correct:
conditionvar.append(varequal)
else:
_not = et.Element('not')
_not.append(varequal)
conditionvar.append(_not)
root.append(conditionvar)
setvar = simple_elemet(
'setvar',
text=str(points),
attrib={'action': 'Add'}
)
root.append(setvar)
if correct:
displayfeedback = et.Element(
'displayfeedback',
attrib={'feedbacktype': 'Response',
'linkrefid': 'response_{}'.format(count)})
root.append(displayfeedback)
return root