Ejemplo n.º 1
0
    def schoolData(self):

        # get all comments
        comments = Comments.gql("WHERE school_id = :1 AND visible = True", self.school.school_id)
        commentsList = []

        if comments:
            for c in comments:
                comment = {
                    "id": c.key().id(),
                    "text": c.text,
                    "reports": c.reports,
                    "user": {"name": c.user.name, "gender": c.user.gender},
                    "upvote": memcache.get("CommentUpvote.%i" % c.key().id()),
                    "downvote": memcache.get("CommentDownvote.%i" % c.key().id()),
                }
                commentsList.append(comment)

        upvote = memcache.get("SchoolUpvote." + self.school.school_id)
        downvote = memcache.get("SchoolDownvote." + self.school.school_id)

        if upvote == None:
            upvote = self.school.upvote
            memcache.add("SchoolUpvote." + self.school.school_id, upvote)

        if downvote == None:
            downvote = self.school.downvote
            memcache.add("SchoolDownvote." + self.school.school_id, downvote)

        schoolData = {"comments": commentsList, "upvote": upvote, "downvote": downvote}

        return schoolData