示例#1
0
def post_moderate(request, post, user, status, date=None):
    """
    Performs a moderator action on the post. 
    """

    # most actions will return the original post
    url = post.get_absolute_url()
    
    # setting posts to open require more than one permission
    if status == POST_OPEN and not user.profile.can_moderate:
        msg = 'User %s not a moderator' % user.id
        messages.error(request, msg) if request else None
        return url

    if post.top_level and post.answer_count > 0 and (not user.profile.can_moderate):
        msg = 'The post already has one or more answers. Only a moderator may delete it.'
        messages.error(request, msg) if request else None
        return url

    # check that user may write the post
    if not auth.authorize_post_edit(user=user, post=post, strict=False):
        msg = 'User %s may not moderate post %s' % (user.id, post.id)
        messages.error(request, msg) if request else None
        return url

    if status == POST_CLOSED:
        # closing posts is only possible by someone that left a comment on the main post
        has_comment = Post.objects.filter(parent=post, type=POST_COMMENT, author=user).count()
        if not has_comment:
            msg = '<b>Note</b>: post closing require that you add a comment that explains the rationale for closing it.'
            messages.error(request, msg)
            return url

    # stop any ads that may be attached to this post
    if status in (POST_CLOSED, POST_DELETED):
        post.ad_set.update(status=Ad.STOPPED)

    # special treatment for deletion
    no_orphans = (Post.objects.filter(parent=post).exclude(id=post.id).count() == 0)

    # authors may remove their post/comments without a trace as long as it has
    if status == POST_DELETED and no_orphans and (user==post.author):
        # destroy the post with no trace
        Vote.objects.filter(post=post).delete()
        post.delete()
        return "/"

    post.status = status
    post.save()
   
    text = notegen.post_moderator_action(user=user, post=post)
    send_note(target=post.author, sender=user, content=text,  type=NOTE_MODERATOR, both=True, url=post.get_absolute_url() )
    
    msg = 'Post status set to %s' % post.get_status_display()
    messages.info(request, msg) if request else None
    
    return url
示例#2
0
def post_moderate(request, post, user, status, date=None):
    """
    Performs a moderator action on the post. 
    """

    # most actions will return the original post
    url = post.get_absolute_url()
    
    # setting posts to open require more than one permission
    if status == POST_OPEN and not user.profile.can_moderate:
        msg = 'User %s not a moderator' % user.id
        messages.error(request, msg) if request else None
        return url

    if post.top_level and post.answer_count > 0 and (not user.profile.can_moderate):
        msg = 'The post already has one or more answers. Only a moderator may delete it.'
        messages.error(request, msg) if request else None
        return url

    # check that user may write the post
    if not auth.authorize_post_edit(user=user, post=post, strict=False):
        msg = 'User %s may not moderate post %s' % (user.id, post.id)
        messages.error(request, msg) if request else None
        return url

    if status == POST_CLOSED:
        # closing posts is only possible by someone that left a comment on the main post
        has_comment = Post.objects.filter(parent=post, type=POST_COMMENT, author=user).count()
        if not has_comment:
            msg = '<b>Note</b>: post closing require that you add a comment that explains the rationale for closing it.'
            messages.error(request, msg)
            return url

    # stop any ads that may be attached to this post
    if status in (POST_CLOSED, POST_DELETED):
        post.ad_set.update(status=Ad.STOPPED)

    # special treatment for deletion
    no_orphans = (Post.objects.filter(parent=post).exclude(id=post.id).count() == 0)

    # authors may remove their post/comments without a trace as long as it has
    if status == POST_DELETED and no_orphans and (user==post.author):
        # destroy the post with no trace
        Vote.objects.filter(post=post).delete()
        post.delete()
        return "/"

    post.status = status
    post.save()
   
    text = notegen.post_moderator_action(user=user, post=post)
    send_note(target=post.author, sender=user, content=text,  type=NOTE_MODERATOR, both=True, url=post.get_absolute_url() )
    
    msg = 'Post status set to %s' % post.get_status_display()
    messages.info(request, msg) if request else None
    
    return url
示例#3
0
def post_moderate(request, post, user, status, date=None):
    """
    Performs a moderator action on the post. 
    """

    # most actions will return the original post
    url = post.get_absolute_url()

    # setting posts to open require more than one permission
    if status == POST_OPEN and not user.profile.can_moderate:
        msg = 'User %s not a moderator' % user.id
        messages.error(request, msg) if request else None
        return url

    # check that user may write the post
    if not auth.authorize_post_edit(user=user, post=post, strict=False):
        msg = 'User %s may not moderate post %s' % (user.id, post.id)
        messages.error(request, msg) if request else None
        return url

    # special treatment for deletion
    no_orphans = (Post.objects.filter(parent=post).exclude(
        id=post.id).count() == 0)

    # authors may remove their post/comments without a trace as long as it has
    if status == POST_DELETED and no_orphans and (user == post.author):
        # destroy the post with no trace
        Vote.objects.filter(post=post).delete()
        post.delete()
        return "/"

    # replace tags with the word deleted
    if status == POST_DELETED:
        post.tag_val = "deleted-post"
        post.set_tags()

    post.status = status
    post.save()

    text = notegen.post_moderator_action(user=user, post=post)
    send_note(target=post.author,
              sender=user,
              content=text,
              type=NOTE_MODERATOR,
              both=True,
              url=post.get_absolute_url())

    msg = 'Post status set to %s' % post.get_status_display()
    messages.info(request, msg) if request else None

    return url
示例#4
0
def post_moderate(request, post, user, status, date=None):
    """
    Performs a moderator action on the post. 
    """

    # most actions will return the original post
    url = post.get_absolute_url()

    # setting posts to open require more than one permission
    if status == POST_OPEN and not user.profile.can_moderate:
        msg = "User %s not a moderator" % user.id
        messages.error(request, msg) if request else None
        return url

    # check that user may write the post
    if not auth.authorize_post_edit(user=user, post=post, strict=False):
        msg = "User %s may not moderate post %s" % (user.id, post.id)
        messages.error(request, msg) if request else None
        return url

    # special treatment for deletion
    no_orphans = Post.objects.filter(parent=post).exclude(id=post.id).count() == 0

    # authors may remove their post/comments without a trace as long as it has
    if status == POST_DELETED and no_orphans and (user == post.author):
        # destroy the post with no trace
        Vote.objects.filter(post=post).delete()
        post.delete()
        return "/"

    # replace tags with the word deleted
    if status == POST_DELETED:
        post.tag_val = "deleted-post"
        post.set_tags()

    post.status = status
    post.save()

    text = notegen.post_moderator_action(user=user, post=post)
    send_note(
        target=post.author, sender=user, content=text, type=NOTE_MODERATOR, both=True, url=post.get_absolute_url()
    )

    msg = "Post status set to %s" % post.get_status_display()
    messages.info(request, msg) if request else None

    return url