Esempio n. 1
0
def question(id):
    related_questions = db_questions.Questions().get_ten_related_questions(id)
    db_questions.Questions().add_question_view_count(id)
    question = db_questions.Questions().get_question_by_id(id)
    publish_time = get_past_time(question.publish_time)
    answer_count = db_answers.Answers().get_answer_count(question.question_id)
    questioner = db_users.Users().get_user_by_id(uid=question.questioner_uid)
    question_focus_cnt = db_question_focus.Question_focus().get_question_foucs_count(id)
    answers = db_answers.Answers().get_all_answer(id)
    answer_users = []
    for answer in answers:
        answer_users.append(db_users.Users().get_user_by_id(answer.answer_uid))
    # 合并answers和answer_users
    answers_and_users = []
    for i in range(len(answers)):
        answer_and_user = {
            'uid': answers[i].answer_uid,
            'content': answers[i].content,
            'username': answer_users[i].username,
            'avatar_url': answer_users[i].avatar_url,
            'introduction': answer_users[i].introduction,
            'is_anonymous': answers[i].is_anonymous
        }
        answers_and_users.append(answer_and_user)
    if question:
        topic_ids = db_topic_questions.Topic_question().get_topics_by_id(question_id=question.question_id)
        topics = []
        for topic_id in topic_ids:
            temp_dict = {'topic_id': topic_id, 'name': db_topics.Topics().get_topic_name_by_id(topic_id)}
            topics.append(temp_dict)
        if is_login():
            user = db_users.Users().get_user(session['username'])
            question_focused = db_question_focus.Question_focus().question_focused(id, uid=user.uid)
            if len(related_questions) > 5:
                five_related_questions = related_questions[0:5]
            else:
                five_related_questions = related_questions
            return render_template('login/login-question_detail.html',
                                   question=question,
                                   topics=topics,
                                   user=user,
                                   question_focus_cnt=question_focus_cnt,
                                   questioner=questioner,
                                   answers_and_users=answers_and_users,
                                   publish_time=publish_time,
                                   answer_count=answer_count,
                                   related_questions=five_related_questions,
                                   question_focused=question_focused)
        return render_template('question_detail.html',
                               question=question,
                               topics=topics,
                               question_focus_cnt=question_focus_cnt,
                               questioner=questioner,
                               answers_and_users=answers_and_users,
                               publish_time=publish_time,
                               answer_count=answer_count,
                               related_questions=related_questions)
    return '没有这个问题'
Esempio n. 2
0
File: api.py Progetto: aragak1/whuDa
def get_user_question_by_page(uid, page_num):
    questions = db_questions.Questions().get_questions_by_username_and_page(uid=uid, page_num=page_num, page_size=15)
    datas = []
    for question in questions:
        data = {
            'question_id': question.question_id,
            'title': question.title,
            'reply_count': db_questions.Questions().get_question_reply_count(question.question_id),
            'view_count': question.view_count,
            'focus_count': db_questions.Questions().get_question_focus_count(question_id=question.question_id),
            'publish_time': get_past_time(question.publish_time)
        }
        datas.append(data)
    return json.dumps(datas, ensure_ascii=False)