Пример #1
0
 def get(self):
   current_game = db.get(self.request.get("gameKey"))
   scores = {}
   for thing in ThingToDo.all().filter("game = ", current_game):
     # App Engine question:
     # I use GQL sometimes and .filter() etc sometimes.  They're both
     # pretty intuitive to me.  Is either way faster or otherwise preferred?
     allVotes = Vote.gql("WHERE thingToDo = :1", thing)
     scores[thing] = 0
     for vote in allVotes.fetch(limit = 1000): # 1000 is the max limit.
     # App Engine question:
     # is there any way to say "give me everything in the data store, I don't
     # care how long it takes?"  The 1000 limit scares me; what if 1001 people
     # are voting on the same thing?  This will just miss 1 vote, silently.
       scores[thing] += vote.score
   self.response.out.write("Here are the totals:")
   for (thing, score) in scores.items():
     self.response.out.write("<br/>" + thing.name + " - " + str(score))
Пример #2
0
 def get(self):
   # HTML question: ugh, to save any state I have to pass the gameKey around.
   # I guess that's the nature of HTTP, though, right?
   # App Engine question: could I set a cookie instead?
   # App Engine question, part 2: devious Alice could easily hack into Bob's
   # voting game if she knew his game key.  Game keys are easy to guess.
   # How can I maintain state without relying on this brittle game key?
   # (also, a long alphanumeric nonsense string in the URL is ugly.)
   current_game = db.get(self.request.get('gameKey'))
   template_values = {
     "user": users.get_current_user(),
     "game": current_game,
     "thingsToDo": ThingToDo.all().filter("game = ", current_game),
     "message": self.request.get('message'),
     "voteValues": [1,2,3,4,5],
   }
   # boilerplate:
   path = os.path.join(os.path.dirname(__file__), 'index.html')
   self.response.out.write(template.render(path, template_values))
Пример #3
0
 def post(self):
   # make a new ThingToDo that points to the game that it's in
   thing = ThingToDo(name = self.request.get('thingName'),
     game = db.get(self.request.get('gameKey')))
   thing.put()
   self.redirect("/main?gameKey=" + str(self.request.get('gameKey')))