def from_xml(self):
		import knstdoc
		doc = knstdoc.parseString(self.xml)
		assert doc.is_normal(), "Stored XML for knst is not normal"
		questions = []
		for pg in doc.pages:
			for qt in pg.questions:
				answers = []
				for an in qt.answers:
					answers.append(dict(text=an.content,value=an.value,label=an.label))
				questions.append(dict(text=qt.content,
					 				  answers=answers))
		return questions
Exemple #2
0
 def from_xml(self):
     import knstdoc
     doc = knstdoc.parseString(self.xml)
     assert doc.is_normal(), "Stored XML for knst is not normal"
     questions = []
     for pg in doc.pages:
         for qt in pg.questions:
             answers = []
             for an in qt.answers:
                 answers.append(
                     dict(text=an.content, value=an.value, label=an.label))
             questions.append(dict(text=qt.content, answers=answers))
     return questions
	def change_values(self,newvalues):
		import knstdoc, utils, StringIO
		w = utils.Writer(StringIO.StringIO())
		doc = knstdoc.parseString(self.xml)
		for pg in doc.pages:
			for qt in pg.questions:
				for an in qt.answers:
					label = int(an.label)
					new = newvalues.get(label,None)
					an.setValue(new)
		doc.toxml(w)
		xml_data = w().getvalue()
		self.xml = unicode(xml_data,'utf8')
Exemple #4
0
 def change_values(self, newvalues):
     import knstdoc, utils, StringIO
     w = utils.Writer(StringIO.StringIO())
     doc = knstdoc.parseString(self.xml)
     for pg in doc.pages:
         for qt in pg.questions:
             for an in qt.answers:
                 label = int(an.label)
                 new = newvalues.get(label, None)
                 an.setValue(new)
     doc.toxml(w)
     xml_data = w().getvalue()
     self.xml = unicode(xml_data, 'utf8')