def removeLinkedPoint(self, unlinkPointRoot, linkType, user): if user: theRoot = self.key.parent().get() newPoint = Point(parent=theRoot.key) # All versions ancestors of the caseRoot newPoint.authorName = user.name newPoint.authorURL = user.url newPoint.supportingPointsLastChange = list(self.supportingPointsLastChange) newPoint.supportingPointsRoots = list(self.supportingPointsRoots) newPoint.counterPointsRoots = list(self.counterPointsRoots) newPoint.counterPointsLastChange = list(self.counterPointsLastChange) newPoint.childPointsRoots = list(self.childPointsRoots) newPoint.childPointsLastChange = list(self.childPointsLastChange) newPoint.sources = list(self.sources) try: newPoint.removeLink(unlinkPointRoot, linkType) except Exception as e: logging.info( 'Could not remove supporting point from list: ' + str(e)) newPoint.title = self.title newPoint.nodetype = self.nodetype newPoint.content = self.content newPoint.summaryText = self.summaryText newPoint.version = self.version + 1 newPoint.upVotes = self.upVotes newPoint.downVotes = self.downVotes newPoint.voteTotal = self.voteTotal newPoint.ribbonTotal = self.ribbonTotal newPoint.imageURL = self.imageURL newPoint.imageDescription = self.imageDescription newPoint.imageAuthor = self.imageAuthor newPoint.url = self.url self.current = False newPoint.current = True self.put() newPoint.put() theRoot.current = newPoint.key theRoot.put() Follow.createFollow(user.key, theRoot.key, "edited") Point.addNotificationTask(theRoot.key, user.key, "unlinked a %s point from" % linkType) return newPoint else: return None
def create(title, nodetype, content, summaryText, user, backlink=None, linktype="", imageURL=None, imageAuthor=None, imageDescription=None, sourceURLs=None, sourceNames=None): newUrl = makeURL(title) pointRoot = PointRoot() pointRoot.url = newUrl pointRoot.nodetype = nodetype pointRoot.numCopies = 0 pointRoot.editorsPick = False pointRoot.viewCount = 1 if backlink: if linktype == 'supporting': pointRoot.pointsSupportedByMe = [backlink] elif linktype == 'counter': pointRoot.pointsCounteredByMe = [backlink] elif linktype == 'child': pointRoot.myParentPoints = [backlink] createdPoint, createdPointRoot = Point.transactionalCreate( pointRoot, title, nodetype, content, summaryText, user, imageURL, imageAuthor, imageDescription, sourceURLs, sourceNames ) Follow.createFollow(user.key, createdPointRoot.key, "created") return createdPoint, createdPointRoot
def update( self, newTitle=None, newContent=None, newSummaryText=None, pointsToLink=None, user=None, imageURL=None, imageAuthor=None, imageDescription=None, sourcesToAdd=None, sourceKeysToRemove=None): if user: theRoot = self.key.parent().get() newPoint = Point(parent=self.key.parent()) # All versions ancestors of the PointRoot newPoint.title = self.title if newTitle is None else newTitle newPoint.nodetype = self.nodetype newPoint.content = self.content if newContent is None else newContent if newSummaryText: newPoint.summaryText = newSummaryText if (len( newSummaryText) != 250) else newSummaryText + '...' else: newPoint.summaryText = self.summaryText newPoint.authorName = user.name newPoint.authorURL = user.url newPoint.supportingPointsRoots = list(self.supportingPointsRoots) newPoint.supportingPointsLastChange = list(self.supportingPointsLastChange) newPoint.counterPointsRoots = list(self.counterPointsRoots) newPoint.counterPointsLastChange = list(self.counterPointsLastChange) newPoint.childPointsRoots = list(self.childPointsRoots) newPoint.childPointsLastChange = list(self.childPointsLastChange) newPoint.sources = self.sources keysToRemove = convertListToKeys(sourceKeysToRemove) if keysToRemove: for keyToRemove in keysToRemove: for oldKey in newPoint.sources: if oldKey == keyToRemove: newPoint.sources.remove(oldKey) newPoint.version = self.version + 1 newPoint.upVotes = self.upVotes newPoint.downVotes = self.downVotes newPoint.voteTotal = self.voteTotal newPoint.imageURL = self.imageURL if imageURL is None else imageURL newPoint.imageDescription = self.imageDescription if imageDescription is None else imageDescription newPoint.imageAuthor = self.imageAuthor if imageAuthor is None else imageAuthor if newPoint.title != self.title: newPoint.url = theRoot.updateURL(newPoint.title) else: newPoint.url = self.url newPoint.current = True self.current = False newPoint, theRoot = self.transactionalUpdate(newPoint, theRoot, sourcesToAdd, user, pointsToLink) Follow.createFollow(user.key, theRoot.key, "edited") Point.addNotificationTask(theRoot.key, user.key, "edited") # THIS NEEDS TO CHECK WHETHER IT IS NECESSARY TO UPDATE THE INDEX newPoint.addToSearchIndexNew() return newPoint else: return None