Пример #1
0
    def show(self, http_handler, param, form=None):
	param_count = len(param)
	if param_count == 1:
	    if form:
		#Add new test
		test_name = form['new_test_name'].value.decode("utf-8")
		test = Test(test_name)
		tid = http_handler.testSet.addTest(test)

		self.redirect(http_handler, '/edit/'+tid)
	    else:
		#Show list of all available test
		template = Template('base.html')
		template.setTemplate('CONTENT', 'edit.html')
		template.setTemplate('INFO_BLOCK', 'admin_menue.html')
		template.setData('TEST_LIST', http_handler.testSet.htmlLinkList())

		self.answer(http_handler, template.show())

	elif param_count == 3 and param[1]=='del':
	    http_handler.testSet.delTest(param[2])
	    self.redirect(http_handler, '/edit/')

	elif param_count == 2:
	    if form:
		try:
		    qcount = int(form['qcount'].value)
		except:
		    qcount = 0

		#Save modifications for test
		test = Test(form['caption'].value.decode("utf-8"))

		for i in xrange(qcount):
		    if form.has_key('q%i'%i):
			try:
			    points = int(form['p%i'%i].value)
			except:
			    points = 1
			
			if form.has_key('h%i'%i):
			    qhint = form['h%i'%i].value.decode("utf-8")
			else:
			    qhint = ""
			
			question = Question(form['q%i'%i].value.decode("utf-8"), qhint, points)
			try:
			    acount = int(form['acount%i'%i].value)
			except:
			    acount = 0

			for a in xrange(acount):
			    akey = 'a%i_%i'%(i, a)
			    if form.has_key(akey):
				if form.has_key('r%i_%i'%(i, a)):
				    question.addRight(form[akey].value.decode("utf-8"))
				else:
				    question.addWrong(form[akey].value.decode("utf-8"))

			test.addQuestion(question)

		http_handler.testSet.replaceTest(test, param[1])
		self.answer(http_handler, '<ok/>', context_type="text/xml")
	    else:
		template = Template('base.html')
		template.setTemplate('CONTENT', 'edit_test_item.html')
		template.setTemplate('INFO_BLOCK', 'admin_menue.html')
		template.setData('TEST_NAME', param[1])
		self.answer(http_handler, template.show())