Esempio n. 1
0
def thread_detail(request, thread_id):
    '''
    指定したスレッドを表示する。
    @param thread_id: スレッドID
    '''  
    #表示するスレッド       
    thread = get_object_or_404(Thread, pk=thread_id)
    #コメントの登録処理
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            #コメントを登録
            comment = form.save(commit = False)
            comment.thread = thread
            comment.save()
            form = CommentForm() #フォームの初期化
            return HttpResponseRedirect('')
    else:            
        form = CommentForm()
    #スレッドのコメント
    comment_list = thread.comment_set.all().order_by('id')
    return render_to_response('bbs/thread_detail.html',
                              {'thread': thread,
                               'comment_list': comment_list,
                               'form': form})
Esempio n. 2
0
def thread_detail(request, thread_id):
    '''
    指定したスレッドを表示する。
    @param thread_id: スレッドID
    '''

    user = User.objects.get(id=request.user.id)
    thread = get_object_or_404(Thread, pk=thread_id)
    # コメントをかいたことがある
    wrote = thread.comment_set.filter(id=request.user.id)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit = False)
            comment.thread = thread
            comment.target_user_id = request.user.id
            # 書いた経験がなければ書ける
            if not wrote:
                comment.save()
            form = CommentForm() # initialize form
    else:
        form = CommentForm()
    comment_list = thread.comment_set.all().order_by('id')

    thread_list = Thread.objects.filter(target_user=request.user.id)
    commented_list = Comment.objects.filter(target_user=request.user.id) # answered
    exuser = ExtendUser.objects.get(user=request.user.id) # TODO

    return render_to_response('bbs/thread_detail.html',
    {'thread': thread,
        'user': user,
        'thread_list': thread_list, #最近した質問
        'commented_list': commented_list, #最近した回答
        'comment_list': comment_list,
        'exuser': exuser, # TODO
        'wrote': wrote,
        'form': form})