Ejemplo n.º 1
0
def edit_post(request, post_id):
    """
    Edits the given Post.
    """
    filters = {'pk': post_id}
    if not auth.is_moderator(request.user):
        filters['topic__hidden'] = False
    post = get_object_or_404(Post, **filters)
    topic = post.topic
    if not auth.user_can_edit_post(request.user, post, topic):
        return permission_denied(request,
            message='You do not have permission to edit this post.')
    forum = Forum.objects.select_related().get(pk=topic.forum_id)
    if forum.section.is_managed():
        if not forum.section.is_corp_authed(request.user):
            return permission_denied(request,
                    message="You are not a member of the appropriate corporation, alliance or coalition.")
    meta_editable = auth.is_moderator(request.user)
    if meta_editable:
        was_meta = post.meta
    preview = None
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Editing a post in:', topic)
    if request.method == 'POST':
        form = forms.ReplyForm(meta_editable, request.POST, instance=post)
        if form.is_valid():
            if 'preview' in request.POST:
                preview = post_formatter.format_post(
                    form.cleaned_data['body'], form.cleaned_data['emoticons'])
            elif 'submit' in request.POST:
                post = form.save(commit=False)
                if auth.is_moderator(request.user):
                    if post.meta and not was_meta:
                        moderation.make_post_meta(post, topic, forum)
                    elif not post.meta and was_meta:
                        moderation.make_post_not_meta(post, topic, forum)
                    else:
                        post.save()
                else:
                    post.save()
                return redirect_to_post(request, post.id, post)
    else:
        form = forms.ReplyForm(meta_editable, instance=post)
    return render(request, 'forum/edit_post.html', {
        'form': form,
        'post': post,
        'topic': topic,
        'forum': forum,
        'section': forum.section,
        'preview': preview,
        'title': 'Edit Post',
        'quick_help_template': post_formatter.QUICK_HELP_TEMPLATE,
    })
Ejemplo n.º 2
0
def edit_post(request, post_id):
    """
    Edits the given Post.
    """
    filters = {"pk": post_id}
    if not auth.is_moderator(request.user):
        filters["topic__hidden"] = False
    post = get_object_or_404(Post, **filters)
    topic = post.topic
    if not auth.user_can_edit_post(request.user, post, topic):
        return permission_denied(request, message="You do not have permission to edit this post.")
    forum = Forum.objects.select_related().get(pk=topic.forum_id)
    meta_editable = auth.is_moderator(request.user)
    if meta_editable:
        was_meta = post.meta
    preview = None
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, "Editing a post in:", topic)
    if request.method == "POST":
        form = forms.ReplyForm(meta_editable, request.POST, instance=post)
        if form.is_valid():
            if "preview" in request.POST:
                preview = post_formatter.format_post(form.cleaned_data["body"], form.cleaned_data["emoticons"])
            elif "submit" in request.POST:
                post = form.save(commit=False)
                if auth.is_moderator(request.user):
                    if post.meta and not was_meta:
                        moderation.make_post_meta(post, topic, forum)
                    elif not post.meta and was_meta:
                        moderation.make_post_not_meta(post, topic, forum)
                    else:
                        post.save()
                else:
                    post.save()
                return redirect_to_post(request, post.id, post)
    else:
        form = forms.ReplyForm(meta_editable, instance=post)
    return render(
        request,
        "forum/edit_post.html",
        {
            "form": form,
            "post": post,
            "topic": topic,
            "forum": forum,
            "section": forum.section,
            "preview": preview,
            "title": "Edit Post",
            "quick_help_template": post_formatter.QUICK_HELP_TEMPLATE,
        },
    )
Ejemplo n.º 3
0
def edit_post(request, post_id):
    """
    Edits the given Post.
    """
    filters = {'pk': post_id}
    if not auth.is_moderator(request.user):
        filters['topic__hidden'] = False
    post = get_object_or_404(Post, **filters)
    topic = post.topic
    if not auth.user_can_edit_post(request.user, post, topic):
        return permission_denied(
            request, message='You do not have permission to edit this post.')
    forum = Forum.objects.select_related().get(pk=topic.forum_id)
    meta_editable = auth.is_moderator(request.user)
    if meta_editable:
        was_meta = post.meta
    preview = None
    if app_settings.USE_REDIS:
        redis.seen_user(request.user, 'Editing a post in:', topic)
    if request.method == 'POST':
        form = forms.ReplyForm(meta_editable, request.POST, instance=post)
        if form.is_valid():
            if 'preview' in request.POST:
                preview = post_formatter.format_post(
                    form.cleaned_data['body'], form.cleaned_data['emoticons'])
            elif 'submit' in request.POST:
                post = form.save(commit=False)
                if auth.is_moderator(request.user):
                    if post.meta and not was_meta:
                        moderation.make_post_meta(post, topic, forum)
                    elif not post.meta and was_meta:
                        moderation.make_post_not_meta(post, topic, forum)
                    else:
                        post.save()
                else:
                    post.save()
                return redirect_to_post(request, post.id, post)
    else:
        form = forms.ReplyForm(meta_editable, instance=post)
    return render(
        request, 'forum/edit_post.html', {
            'form': form,
            'post': post,
            'topic': topic,
            'forum': forum,
            'section': forum.section,
            'preview': preview,
            'title': 'Edit Post',
            'quick_help_template': post_formatter.QUICK_HELP_TEMPLATE,
        })
