def relevanceVote(self): resultJSON = json.dumps({'result': False}) parentRootURLsafe = self.request.get('parentRootURLsafe') childRootURLsafe = self.request.get('childRootURLsafe') linkType = self.request.get('linkType') vote = self.request.get('vote') user = self.current_user if int(vote) > 100 or int(vote) < 0: resultJSON = json.dumps({'result': False, 'error':'Vote value out of range.'}) # logging.info('ABOUT TO CHECK ALL THE DATA 1:%s 2:%s 3:%s 4:%s ' % (parentRootURLsafe,childRootURLsafe,linkType, vote)) elif parentRootURLsafe and childRootURLsafe and linkType and user: result, newRelevance, newVoteCount = user.addRelevanceVote( parentRootURLsafe, childRootURLsafe, linkType, int(vote)) if result: # Hacky, parent score retrieval could be pushed into addRelevanceVote parentNewScore = None parentPoint, parentPointRoot = Point.getCurrentByRootKey(parentRootURLsafe) if parentPoint: parentNewScore = parentPoint.pointValue() else: parentNewScore = 17 resultJSON = json.dumps({ 'result': True, 'newVote': vote, 'newRelevance': str(newRelevance) + '%', 'newVoteCount': newVoteCount, 'parentNewScore': parentNewScore }) self.response.headers["Content-Type"] = 'application/json; charset=utf-8' self.response.out.write(resultJSON)
def mutate(self, info, linkType, url, parentRootURLsafe, rootURLsafe, vote): user = info.context.current_user point, pointRoot = PointModel.getCurrentByUrl(url) if point: if user: pp, ppr = PointModel.getCurrentByRootKey(parentRootURLsafe) result, newRelevance, newVoteCount = user.addRelevanceVote( parentRootURLsafe, rootURLsafe, linkType, vote) if result: return RelevanceVote( point=point, parentPoint=pp, link=Link(type=linkType, relevance=newRelevance, sortScore=LinkModel.calcSortScore( newRelevance, point.pointValueCached), relevanceVote=vote, voteCount=newVoteCount, parentURLsafe=parentRootURLsafe, childURLsafe=rootURLsafe)) else: raise Exception(str('vote failed: ' + str(vote))) else: raise Exception(str('user not defined ' + str(user))) else: raise Exception(str('point not defined ' + str(point)))
def relevanceVote(self): resultJSON = json.dumps({'result': False}) parentRootURLsafe = self.request.get('parentRootURLsafe') childRootURLsafe = self.request.get('childRootURLsafe') linkType = self.request.get('linkType') vote = self.request.get('vote') user = self.current_user if int(vote) > 100 or int(vote) < 0: resultJSON = json.dumps({'result': False, 'error':'Vote value out of range.'}) # logging.info('ABOUT TO CHECK ALL THE DATA 1:%s 2:%s 3:%s 4:%s ' % (parentRootURLsafe,childRootURLsafe,linkType, vote)) elif parentRootURLsafe and childRootURLsafe and linkType and user: result, newRelevance, newVoteCount = user.addRelevanceVote( parentRootURLsafe, childRootURLsafe, linkType, int(vote)) if result: # Hacky, parent score retrieval could be pushed into addRelevanceVote parentNewScore = None parentPoint, parentPointRoot = Point.getCurrentByRootKey(parentRootURLsafe) if parentPoint: parentNewScore = parentPoint.pointValue() else: parentNewScore = -999 resultJSON = json.dumps({ 'result': True, 'newVote': vote, 'newRelevance': str(newRelevance) + '%', 'newVoteCount': newVoteCount, 'parentNewScore': parentNewScore }) self.response.headers["Content-Type"] = 'application/json; charset=utf-8' self.response.out.write(resultJSON)
def mutate(self, info, id): user = info.context.current_user point, point_root = PointModel.getCurrentByRootKey(id) if user.isAdmin: if FeaturedPoint.setFeatured(point_root.key): return MakeFeatured(point=point, point_root=point_root) else: raise Exception(str('make featured failed:')) else: raise Exception(str('non admin user tried to set featured point'))
def mutate(self, info, id): user = info.context.current_user point, point_root = PointModel.getCurrentByRootKey(id) if user.isAdmin: if point_root.updateEditorsPick(True, int(-time.time())): return SetEditorsPick(point=point, point_root=point_root) else: raise Exception(str('set editors pick failed:')) else: raise Exception(str('non admin user tried to set editors pick'))
def post(self, pointURL): rootKey = self.request.get('rootKey') point, pointRoot = Point.getCurrentByRootKey(rootKey) template_values = self.createTemplateValues(point, pointRoot) self.outputTemplateValues(template_values)
def createTemplateValues(self, url=None, full=True, rootKey=None): newURL = None templateValues = {} point = None pointRoot = None if url: point, pointRoot = yield Point.findCurrent_async(url) elif rootKey: point, pointRoot = Point.getCurrentByRootKey(rootKey) else: templateValues = { 'user': self.current_user, 'message': "URL or Key must be supplied.", 'currentArea': self.session.get('currentArea'), 'currentAreaDisplayName': self.session.get('currentAreaDisplayName') } if not point: templateValues = { 'user': self.current_user, 'message': "Could not find point. Some points are in private classrooms and you \ need to be logged in and authorized to view them.", 'currentArea': self.session.get('currentArea'), 'currentAreaDisplayName': self.session.get('currentAreaDisplayName') } else: # we have a point! voteValue = 0 ribbonValue = False addedToRecentlyViewed = False user = self.current_user # supportingPoints, counterPoints = point.getAllLinkedPoints(user) # We need to get the recently viewed points here # Because the user can add them as counter/supporting points if user: vote, relevanceVotes, recentlyViewed, sources, supportingPoints, counterPoints = yield \ user.getVote_async(point.key.parent()), \ user.getRelevanceVotes_async(point), \ user.getRecentlyViewed_async( \ excludeList=[point.key.parent()] + \ point.getLinkedPointsRootKeys("supporting") + \ point.getLinkedPointsRootKeys("counter")), \ point.getSources_async(), \ point.getLinkedPoints_async("supporting", user), \ point.getLinkedPoints_async("counter", user) point.addRelevanceVotes(relevanceVotes, supportingPoints, counterPoints) addedToRecentlyViewed = user.updateRecentlyViewed(point.key.parent()) else: sources, supportingPoints, counterPoints = yield point.getSources_async(), \ point.getLinkedPoints_async("supporting", None), \ point.getLinkedPoints_async("counter", None) recentlyViewed = None # For now add to a point's view count if user is not logged in or if view point is added to the recently viewed list if addedToRecentlyViewed or not user: viewCountFuture = pointRoot.addViewCount() if user: voteValue = vote.value if vote else 0 ribbonValue = vote.ribbon if vote else False # viewCountFuture.get_result() templateValues = { 'point': point, 'pointRoot': pointRoot, 'recentlyViewedPoints': recentlyViewed, 'supportingPoints': supportingPoints, 'counterPoints': counterPoints, 'supportedPoints':pointRoot.getBacklinkPoints("supporting"), 'counteredPoints':pointRoot.getBacklinkPoints("counter"), 'sources': sources, 'user': user, 'voteValue': voteValue, 'ribbonValue': ribbonValue, 'currentArea':self.session.get('currentArea'), 'currentAreaDisplayName':self.session.get('currentAreaDisplayName') } if full: if user: user.getActiveNotifications() templateValues['notifications'] = user.notifications if user else None, templateValues['comments'] = pointRoot.getComments() raise ndb.Return(templateValues)
def resolve_comments(self, info, pointID, showArchived=False): point, point_root = PointModel.getCurrentByRootKey(pointID) return Comments(point_root=point_root, show_archived=showArchived)
def mutate(self, info, pointID, id): point, pointRoot = PointModel.getCurrentByRootKey(pointID) newPointVersion = point.update(user=info.context.current_user, sourceKeysToRemove=[id]) return AddSource(point=newPointVersion)
def mutate(self, info, pointID, url, name=None): point, pointRoot = PointModel.getCurrentByRootKey(pointID) newPointVersion = point.update( user=info.context.current_user, sourcesToAdd=[SourceModel(parent=point.key, url=url, name=name)]) return AddSource(point=newPointVersion)