Exemplo n.º 1
0
 def get(self):
     type = self.request.get("type")
     if (type not in TYPES):
         self.error(400)
         return
     fetch = int(self.request.get("fetch"))
     offset = int(self.request.get("offset"))
     rankings = Ranking.all().order('-created').fetch(limit=fetch, offset=offset)
     response = []
     for ranking in rankings:
         response_rank = {}
         response_rank["type"] = type
         response_rank["user"] = ranking.user.name
         response_rank["created"] = ranking.created.strftime("%Y-%m-%d %H:%M:%S")
         response_rank["id"] = ranking.get_id()
         response_rank["title"] = ranking.title
         response_rank["description"] = ranking.description
         response_rank["likes"] = ranking.number_of_likes
         response_rank["votes"] = ranking.number_of_votes
         response_rank["rank_items"] = []
         items = ranking.get_items()
         for (i, item) in enumerate(items):
             response_item = {}
             response_item["id"] = item.get_id()
             response_item["type"] = type
             response_item["title"] = item.name
             response_item["score"] = i
             if type == "full":
                 response_item["content"] = item.content
             response_rank["rank_items"].append(response_item)
                 
         response.append(response_rank)
     self.write(response)
     
Exemplo n.º 2
0
 def render_main_page(self):
     user = self.get_current_user()
     rankings = Ranking.all().order('-created').fetch(limit=100, offset=0)
     self.render("main.html", current_user=user, user=user, rankings=rankings)