Ejemplo n.º 4
0
    def test_post_to_metapost(self):
        post = Post.objects.get(pk=2)
        post.meta = True
        moderation.make_post_meta(post, post.topic, post.topic.forum)

        self.assertEquals(post.num_in_topic, 1)
        self.assertEquals(Post.objects.get(pk=82).num_in_topic, 2)
        self.assertEquals(Post.objects.get(pk=83).num_in_topic, 3)
        self.assertEquals(Post.objects.get(pk=84).num_in_topic, 4)
        self.assertEquals(Post.objects.get(pk=1).num_in_topic, 1)
        self.assertEquals(Post.objects.get(pk=3).num_in_topic, 2)

        topic = Topic.objects.get(pk=1)
        self.assertEquals(topic.post_count, 2)
        self.assertEquals(topic.metapost_count, 4)
Ejemplo n.º 5
0
    def test_post_to_metapost(self):
        post = Post.objects.get(pk=2)
        post.meta = True
        moderation.make_post_meta(post, post.topic, post.topic.forum)

        self.assertEquals(post.num_in_topic, 1)
        self.assertEquals(Post.objects.get(pk=82).num_in_topic, 2)
        self.assertEquals(Post.objects.get(pk=83).num_in_topic, 3)
        self.assertEquals(Post.objects.get(pk=84).num_in_topic, 4)
        self.assertEquals(Post.objects.get(pk=1).num_in_topic, 1)
        self.assertEquals(Post.objects.get(pk=3).num_in_topic, 2)

        topic = Topic.objects.get(pk=1)
        self.assertEquals(topic.post_count, 2)
        self.assertEquals(topic.metapost_count, 4)
Ejemplo n.º 6
0
    def test_last_post_to_metapost(self):
        post = Post.objects.get(pk=9)
        post.meta = True
        moderation.make_post_meta(post, post.topic, post.topic.forum)

        self.assertEquals(post.num_in_topic, 1)
        self.assertEquals(Post.objects.get(pk=88).num_in_topic, 2)
        self.assertEquals(Post.objects.get(pk=89).num_in_topic, 3)
        self.assertEquals(Post.objects.get(pk=90).num_in_topic, 4)

        topic = Topic.objects.get(pk=3)
        last_post = Post.objects.get(pk=8)
        self.assertEquals(topic.last_post_at, last_post.posted_at)
        self.assertEquals(topic.last_user_id, last_post.user_id)
        self.assertEquals(topic.last_username, last_post.user.username)

        forum = Forum.objects.get(pk=1)
        self.assertEquals(forum.last_post_at, last_post.posted_at)
        self.assertEquals(forum.last_topic_id, topic.id)
        self.assertEquals(forum.last_topic_title, topic.title)
        self.assertEquals(forum.last_user_id, last_post.user_id)
        self.assertEquals(forum.last_username, last_post.user.username)
Ejemplo n.º 7
0
    def test_last_post_to_metapost(self):
        post = Post.objects.get(pk=9)
        post.meta = True
        moderation.make_post_meta(post, post.topic, post.topic.forum)

        self.assertEquals(post.num_in_topic, 1)
        self.assertEquals(Post.objects.get(pk=88).num_in_topic, 2)
        self.assertEquals(Post.objects.get(pk=89).num_in_topic, 3)
        self.assertEquals(Post.objects.get(pk=90).num_in_topic, 4)

        topic = Topic.objects.get(pk=3)
        last_post = Post.objects.get(pk=8)
        self.assertEquals(topic.last_post_at, last_post.posted_at)
        self.assertEquals(topic.last_user_id, last_post.user_id)
        self.assertEquals(topic.last_username, last_post.user.username)

        forum = Forum.objects.get(pk=1)
        self.assertEquals(forum.last_post_at, last_post.posted_at)
        self.assertEquals(forum.last_topic_id, topic.id)
        self.assertEquals(forum.last_topic_title, topic.title)
        self.assertEquals(forum.last_user_id, last_post.user_id)
        self.assertEquals(forum.last_username, last_post.user.username)