def get(self): user = self.current_user linkType = 'supporting' p1, pRoot1 = Point.getCurrentByUrl('CCC') p2, pRoot2 = Point.getCurrentByUrl('bbb') #result, newRelevance, newVoteCount = \ # user.addRelevanceVote(pRoot1.key.urlsafe(), pRoot2.key.urlsafe(), linkType, 50) """newRelVote = RelevanceVote( parent=user.key, parentPointRootKey = pRoot1.key, childPointRootKey = pRoot2.key, value = 50, linkType=linkType) newRelVote.put()""" # GET THE VOTE BACK q = RelevanceVote.query(RelevanceVote.parentPointRootKey == pRoot1.key, RelevanceVote.childPointRootKey == pRoot2.key, RelevanceVote.linkType == linkType) votes = q.fetch(20) message = "" message = 'Got %d votes on retrieval.' % len(votes) template_values = { 'user': user, 'message': message, 'currentArea':self.session.get('currentArea'), 'currentAreaDisplayName':self.session.get('currentAreaDisplayName') } self.response.out.write(self.template_render('message.html', template_values))
def mutate(self, info, url, parentURL, linkType): supportingPoint, supportingPointRoot = PointModel.getCurrentByUrl(url) oldPoint, oldPointRoot = PointModel.getCurrentByUrl(parentURL) user = info.context.current_user if user: # NOTE: ported this over from handlers/linkpoint.py, don't totally understand it all # This code is if the vote existed before and the point was unlinked, and now # it is being re-linked voteCount, rating, myVote = RelevanceVoteModel.getExistingVoteNumbers( oldPointRoot.key, supportingPointRoot.key, linkType, user) supportingPoint._relevanceVote = myVote newLink = [{ 'pointRoot': supportingPointRoot, 'pointCurrentVersion': supportingPoint, 'linkType': linkType, 'voteCount': voteCount, 'fRating': rating }] newVersion = oldPoint.update(pointsToLink=newLink, user=user) user.addRelevanceVote(oldPointRoot.key.urlsafe(), supportingPointRoot.key.urlsafe(), linkType, 100) # get my vote for this point, to render it in the linkPoint template supportingPoint.addVote(user) # these two are in service of the SubPointConnection logic - we should find a way to DRY this up supportingPoint.parent = newVersion supportingPoint.link_type = linkType return LinkPoint(parent=newVersion, point=supportingPoint) else: raise Exception("User not logged in.")
def post(self): self.response.headers["Content-Type"] = 'application/json; charset=utf-8' resultJSON = json.dumps({'result': False}) supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get('supportingPointURL')) oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('parentPointURL')) user = self.current_user linkType = self.request.get('linkType') if user: try: # This code is if the vote existed before and the point was unlinked, and now # it is being re-linked voteCount, rating, myVote = RelevanceVote.getExistingVoteNumbers( oldPointRoot.key, supportingPointRoot.key, linkType, user) supportingPoint._relevanceVote = myVote linkType = self.request.get('linkType') newLink = [{'pointRoot':supportingPointRoot, 'pointCurrentVersion':supportingPoint, 'linkType':linkType, 'voteCount': voteCount, 'fRating':rating } ] newVersion = oldPoint.update( pointsToLink=newLink, user=user ) user.addRelevanceVote( oldPointRoot.key.urlsafe(), supportingPointRoot.key.urlsafe(), linkType, 100) # get my vote for this point, to render it in the linkPoint template supportingPoint.addVote(user) except WhysaurusException as e: resultJSON = json.dumps({'result': False, 'error': e.message}) else: if newVersion: newLinkPointHTML = self.template_render('linkPoint.html', { 'point': supportingPoint, 'linkType': linkType }) resultJSON = json.dumps({ 'result': True, 'numLinkPoints': newVersion.linkCount(linkType), 'newLinkPoint':newLinkPointHTML, 'authorURL': self.current_user.url, 'author': newVersion.authorName, 'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'), }) else: json.dumps({'result': False, 'error': 'There was a problem updating the point.'}) else: resultJSON = json.dumps({'result': 'User not logged in. ACCESS DENIED!'}) self.response.out.write(resultJSON)
def post(self): self.response.headers["Content-Type"] = "application/json; charset=utf-8" resultJSON = json.dumps({"result": False}) supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get("supportingPointURL")) oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get("parentPointURL")) user = self.current_user linkType = self.request.get("linkType") if user: try: # This code is if the vote existed before and the point was unlinked, and now # it is being re-linked voteCount, rating, myVote = RelevanceVote.getExistingVoteNumbers( oldPointRoot.key, supportingPointRoot.key, linkType, user ) supportingPoint._relevanceVote = myVote linkType = self.request.get("linkType") newLink = [ { "pointRoot": supportingPointRoot, "pointCurrentVersion": supportingPoint, "linkType": linkType, "voteCount": voteCount, "fRating": rating, } ] newVersion = oldPoint.update(pointsToLink=newLink, user=user) user.addRelevanceVote(oldPointRoot.key.urlsafe(), supportingPointRoot.key.urlsafe(), linkType, 100) # get my vote for this point, to render it in the linkPoint template supportingPoint.addVote(user) except WhysaurusException as e: resultJSON = json.dumps({"result": False, "error": e.message}) else: if newVersion: newLinkPointHTML = self.template_render( "linkPoint.html", {"point": supportingPoint, "linkType": linkType} ) resultJSON = json.dumps( { "result": True, "numLinkPoints": newVersion.linkCount(linkType), "newLinkPoint": newLinkPointHTML, "authorURL": self.current_user.url, "author": newVersion.authorName, "dateEdited": newVersion.PSTdateEdited.strftime("%b. %d, %Y, %I:%M %p"), } ) else: json.dumps({"result": False, "error": "There was a problem updating the point."}) else: resultJSON = json.dumps({"result": "User not logged in. ACCESS DENIED!"}) self.response.out.write(resultJSON)