Beispiel #1
0
def thread(**kwargs):
    defaults = {}
    if 'document' not in kwargs:
        defaults['document'] = document(save=True)
    if 'creator' not in kwargs:
        defaults['creator'] = user(save=True)
    defaults.update(kwargs)
    return Thread(**defaults)
Beispiel #2
0
 def test_delete_last_and_only_post_in_thread(self):
     """Deleting the only post in a thread should delete the thread"""
     doc = Document.objects.get(pk=1)
     thread = Thread(title="test", document=doc, creator_id=118533)
     thread.save()
     post = Post(thread=thread, content="test", creator=thread.creator)
     post.save()
     eq_(1, thread.post_set.count())
     post.delete()
     eq_(0, Thread.objects.filter(pk=thread.id).count())
Beispiel #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'])
        else:
            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
    })