Exemple #1
0
def reply_list(request):
    """
    自分に来た質問一覧を表示する
    """

    # 自分宛の質問のうち、自分の回答待ちになっている質問を取ってきて時系列に並べる
    reply_list = ReplyList.objects.filter(answerer=request.user, has_replied=False)
    reply_list = QAManager.sort_qa(qa_list=reply_list, reverse=True)

    if reply_list is not None:
        q_manager = QAManager(request.user)
        qa_list = q_manager.reply_state(reply_list=reply_list)
    else:
        qa_list = None

    return render_to_response('question/top_r.html',
                              {'qa_list': qa_list, 'last_login': request.user.last_login},
                              context_instance=RequestContext(request))
Exemple #2
0
def top_default(request, msg=None):
    """
    トップページ
    """

    # 自分の質問
    questions = Question.objects.filter(questioner=request.user)
    # 自分宛の質問リスト
    reply_lists = ReplyList.objects.filter(answerer=request.user)

    if request.method == 'POST':
        form = KeywordSearchForm(request.POST)

        """
        以下の質問をキーワード検索で取ってくる
        * 自分がした質問のタイトル・内容・タグいずれかがキーワードと部分一致
        * 相手から自分へ来た質問のタイトル・内容・タグいずれかがキーワードと部分一致
        * 自分の回答内容がキーワードと部分一致
        * 自分の投稿に対する相手の回答内容がキーワードと部分一致
        """
        if form.is_valid():
            keyword = form.clean()['keyword']
            questions, reply_lists = QAManager.search_keyword(user=request.user, keyword=keyword,
                                                              question=True, reply=True, tag=True)
            result = len(questions) + len(reply_lists)
            msg = '「'+keyword+'」の検索結果: '+str(result)+'件'

    # 自分の質問と自分宛ての質問の状態を調べる
    qa_manager = QAManager(request.user)
    questions = qa_manager.question_state(questions)
    reply_lists = qa_manager.reply_state(reply_lists)

    # 自分と自分宛の質問を結合して時系列に並べる
    qa_list = list()
    qa_list.extend(questions)
    qa_list.extend(reply_lists)
    qa_list = QAManager.sort_qa(qa_list=qa_list, reverse=True)

    return render_to_response('question/top_all.html',
                              {'qa_list': qa_list,
                               'last_login': request.user.last_login, 'msg': msg},
                              context_instance=RequestContext(request))