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")