Exemple #1
0
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')
Exemple #2
0
def follow_user(request):
    if request.user.is_authenticated:
        if 'user_id' in request.POST:
            try:
                target = User.get_by_id(request.POST['user_id'])
            except:
                return apiRespond(400, msg='Target user not found')
            else:
                result, obj = request.user.follow(target)
                Alert.create_alert(user=target, ref_user=request.user, type=Alert.FOLLOW, follow=obj)
                return apiRespond(201, result=result)
        else:
            return apiRespond(400, msg='Required fields missing')
    else:
        return apiRespond(401, msg='User not logged in')
Exemple #3
0
def blog_react(request):
    if request.user.is_authenticated:
        if 'blog_id' in request.POST and 'reaction' in request.POST and request.POST['reaction'] in Reaction.CODES:
            reaction = request.POST['reaction']
            try:
                b = Blog.get_by_id(request.POST['blog_id'])
            except:
                return apiRespond(400, msg='Target blog not found')
            else:
                obj = request.user.react(blog=b, reaction=reaction)
                Alert.create_alert(ref_user=request.user, blog=b, type=Alert.REACTION, reaction=obj)
                return apiRespond(201, result=True)
        else:
            return apiRespond(400, msg='Required fields missing')
    else:
        return apiRespond(401, msg='User not logged in')