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
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
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
def taketest(self, id): logging.info("AA: entering soluto.taketest") test = DBSession.query(Test).filter(Test.id == id).first() open_tests = Test.open_tests_for(MCUser.current()) closed_tests = Test.closed_tests_for(MCUser.current()) count_open_tests = len(open_tests) count_closed_tests = len(closed_tests) test_id = test.id questions = test.questions; title = test.title questions = test.questions question_count = 0 for q in questions: question_count = question_count + 1 # now let's put together the dict used for rendering the test page pg = {'page':'index'} pg['test_title'] = title pg['test_description'] = test.description pg['question_count'] = question_count count = 0 # get a list of tests that are open and closed pg['done_tests'] = count_closed_tests pg['open_tests'] = count_open_tests # insert the test id pg['test_id'] = str(test_id) pg['question_urls'] = {} for q in questions: count = count+1 #txt = "question" + count pg['question_urls'][q.id] = str(q.url) return pg
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def by_email_address(cls, email): """Return the user object whose email address is ``email``.""" return DBSession.query(cls).filter_by(email_address=email).first()
def test_query_obj(self): """Model objects can be queried""" obj = DBSession.query(self.klass).one() for key, value in self.attrs.iteritems(): assert_equals(getattr(obj, key), value)
def tearDown(self): """Finish model test fixture.""" DBSession.rollback()
def test(self, title, id): test = DBSession.query(Test).filter(Test.id == id).first() return self._test_to_dict(test)