def blog_comment(request): if request.user.is_authenticated: if 'blog_id' in request.POST and 'text' in request.POST and len( request.POST['text'].strip()) > 2: ref = None if 'ref_comment_id' in request.POST: ref_id = request.POST['ref_comment_id'] try: ref = Comment.get_by_id(ref_id) except: return apiRespond(400, msg='Reference comment not found') try: b = Blog.get_by_id(request.POST['blog_id']) except: return apiRespond(400, msg='Target blog not found') else: comment = request.user.comment( blog=b, text=request.POST['text'].strip(), reference=ref) Alert.create_alert( ref_user=request.user, type=Alert.COMMENT_REPLY if ref else Alert.COMMENT, blog=b) return apiRespond(201, comment=comment.get_obj()) else: return apiRespond(400, msg='Required fields missing') else: return apiRespond(401, msg='User not logged in')
def blog_uncomment(request): if request.user.is_authenticated: if 'comment_id' in request.POST: try: comment = Comment.get_by_id(request.POST['comment_id']) except: return apiRespond(400, msg='Target comment not found') else: if comment.user == request.user: comment.delete() return apiRespond(201, result=True) else: return apiRespond(400, msg='Required fields missing') else: return apiRespond(401, msg='User not logged in')