Ejemplo n.º 1
0
    def show(self, http_handler, param, form=None):
	storage = http_handler.sessionData('storage')

	if storage == None:
	    self.register(http_handler, param, form)
	else:
	    session = http_handler.session()
	
	    question = self.currentQuestion(session, storage)

	    hint_field = ""

	    if form != None and question:
		if not form.has_key('hint'):
		    storage.populateAnswers(form)
		    question.applyAnswers(storage.answer)
		    storage.saveResult()

		    if question.getPoints() != 0:
			question = self.nextQuestion(session, storage)
		    else:
			hint_field = '<input type="hidden" name="hint" value="1">'
		else:
		    question = self.nextQuestion(session, storage)

	    template = Template('base.html')
	    template.setTemplate('INFO_BLOCK', 'test_info.html')
	    template.setData('TEST_TITLE', storage.test.caption)
	    if question:
		template.setTemplate('CONTENT', 'test_screen.html')

		template.setData('CURRENT', u'%i'%(session.get('curr_question', 0)+1) )
		template.setData('TOTTAL', u'%i'%(len(storage.test.questions)) )

		template.setData('QUESTION', question.serializeForHtml()+hint_field)
		if hint_field:
		    template.setData('ERROR', u'Ошибка')
		    template.setData('NEXT', u'Далее')
		else:
		    template.setData('NEXT', u'Ответить')
	    else:
		storage.test.setComplete()
		template.setTemplate('CONTENT', 'test_screen_end.html')
		template.setData('RESULT', str(storage.test.getPoints()))
		http_handler.dropSession()

	    self.answer(http_handler, template.show())
Ejemplo n.º 2
0
    def show(self, http_handler, param, form=None):
	storage = http_handler.sessionData('storage')
	if storage == None:
	    self.register(http_handler, param, form)
	else:
	    template = Template('base.html')
	    template.setTemplate('INFO_BLOCK', 'test_info.html')
	    template.setData('TEST_TITLE', storage.test.caption)

	    if form != None:
		storage.populateAnswers(form)
		storage.test.applyAnswers(storage.answer)
		storage.test.setComplete()
		storage.saveResult()
	        template.setTemplate('CONTENT', 'test_list_end.html')
		template.setData('RESULT', u"%i"%storage.test.getPoints())
		http_handler.dropSession()
	    else:
	        template.setTemplate('CONTENT', 'test_list.html')

	    template.setData('TEST', storage.test.serializeForHtml(show_hint=False))
	    self.answer(http_handler, template.show())