コード例 #1
0
ファイル: profile.py プロジェクト: Sagelt/dungeon-world-codex
 def get(self, profile_id=None):
   """HTML GET handler.
   
   Check the query parameters for the ID of the profile to be displayed.
   If found, display the user. Otherwise display current user"""
   
   template_values = self.build_template_values()
   
   if profile_id and template_values[handlers.base.PROFILE_KEY] and int(profile_id) == template_values[handlers.base.PROFILE_KEY].key().id():
     template_values['viewed_profile'] = template_values[handlers.base.PROFILE_KEY]
   elif profile_id:
     template_values['viewed_profile'] = Profile.get_by_id(int(profile_id))
   elif template_values[handlers.base.PROFILE_KEY]:
     return self.redirect(self.uri_for("profile", profile_id=template_values[handlers.base.PROFILE_KEY].key().id()))
   else:
     return self.forbidden()
   
   favorites = Vote.all().filter("voter = ", template_values['viewed_profile']).filter("is_up = ", True).fetch(1)
   if favorites:
     template_values['recent_up_monster'] = favorites[0].monster
     
   created =   Monster.get_recent(1, creator=template_values['viewed_profile'], user=template_values[handlers.base.PROFILE_KEY])
   if created:
     template_values['recent_monster'] = created[0]
   template = configuration.site.jinja_environment.get_template('profile/view.html')
   return self.response.write(template.render(template_values))
コード例 #2
0
ファイル: monster.py プロジェクト: Sagelt/dungeon-world-codex
 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))
コード例 #3
0
ファイル: monster.py プロジェクト: Sagelt/dungeon-world-codex
 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()