def post(self): poll = Question() poll.name = self.request.get('question') poll.voteCount = 0 options = self.request.get_all('option') width = 0 for o in options: tmpWidth = imagegen.width(o) if tmpWidth > width: width = tmpWidth poll.textWidth = width poll.put() for o in options: option = Option(parent=poll.key()) option.name = o option.voteCount = 0 option.colour = random.randrange(0,255) option.image = db.Blob(imagegen.create(width, option.colour, o, 0)) option.put() self.redirect('/')
def get(self): """pass me the db id of the question then option""" q_id = self.request.get('q') option_id = self.request.get('v') q = Question.get_by_id(int(q_id)) option = Option.get_by_id(int(option_id), q) vote = Vote(parent=option) vote.put() option.voteCount += 1 option.put() q.voteCount += 1 """Update graph(s)""" width = q.textWidth questionCount = float(q.voteCount) q.put() option_query = db.GqlQuery("SELECT * " "FROM Option " "WHERE ANCESTOR IS :1 " "LIMIT 20", q.key()) option_query.run() for o in option_query: colour = o.colour text = o.name optionCount = float(o.voteCount) ratio = int((optionCount / questionCount)*100) o.image = db.Blob(imagegen.create(width, colour, text, ratio)) o.put() """Save to the datastore!""" q.put() """Display a page for that poll if from this host, else send back""" self.redirect('/')