def post(self): user = self.getuser() if user is not None: jirgaId = self.request.get('jirgaId') print(self.request) questionString = self.request.get('question') print(jirgaId) jirga = Jirga.all().filter('jirgaId', jirgaId).get() votes = [] for x in range(1,6): curr = self.request.get("vote"+str(x)) if curr is not None and curr != "": vote = Vote(answer=curr,number=x,count=0) print vote.answer vote.put() votes.append(vote.key()) if jirga is not None: if questionString != "" and questionString is not None and votes.count > 1: if jirga.publicJirga == 1 or jirga.owner == user.username: i = uuid.uuid1() question = Question(questionString=questionString, author=user.username,qId=(str(i)),votes=votes) question.put() jirga.questions.append(question.key()) jirga.put() time.sleep(.5) self.redirect("/viewQuestion/"+question.qId) else: self.response.write("FAIL - insufficient permissions") else: self.response.write("FAIL - invalid question - " + questionString) else: self.response.write("FAIL - invalid jirga") else: self.response.write("FAIL - not logged in")
def test_new_question(self): answer = ['help','me'] answer.append('please') question2 = Question() question2.questionDescr ='testing_question' question2.questionType ='MCQ' question2.questionParts = answer question2.answerList = answer question2.answerList = answer question2.userId = '*****@*****.**' question2.ansPos = answer question2.put() question1 = Question.newQuestion(Question(key_name='help'),'test','MCQ',answer,answer,'*****@*****.**',answer)
def post(self): user = self.getuser() if user is not None: jirgaId = self.request.get('jirgaId') questionId = self.request.get('questionId') answerString = self.request.get('answerString') jirga = Jirga.all().filter('jirgaId', jirgaId).get() question = Question.all().filter('qId',questionId).get() relNum = self.request.get('relNum') if jirga is not None and question is not None: if answerString != "" and answerString is not None: if question.author == user.username: vote = Vote(answer=answerString,number=len(question.votes)+1+int(relNum),) vote.put() print("vote: " + answerString) question.votes.append(vote.key()) question.put() self.response.write("OK") else: self.response.write("FAIL") else: self.response.write("FAIL") else: self.response.write("FAIL") else: self.response.write("FAIL - not logged in")
def get(self): try: #email,gem,move,fuel,cargo,food deyang = Player.newPlayer(Player(key_name='deyang'),'deyang',10,10,10,40,20,0,0) kelvin = Player.newPlayer(Player(key_name='kelvin'),'kelvin',20,10,20,50,70,0,0) siewlin = Player.newPlayer(Player(key_name='siewlin'),'siewlin',30,10,30,20,50,0,0) brian = Player.newPlayer(Player(key_name='brian'),'brian',40,10,40,50,60,0,0) deyang.put() kelvin.put() siewlin.put() brian.put() trade = TradeRequest.newTradeRequest(TradeRequest(key_name='*****@*****.**'),'*****@*****.**','*****@*****.**',10,10,20,'onging') trade.put() trade2 = TradeRequest.newTradeRequest(TradeRequest(key_name='*****@*****.**'),'*****@*****.**','*****@*****.**',10,10,20,'onging') trade2.put() trade3 = TradeRequest.newTradeRequest(TradeRequest(key_name='*****@*****.**'),'*****@*****.**','*****@*****.**',10,10,20,'onging') trade3.put() trade4 = TradeRequest.newTradeRequest(TradeRequest(key_name='*****@*****.**'),'*****@*****.**','*****@*****.**',10,10,20,'onging') trade4.put() answer = ['help3','me'] answer.append('please') question1 = Question.newQuestion(Question(key_name='help'),'test','MCQ',answer,answer,'*****@*****.**',answer) question1.put() self.response.out.write('Successful in creating Player Object & trade Object & question Object') except: self.response.out.write()
def post(self): user = self.getuser() if user is not None: jirgaId = self.request.get('jirgaId') questionId = self.request.get('questionId') answerString = self.request.get('answerString') jirga = Jirga.all().filter('jirgaId', jirgaId).get() question = Question.all().filter('qId', questionId).get() relNum = self.request.get('relNum') if jirga is not None and question is not None: if answerString != "" and answerString is not None: if question.author == user.username: vote = Vote( answer=answerString, number=len(question.votes) + 1 + int(relNum), ) vote.put() print("vote: " + answerString) question.votes.append(vote.key()) question.put() self.response.write("OK") else: self.response.write("FAIL") else: self.response.write("FAIL") else: self.response.write("FAIL") else: self.response.write("FAIL - not logged in")
def get(self, qId): user = self.getuser() if (user is not None): question = Question.all().filter('qId', qId).get() votes = Vote.get(question.votes) template_params = {'question': question, 'votes': votes} render_template(self, "viewResults.html", template_params) else: self.response.write("FAIL - you need to be logged in for this")
def getQuestionsFromDB(): questions = Questions.query.distinct() resQuestions = [] for q in questions: resQuestions.append( Question(idQuestion=q.idQuestion, textQuestion=q.textQuestion, textQuestionIta=q.textQuestionIta)) return resQuestions
def get(self, qId): user = self.getuser() if(user is not None): question = Question.all().filter('qId',qId).get() votes = Vote.get(question.votes) template_params = { 'question':question, 'votes':votes } render_template(self,"viewResults.html",template_params) else: self.response.write("FAIL - you need to be logged in for this")
def initQuestionSet(): questions = [] questionSet = [ "あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ" ] answerSet = [ "a", "i", "u", "e", "o", "ka", "ki", "ku", "ke", "ko", "sa", "si", "su", "se", "so" ] for index in range(len(questionSet)): elemnet = Question() elemnet.setQuestion(questionSet[index]) elemnet.setAnswer(answerSet[index]) questions.append(elemnet) return questions # if __name__ == '__main__': # list = initQuestionSet() # target = random.choice(list) # print( "請告訴我『 " + target.getQuestion() +" 』的讀音") # userAnswer = input("請輸入答案:") # # if userAnswer == target.getAnswer() : # print("答對了") # else: # print("答錯了")
def get(self,jirgaId,questionId): loggedIn= False user = self.getuser() if(user is not None): question = Question.all().filter('qId', questionId).get() jirga = Jirga.all().filter('jirgaId', jirgaId).get() votes = Vote.get(question.votes) template_params = { 'question': question, 'votes': votes, 'user':user, 'jirga':jirga } render_template(self,"viewQuestion.html",template_params) else: self.response.write("FAIL - you need to be logged in for this")
def get(self, jirgaId, questionId): loggedIn = False user = self.getuser() if (user is not None): question = Question.all().filter('qId', questionId).get() jirga = Jirga.all().filter('jirgaId', jirgaId).get() votes = Vote.get(question.votes) template_params = { 'question': question, 'votes': votes, 'user': user, 'jirga': jirga } render_template(self, "viewQuestion.html", template_params) else: self.response.write("FAIL - you need to be logged in for this")
def post(self): trial = json.loads(self.request.body) qn = Question() qn.questionDescr = trial['descr'] qn.questionType = trial['questionType'] questionParts = trial['qnParts'] answerLong = trial['answer'] qnPartsLong = trial['qnParts'] ansPosLong = trial['ansPos'] answer = [] qnParts = [] ansPos = [] for x in answerLong: number = x['num'] answer.append(str(number)) ans = x['ans'] answer.append(str(ans)) qn.answerList = answer for x in qnPartsLong: number = x['num'] qnParts.append(str(number)) qnss = x['qn'] qnParts.append(str(qnss)) qn.questionParts = qnParts for x in ansPosLong: number = x['num'] ansPos.append(str(number)) dir = x['dir'] ansPos.append(str(dir)) posR = x['posR'] ansPos.append(str(posR)) posC = x['posC'] ansPos.append(str(posC)) qn.ansPos = ansPos user = users.get_current_user() qn.userId = user.email() qn.put() self.response.out.write("Success")
def post(self): user = self.getuser() if(user is not None): questionKey = self.request.get('questionKey') jirgaKey = self.request.get('jirgaId') question = Question.all().filter('qId',questionKey).get() jirga = Jirga.all().filter('jirgaId',jirgaKey).get() voteNum = int(self.request.get('voteselect')) if question is not None and jirga is not None and user.key not in question.voted and user.key() in jirga.members: for v in question.votes: vc = Vote.get(v) print(vc.number) if vc.number == voteNum: vc.users.append(user.key()) vc.count += 1 vc.put() question.voted.append(user.key()) question.put() self.redirect("/viewResults/"+question.qId) else: self.response.write("FAIL - not logged in")
def get(self): user = self.getuser() if(user is not None): jirgas = Jirga.all() newlist=[] pubJirgas = [] lanks = [] questions = [] for jirga in jirgas: if jirga is not None and (user.key() in jirga.members or jirga.owner == user.username): newlist.append(jirga) for qkey in jirga.questions: question = Question.get(qkey) if question is not None and user.key not in question.voted: question.lank=(str(jirga.jirgaId) +"/" +str(question.qId)) questions.append(question) elif jirga is not None and jirga.publicJirga==1: pubJirgas.append(jirga) #check to avoid throwing unbounderror when no jirgas #todo - make this give a warning when no jirgas if len(newlist) < 1: template_params = { 'jirgasmem':newlist, 'jirgaspub':pubJirgas, 'questions':questions } else: template_params = { 'questions':questions, #throws exception when goodQuestions not initialized (due to no Jirgas) 'jirgasmem':jirgas, 'jirgaspub':pubJirgas } render_template(self,"home.html",template_params) else: self.redirect("/login")
def get(self): user = self.getuser() if(user is not None): jirgas = Jirga.get(user.jirgas) result = {} self.response.headers['Content-Type'] = 'application/json' for jirga in jirgas: obj2 = { 'name': jirga.title, 'key': jirga.jirgaId, } questions = Question.get(jirga.questions) for question in questions: if user.key not in question.voted: obj3 = { 'key':question.key(), 'title':question.questionString, 'author':question.author } votes = Vote.get(question.votes) for vote in votes: if vote is not None: obj4 = { 'vote':vote.number, 'answer':vote.answer, 'count':vote.count } obj3.update(obj4) obj2.update(obj3) result.update(obj2) #else: #user has already voted skip this question self.response.out.write(json.dumps(result)) else: self.response.write("FAIL - not logged in")
def test_saved_entity(self): entity = Question(email='*****@*****.**') key = entity.put() self.assertEqual(None, db.get(key).userId)
from data.data import ALL_QUESTIONS from functions.ask import ask, countHowManyCorrect from model.Terminal import Terminal """ CREATE - Questions and Answers Description: - One question may have any number of: - incorrect answers - correct answers - One answer may be reused to be included in: - any number of questions - So there is a many to many relation """ # Questions question_howManyDaysInYear = Question.insertQuestion( "How many days are in a year?") question_howManyDaysInWeek = Question.insertQuestion( "How many days are in a week?") # Answers answer_300 = Answer.insertAnswer("300") answer_400 = Answer.insertAnswer("400") answer_365 = Answer.insertAnswer("365") answer_7 = Answer.insertAnswer("7") answer_100 = Answer.insertAnswer("100") answer_not8 = Answer.insertAnswer("Not 8") answer_seven = Answer.insertAnswer("Seven") # QA for question_howManyDaysInYear QA.insertQA(question_howManyDaysInYear, answer_300, False) QA.insertQA(question_howManyDaysInYear, answer_400, False)
def setUp(self): # Populate test entities. entity = Question(email='*****@*****.**') self.setup_key = entity.put()