Example #1
0
    def create(cls, text, user, pointRoot, parent=None):
        parentCommentKey = None
        parentComment = None
        if parent:
            parentCommentKey = ndb.Key(urlsafe=parent)
            parentComment = parentCommentKey.get()
            if not parentComment:
                raise WhysaurusException("Bad parent comment key supplied.")
            elif parentComment.level >= 8:
                raise WhysaurusException("9 levels of replies are maximum for now.")

        if pointRoot:
            comment = Comment(
                parent=parentCommentKey,
                text=text,
                userName=user.name,
                userUrl=user.url,
                avatar_url=user.avatar_url
                if hasattr(user, "avatar_url")
                else "/static/img/icon_triceratops_black_47px.png",
                parentComment=parentCommentKey,
                level=parentComment.level + 1 if parentComment else 0,
            )
            newComment = comment.transactionalCreate(pointRoot, comment)
            Follow.createFollow(user.key, pointRoot.key, "commented on")
            return newComment
        else:
            return None
Example #2
0
    def create(cls, text, user, pointRoot, parent=None):
        parentCommentKey = None
        parentComment = None
        if parent:
            parentCommentKey = ndb.Key(urlsafe=parent)
            parentComment = parentCommentKey.get()
            if not parentComment:
                raise WhysaurusException("Bad parent comment key supplied.")
            elif parentComment.level >= 8:
                raise WhysaurusException(
                    "9 levels of replies are maximum for now.")

        if pointRoot:
            comment = Comment(
                parent=parentCommentKey,
                text=text,
                userName=user.name,
                userUrl=user.url,
                avatar_url=user.avatar_url if hasattr(user, 'avatar_url') else
                '/static/img/icon_triceratops_black_47px.png',
                parentComment=parentCommentKey,
                level=parentComment.level + 1 if parentComment else 0)
            newComment = comment.transactionalCreate(pointRoot, comment)
            Follow.createFollow(user.key, pointRoot.key, "commented on")
            return newComment
        else:
            return None
Example #3
0
    def MakeFollows(self):
        """
        # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        ADD FOLLOWS FOR ADMIN USERS
        # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
        """
        nextURL = None
        firstURL = self.request.get('nexturl')
        query = PointRoot.query().order(PointRoot.url)
        if firstURL:
            query = query.filter(PointRoot.url >= firstURL)
        pointRoots = query.fetch(11)
        if len(pointRoots) == 11:
            nextURL = pointRoots[-1].url
            pointRootsToReview = pointRoots[:10]
        else:
            pointRootsToReview = pointRoots

        i = 0
        for pointRoot in pointRootsToReview:
            pointRootKey = pointRoot.key
            followers = {}

            versions = pointRoot.getAllVersions()
            for point in versions:
                if point.version == 1:
                    followers[point.authorURL] = 'created'
                elif not point.authorURL in followers:
                    followers[point.authorURL] = 'edited'

            for comment in pointRoot.getComments():
                if not comment.userUrl in followers:
                    followers[comment.userUrl] = 'commented'

            logging.info('ROOT: %s FOLLOWERS: %s' %
                         (pointRoot.url, str(followers)))
            for url in followers.iterkeys():
                followType = followers[url]
                previousNamespace = namespace_manager.get_namespace()
                if previousNamespace and previousNamespace != '':
                    namespace_manager.set_namespace('')  # DEFAULT NAMESPACE
                    usr = WhysaurusUser.getByUrl(url)
                    namespace_manager.set_namespace(previousNamespace)
                else:
                    usr = WhysaurusUser.getByUrl(url)
                logging.info('Trying to follow for U:%s, R:%s, T:%s' %
                             (url, pointRoot.url, followType))
                f = None
                f = Follow.createFollow(usr.key, pointRootKey, followType)
                if f:
                    i = i + 1
                    logging.info('ADDED follow for U:%s, R:%s, T:%s' %
                                 (url, pointRoot.url, followType))

        logging.info('Added %d follows' % i)
        if nextURL:
            t = Task(url="/MakeFollows", params={'nexturl': nextURL})
            t.add(queue_name="notifications")
            logging.info('Requeing MakeFollows task to start at url %s ' %
                         nextURL)
Example #4
0
    def MakeFollows(self):
        """
        # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        ADD FOLLOWS FOR ADMIN USERS
        # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
        """
        nextURL = None
        firstURL = self.request.get('nexturl')
        query = PointRoot.query().order(PointRoot.url)
        if firstURL:
            query = query.filter(PointRoot.url >= firstURL)
        pointRoots = query.fetch(11)
        if len(pointRoots) == 11:
            nextURL = pointRoots[-1].url
            pointRootsToReview = pointRoots[:10]
        else:
            pointRootsToReview = pointRoots
        
        i = 0
        for pointRoot in pointRootsToReview:
            pointRootKey = pointRoot.key
            followers = {}     
                          
            versions = pointRoot.getAllVersions()
            for point in versions:
                if point.version == 1:
                    followers[point.authorURL] = 'created'         
                elif not point.authorURL in followers:
                    followers[point.authorURL] = 'edited'  
            
            for comment in pointRoot.getComments():
                if not comment.userUrl in followers:
                    followers[comment.userUrl] = 'commented'  
                
            logging.info('ROOT: %s FOLLOWERS: %s' % (pointRoot.url, str(followers)))       
            for url in followers.iterkeys():
                followType = followers[url]
                previousNamespace = namespace_manager.get_namespace()
                if previousNamespace and previousNamespace != '':                
                    namespace_manager.set_namespace('') # DEFAULT NAMESPACE
                    usr = WhysaurusUser.getByUrl(url)
                    namespace_manager.set_namespace(previousNamespace)
                else:
                    usr = WhysaurusUser.getByUrl(url)
                logging.info('Trying to follow for U:%s, R:%s, T:%s' % (url, pointRoot.url, followType))
                f = None
                f = Follow.createFollow(usr.key, pointRootKey, followType)
                if f:
                    i = i + 1
                    logging.info('ADDED follow for U:%s, R:%s, T:%s' % (url, pointRoot.url, followType))

                       
        logging.info('Added %d follows' % i)
        if nextURL:
            t = Task(url="/MakeFollows", params={'nexturl':nextURL})
            t.add(queue_name="notifications")
            logging.info('Requeing MakeFollows task to start at url %s ' % nextURL)