def questions(qid=None, url=None): questions_dict = {} if qid is None: questions_list = question.get_questions() if g.user is None: return render_template('questions.html', title='Questions', qpage=True, questions=questions_list) elif g.user is not None and g.user.is_authenticated(): return render_template('questions.html', title='Questions', qpage=True, questions=questions_list, fname=g.user.name, user_id=g.user.id) else: return render_template('questions.html', title='Questions', qpage=True, questions=questions_list) else: questions_dict = question.get_question_by_id(qid, questions_dict) if request.referrer == "http://localhost:5000/questions": questions_dict['views'] += 1 elif request.host_url != "http://localhost:5000/": questions_dict['views'] += 1 if g.user is AnonymousUser: return render_template('single_question.html', title='Questions', qpage=True, questions=questions_dict) elif g.user is not None and g.user.is_authenticated(): answerForm = AnswerForm(request.form) if answerForm.validate_on_submit() and request.method == 'POST': answer = {} if 'answers' in questions_dict: answer['aid'] = questions_dict['acount'] + 1 answer['answer'] = answerForm.answer.data answer['poster'] = g.user.id answer['ts'] = int(time()) answer['votes'] = 0 answer['ip'] = request.remote_addr answer['best'] = False questions_dict['acount'] += 1 questions_dict['answers'].append(answer) else: answer['aid'] = 1 answer['answer'] = answerForm.answer.data answer['poster'] = g.user.id answer['ts'] = int(time()) answer['votes'] = 0 answer['ip'] = request.remote_addr answer['best'] = False questions_dict['acount'] = 1 questions_dict['answers'] = [] questions_dict['answers'].append(answer) user = cb.get(str(g.user.id)).value user['rep'] += 4 cb.replace(str(g.user.id), user) qb.replace(str(questions_dict['qid']), questions_dict) return redirect(url_for('questions', qid=questions_dict['qid'], url=questions_dict['content']['url'])) qb.replace(str(questions_dict['qid']), questions_dict) return render_template('single_question.html', title='Questions', qpage=True, questions=questions_dict, form=answerForm, fname=g.user.name, user_id=unicode(g.user.id), gravatar=gravatar32) else: return render_template('single_question.html', title='Questions', qpage=True, questions=questions_dict)
def unanswered(): questions_list = question.get_questions() if g.user is None: return render_template('unanswered.html', title='Unanswered questions', unpage=True, questions=questions_list) elif g.user is not None and g.user.is_authenticated(): return render_template('unanswered.html', title='Unanswered questions', unpage=True, questions=questions_list, fname=g.user.name, user_id=g.user.id) else: return render_template('unanswered.html', title='Unanswered questions', unpage=True, questions=questions_list)
def main(): return render_template("main.html", questions = question.get_questions());