Ejemplo n.º 1
0
 def get(self, entity_id=None):
   """HTML GET handler.
   
   Check the query parameters for the ID of the monster to be displayed.
   If found, disply that monster using the standard template."""
   
   template_values = self.build_template_values()
   
   if entity_id:
     try:
       monster = Monster.get_by_id_safe(int(entity_id), template_values[handlers.base.PROFILE_KEY])
     except ValueError:
       return self.not_found()
     if not monster:
       self.not_found()
       return
     template_values['monster'] = monster
   else:
     self.redirect("/view/"+str(Monster.all().order("-creation_time").get().key().id()))
     return
   
   if handlers.base.PROFILE_KEY in template_values:
     template_values['vote'] = Vote.all().filter("monster = ", template_values['monster']).filter("voter = ", template_values[handlers.base.PROFILE_KEY]).get()
   
   template_values['edit_url'] = self.uri_for('monster.edit', entity_id=r'%s')
   template_values['delete_url'] = self.uri_for('monster.delete', entity_id=entity_id)
   template_values['profile_url'] = self.uri_for('profile', profile_id=monster.creator.key().id())
   
   template = configuration.site.jinja_environment.get_template('monster/view.html')
   self.response.write(template.render(template_values))
Ejemplo n.º 2
0
 def post(self, entity_id=None):
   """HTML POST handler. 
   
   Save changes to the given monster."""
   
   template_values = self.build_template_values()
   
   if entity_id:
     monster = Monster.get_by_id_safe(int(entity_id), template_values[handlers.base.PROFILE_KEY])
     if monster:
       user = users.get_current_user()
       if monster.creator.account == user:
         monster.name = self.request.get('name')
         monster.hp = self.request.get('hp')
         monster.armor = self.request.get('armor')
         monster.damage = self.request.get('damage')
         monster.instinct = self.request.get('instinct')
         monster.description = self.request.get('description')
         
         nextindex = 0
         monster.tags = []
         while self.request.get('tag-'+str(nextindex)):
           monster.tags.append(self.request.get('tag-'+str(nextindex)))
           nextindex += 1
         
         nextindex = 0
         monster.special_qualities = []
         while self.request.get('specialquality-'+str(nextindex)):
           monster.special_qualities.append(self.request.get('specialquality-'+str(nextindex)))
           nextindex += 1
         
         nextindex = 0
         monster.damage_tags = []
         while self.request.get('damagetag-'+str(nextindex)):
           monster.damage_tags.append(self.request.get('damagetag-'+str(nextindex)))
           nextindex += 1
           
         nextindex = 0
         monster.moves = []
         while self.request.get('move-'+str(nextindex)):
           monster.moves.append(self.request.get('move-'+str(nextindex)))
           nextindex += 1
         
         monster.edited = True
         monster.put()
         return self.redirect(self.uri_for("monster", entity_id=monster.key().id()))
       else:
         return self.forbidden()
     else:
       return self.not_found()
   else:
     return self.not_found()
     
   template = configuration.site.jinja_environment.get_template('monster/edit.html')
   self.response.write(template.render(template_values))
Ejemplo n.º 3
0
 def get(self, entity_id=None):
   """HTML GET handler.
   
   Check if the user has already voted. If they haven't, -1 the monster.
   Otherwise, error."""
   
   user = users.get_current_user()
   profile = Profile.all().filter("account = ", user).get()
   monster = Monster.get_by_id_safe(int(entity_id), profile)
   
   if (not monster) or (not profile):
     return self.forbidden()
     
   previous_vote = Vote.all().filter("voter = ", profile).filter("monster = ",monster).get()
   if previous_vote and previous_vote.is_up:
     previous_vote.is_up = False
     previous_vote.put()
     
     if monster.downs:
       monster.downs += 1
     else:
       monster.downs = 1
       
     if monster.ups:
       monster.ups -= 1
     else:
       monster.ups = 0
       
     monster.compute_score()
     monster.put()
   elif previous_vote:
     return self.response_set_status(500)
   else:
     vote = Vote()
     vote.voter = profile
     vote.monster = monster
     vote.is_up = False
     vote.put()
     
     if monster.downs:
       monster.downs += 1
     else:
       monster.downs = 1
     monster.compute_score()
     monster.put()
Ejemplo n.º 4
0
 def get(self, entity_id=None):
   """HTML GET handler.
   
   Check the query parameters for the ID of the monster to be displayed.
   If found, disply that monster using the standard template."""
   
   template_values = self.build_template_values()
   
   if entity_id:
     monster = Monster.get_by_id_safe(int(entity_id), template_values[handlers.base.PROFILE_KEY])
     if monster:
       if monster.creator.account == template_values[handlers.base.USER_KEY]:
         monster.delete()
       else:
         return self.forbidden()
     else:
       return self.not_found()
   else:
     return self.not_found()
   
   template = configuration.site.jinja_environment.get_template('monster/delete.html')
   self.response.write(template.render(template_values))