Пример #1
0
 def index(self, email):
     """Handle the 'about' page."""
     #logging.info("AA: entering subscribe index with %s", email)
     em = MCSubscribe(sub_email = email)
     DBSession.add(em)
     data = {'email':email}
     return data
Пример #2
0
	def question(self, tid, qid_next, qid_curr, answer):
		s = "AA: soluto/question, qid=" + qid_next + ", tid = " + tid + ",answer: " + answer
		logging.info(s)

		user = MCUser.current()		
		test = DBSession.query(Test).filter(Test.id == tid).first()

		# let's find the question which prompted us to come here
		## this is weird and odd way of doing things.
		## TODO - fix
		## I am sure there is a better way of finding the first element of an
		## instrumentedlist (questions)
		questions = test.questions
                first = 1
		for q in questions:
			if first == 1:
				question = q
				first = 0
			if str(q.id) == qid_next:
				question = q
				break
		
		#first thing is to save the answer is one was provided
		if answer != "":
			user_answer = UserAnswer()
			user_answer.answer = answer
			user_answer.user_id = user.user_id
			user_answer.question_id = question.id
			# lets save the answer
			DBSession.add(user_answer)

		# add some information to the page
		pg = {'page':'index'}
		pg['tid'] = tid

		pg['q_description'] = question.description
		pg['q_question'] = question.question
		pg['q_curr'] = str(question.id)
		pg['q_next'] = str(question.id + 1)

		# now if the related question was specified
		# we have to find the answer the user gave there

		pg['q_related_answer'] = ''
		relatedanswerlist = DBSession.query(UserAnswer).filter(UserAnswer.question_id == 
								       question.relatedquestion_id)
		for r in relatedanswerlist:
			if r.user_id == user.user_id:
				pg['q_related_answer'] = r.answer
				raise RuntimeError()

		return pg
Пример #3
0
 def setUp(self):
     """Prepare model test fixture."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise