def get(self): #We are using a NoSQL DB so will be refraining fom writing GQL #query for all Question objects in DB user=users.get_current_user() query=Question.query() #fetch them questions=query.fetch() #Values we will be passing to the view (of MVC) vals={'current_user':user,'questions':questions} #get the page template suitable for this page template=jinjaEnv.get_template('performance.html') #render the values into the template and put it in the output stream of the RequestHandler self.response.out.write(template.render(vals))
def get(self): for x in range(0, 110): user=users.get_current_user() q=Question() #get the key of the question q.question='Question Number %d ?'%(x+1) #initialize a, b, c #q.a an important parameter #q.a=1.0 Rasch Case q.a=randint(50,200)/100.0 # this is real case, should be properly estimated q.b=(x+1)/10.0 q.c=0.25 if user: #create/find out the User class q.poster=user else: self.redirect(users.create_login_url(self.request.uri)) putQ=None try: putQ=q.put() self.response.out.write("S") except TransactionFailedError: self.response.out.write("F") ans=[] #currentAnswer can also be randomised atm, its always the first one #currentAnswer=randint(0,3) currentAnswer=0 for i in range(4): #four answers at present a=Answer() #get the numbered variable which hold the flag of it being correct a.answer='Option %d-%d'%(x+1,i+1) if i==currentAnswer: #check for correctness, set by true a.correct=True else: a.correct=False a.question=putQ ans.append(a) try: putQ=q.put() for i in range(4): ans[i].put() self.response.out.write("S") except TransactionFailedError: self.response.out.write("F") #temp test for score :P #user=users.get_current_user() #DisplayResultPg85(self,getThetaResult(user))
def post(self): user=users.get_current_user() q=Question() #get the key of the question q.question=self.request.get('q') #initialize a, b, c q.b=0.0 q.a=1.0 q.c=0.25 if user: #create/find out the User class q.poster=user else: self.redirect(users.create_login_url(self.request.uri)) putQ=None try: putQ=q.put() except TransactionFailedError: self.response.out.write("F") return ans=[] for i in range(4): #four answers at present a=Answer() #get the numbered variable which hold the flag of it being correct a.answer=self.request.get('a'+str(i+1)) checked=self.request.get('c'+str(i+1)) if checked=="true": #check for correctness, set by true a.correct=True else: a.correct=False a.question=putQ ans.append(a) try: for i in range(4): ans[i].put() self.response.out.write("S") except TransactionFailedError: self.response.out.write("F")
def addTasks(self): all_questions=Question.query().fetch() for question in all_questions: taskqueue.add(queue_name='estimatorQueue',url='/estim/admin/tasks/calculateparams',params={'qid':str(question.key.id())})