Example #1
0
    def archiveComments(self):
        results = {'result': False}
        pointRootUrlsafe = self.request.get('rootKey')
        parentCommentUrlsafe = self.request.get('parentKey')
        user = self.current_user
        
        if user and user.isAdmin:
            pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe)
            if pointRoot:
                try:
                    numArchived = pointRoot.archiveComments(parentCommentUrlsafe)
                    results = {
                        'result': True,
                        'numArchived': numArchived
                    }
                    
                except WhysaurusException as e:
                    results['error'] = str(e)                    
            else:
                results['error'] = 'Unable to find point root'

        else:
            results['error'] = 'Not authorized to archive comments'
            
        resultJSON = json.dumps(results)
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Example #2
0
    def archiveComments(self):
        results = {'result': False}
        pointRootUrlsafe = self.request.get('rootKey')
        parentCommentUrlsafe = self.request.get('parentKey')
        user = self.current_user

        if user and user.isAdmin:
            pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe)
            if pointRoot:
                try:
                    numArchived = pointRoot.archiveComments(
                        parentCommentUrlsafe)
                    results = {'result': True, 'numArchived': numArchived}

                except WhysaurusException as e:
                    results['error'] = str(e)
            else:
                results['error'] = 'Unable to find point root'

        else:
            results['error'] = 'Not authorized to archive comments'

        resultJSON = json.dumps(results)
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Example #3
0
    def mutate(self, info, pointID, commentID):
        user = info.context.current_user
        if user and user.isAdmin:

            pointRoot = PointRootModel.getByUrlsafe(pointID)
            numArchived = pointRoot.archiveComments(commentID)
            return ArchiveComment(numArchived=numArchived)
Example #4
0
 def mutate(self, info, comment_data):
     point_root = PointRootModel.getByUrlsafe(comment_data.pointID)
     user = info.context.current_user
     text = comment_data.text
     comment = CommentModel.create(text, user, point_root,
                                   comment_data.parentCommentID)
     PointModel.addNotificationTask(point_root.key, user.key, 3, text)
     return NewComment(comment=comment)
Example #5
0
 def joshTaskTemp(self):
     results = {'result': False}
     pointRootUrlsafe = self.request.get('rootKey')
     pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe)
     if pointRoot:
         try: 
             #pointRoot.setTop();
         except WhysaurusException as e:
             results['error'] = str(e)
     else:
         results['error'] = 'Unable to find point root'
         
     resultJSON = json.dumps(results)
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Example #6
0
    def saveComment(self):
        results = {'result': False}
        text = self.request.get('commentText')
        pointRootUrlsafe = self.request.get('p')
        parentCommentUrlsafe = self.request.get('parentKey')

        user = self.current_user
        if user:
            try:
                pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe)
                if pointRoot:
                    comment = Comment.create(text, user, pointRoot,
                                             parentCommentUrlsafe)
                    if comment:
                        pst_date = PST.convert(comment.date)
                        results = {
                            'result':
                            True,
                            'userName':
                            user.name,
                            'userURL':
                            user.url,
                            'avatar_url':
                            user.avatar_url if hasattr(user, 'avatar_url') else
                            '/static/img/icon_triceratops_black_47px.png',
                            'text':
                            text,
                            'date':
                            pst_date.strftime('%b. %d, %Y, %I:%M %p'),
                            'parentUrlsafe':
                            parentCommentUrlsafe,
                            'myUrlSafe':
                            comment.key.urlsafe(),
                            'level':
                            comment.level
                        }
                        Point.addNotificationTask(pointRoot.key, user.key, 3,
                                                  text)

                else:
                    results[
                        'error'] = 'Unable to find the point to add this comment'
            except WhysaurusException as e:
                results['error'] = str(e)
        resultJSON = json.dumps(results)
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Example #7
0
    def getArchivedComments(self):
        results = {'result': False}
        pointRootUrlsafe = self.request.get('rootKey')
        pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe)
        if pointRoot:
            try:
                template_values = {
                    'archivedComments': pointRoot.getArchivedComments()
                }
                html = self.template_render('archivedComments.html',
                                            template_values)
                results = {'result': True, 'html': html}
            except WhysaurusException as e:
                results['error'] = str(e)
        else:
            results['error'] = 'Unable to find point root'

        resultJSON = json.dumps(results)
        self.response.headers[
            "Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
Example #8
0
 def getArchivedComments(self):
     results = {'result': False}
     pointRootUrlsafe = self.request.get('rootKey')
     pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe)
     if pointRoot:
         try: 
             template_values = {
                 'archivedComments': pointRoot.getArchivedComments()
             }
             html = self.template_render('archivedComments.html', template_values)
             results = {
                 'result': True,
                 'html': html
             }
         except WhysaurusException as e:
             results['error'] = str(e)
     else:
         results['error'] = 'Unable to find point root'
             
     resultJSON = json.dumps(results)
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Example #9
0
 def saveComment(self):
     results = {'result': False}
     text = self.request.get('commentText')
     pointRootUrlsafe = self.request.get('p')
     parentCommentUrlsafe = self.request.get('parentKey')
     
     user = self.current_user
     if user:
         try:
             pointRoot = PointRoot.getByUrlsafe(pointRootUrlsafe) 
             if pointRoot:               
                 comment = Comment.create(
                     text, user, pointRoot, 
                     parentCommentUrlsafe)
                 if comment:
                     pst_date = PST.convert(comment.date)
                     results = {
                                'result': True, 
                                'userName': user.name,
                                'userURL': user.url,
                                'avatar_url': user.avatar_url if hasattr(user, 'avatar_url') else '/static/img/icon_triceratops_black_47px.png',
                                'text': text,
                                'date': pst_date.strftime('%b. %d, %Y, %I:%M %p'),
                                'parentUrlsafe': parentCommentUrlsafe,
                                'myUrlSafe':comment.key.urlsafe(),
                                'level': comment.level
                                }
                     Point.addNotificationTask(pointRoot.key, user.key, 3, text)
                                
             else:
                 results['error'] = 'Unable to find the point to add this comment'
         except WhysaurusException as e:
             results['error'] = str(e)
     resultJSON = json.dumps(results)
     self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
     self.response.out.write(resultJSON)
Example #10
0
 def resolve_root(self, info):
     return PointRootModel.getByUrlsafe(self.rootURLsafe)