Ejemplo n.º 1
0
def post(**kwargs):
    defaults = {}
    if 'creator' not in kwargs:
        defaults['creator'] = user(save=True)
    if 'thread' not in kwargs:
        defaults['thread'] = thread(creator=defaults['creator'], save=True)
    defaults.update(kwargs)
    return Post(**defaults)
Ejemplo n.º 2
0
def new_thread(request, document_slug):
    """Start a new thread."""
    doc = get_document(document_slug, request)

    if request.method == "GET":
        form = NewThreadForm()
        return render(request, "kbforums/new_thread.html", {
            "form": form,
            "document": doc
        })

    form = NewThreadForm(request.POST)
    post_preview = None
    if form.is_valid():
        if "preview" in request.POST:
            thread = Thread(creator=request.user,
                            title=form.cleaned_data["title"])
            post_preview = Post(thread=thread,
                                creator=request.user,
                                content=form.cleaned_data["content"])
        elif not _is_ratelimited(request):
            thread = doc.thread_set.create(creator=request.user,
                                           title=form.cleaned_data["title"])
            thread.save()
            post = thread.new_post(creator=request.user,
                                   content=form.cleaned_data["content"])
            post.save()

            # Send notifications to forum watchers.
            NewThreadEvent(post).fire(exclude=post.creator)

            # Add notification automatically if needed.
            if Setting.get_for_user(request.user, "kbforums_watch_new_thread"):
                NewPostEvent.notify(request.user, thread)

            return HttpResponseRedirect(
                reverse("wiki.discuss.posts", args=[document_slug, thread.id]))

    return render(
        request,
        "kbforums/new_thread.html",
        {
            "form": form,
            "document": doc,
            "post_preview": post_preview
        },
    )
Ejemplo n.º 3
0
def new_thread(request, document_slug):
    """Start a new thread."""
    doc = get_document(document_slug, request)

    if request.method == 'GET':
        form = NewThreadForm()
        return render(request, 'kbforums/new_thread.html', {
            'form': form,
            'document': doc
        })

    form = NewThreadForm(request.POST)
    post_preview = None
    if form.is_valid():
        if 'preview' in request.POST:
            thread = Thread(creator=request.user,
                            title=form.cleaned_data['title'])
            post_preview = Post(thread=thread,
                                creator=request.user,
                                content=form.cleaned_data['content'])
        elif not _is_ratelimited(request):
            thread = doc.thread_set.create(creator=request.user,
                                           title=form.cleaned_data['title'])
            thread.save()
            statsd.incr('kbforums.thread')
            post = thread.new_post(creator=request.user,
                                   content=form.cleaned_data['content'])
            post.save()

            # Send notifications to forum watchers.
            NewThreadEvent(post).fire(exclude=post.creator)

            # Add notification automatically if needed.
            if Setting.get_for_user(request.user, 'kbforums_watch_new_thread'):
                NewPostEvent.notify(request.user, thread)

            return HttpResponseRedirect(
                reverse('wiki.discuss.posts', args=[document_slug, thread.id]))

    return render(request, 'kbforums/new_thread.html', {
        'form': form,
        'document': doc,
        'post_preview': post_preview
    })
Ejemplo n.º 4
0
def post_preview_async(request, document_slug):
    """Ajax preview of posts."""
    statsd.incr('forums.preview')
    post = Post(creator=request.user, content=request.POST.get('content', ''))
    return render(request, 'kbforums/includes/post_preview.html',
                  {'post_preview': post})
Ejemplo n.º 5
0
def post_preview_async(request, document_slug):
    """Ajax preview of posts."""
    post = Post(creator=request.user, content=request.POST.get("content", ""))
    return render(request, "kbforums/includes/post_preview.html",
                  {"post_preview": post})