Example #1
0
def at_users(content, autoescape=None):
    if autoescape:
        esca = conditional_escape
    else:
        esca = lambda x: x
    filtered = filter_at_users(esca(content))
    return mark_safe(filtered)
Example #2
0
def comments(request, post_id):
    if request.method == 'POST':
        if len(request.POST.get('content', '')) > 0 and len(request.POST.get('content', '')) <= 200:
            content = request.POST['content']
            post = get_object_or_404(Post, pk=post_id)
            post.comments.create(content=content, user=request.user)

            # get users who has been @, and send notification to them
            notify_at_users(content, "post_comment", post.id, request.user)
            return {'status': 'ok'}
        else:
            return {'status': 'error'}
    else:
        post = Post.objects.get(id=post_id)
        comments = list(post.comments.prefetch_related("user").all())
        for comment in comments:
            comment.content = filter_at_users(comment.content)
        return comments