def log(self, question, r): logging.info('Updating datastore with question.') # Insert question into datastore response = json.loads(r.content) answers = response['question']['answers'] answer = answers[0]['text'] if len(answers) > 0 else 'No answer given' phone_number = int(self.request.get('p', '0')) q = Question(phone_number=phone_number, question=question, response=response, answer=answer) q.put() # Update user stats # This isn't atomic, I don't think it's a big deal though. user = Stats.query(Stats.phone_number == phone_number).fetch() if len(user) > 0: user = user[0] else: user = Stats(phone_number=phone_number, number_of_questions=0, most_recent_question=datetime.min) user.number_of_questions += 1 user.most_recent_question = q.time user.put()
def add_question(qtype, qtext, hint, img, handler): question = Question() cookies = h.get_default_cookies(handler) current_user = h.get_current_user(cookies) if current_user: question.user = current_user question.qtype = int(qtype) question.qtext = qtext question.hint = hint question.img = img question.status = 1 question.put() return question