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)
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)
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)