def addRelevanceVote(self, parentRootURLsafe, childRootURLsafe, linkType, vote): parentRootKey = ndb.Key(urlsafe=parentRootURLsafe) childRootKey = ndb.Key(urlsafe=childRootURLsafe) pointRoot = parentRootKey.get() curPoint = pointRoot.current.get() oldRelVote = RelevanceVote.query( RelevanceVote.parentPointRootKey == parentRootKey, RelevanceVote.childPointRootKey == childRootKey, RelevanceVote.linkType == linkType, ancestor=self.key).get() newRelVote = RelevanceVote( parent=self.key, parentPointRootKey = parentRootKey, childPointRootKey = childRootKey, value = vote, linkType=linkType) return self.transactionalAddRelevanceVote( curPoint, oldRelVote, newRelVote)
def getRelevanceVotes_async(self, parentPoint): parentRootKey = parentPoint.key.parent(); maxNumVotes = parentPoint.numSupporting + parentPoint.numCounter; rVotes = None if maxNumVotes > 0: # MULTIPLY numVotes * 2 because the current set of points may be smaller # than the set for a given version rVotes = yield RelevanceVote.query( RelevanceVote.parentPointRootKey == parentRootKey, ancestor = self.key).fetch_async(maxNumVotes*2) raise ndb.Return(rVotes)