Exemplo n.º 1
0
def question(question_id):
    current_question = Question.query.filter(
        Question.id == question_id).first()
    question_form = QuestionForm()
    if question_form.validate_on_submit():
        return validate_question(question_form)
    answer_form = AnswerForm()
    if answer_form.validate_on_submit():
        return validate_answer(answer_form=answer_form,
                               question_id=question_id)

    users_in_db = User.query.all()
    answers_in_db = Answer.query.filter(Answer.question_id == question_id)
    answer_ids = []
    for answer in answers_in_db:
        answer_ids.append(answer.id)
    answers = get_answers(answer_ids=answer_ids)

    return render_template('question.html',
                           username=session.get('USERNAME'),
                           question_form=question_form,
                           question=current_question,
                           answer_form=answer_form,
                           answers=answers,
                           user_id=session.get('USERID'),
                           users=users_in_db)
Exemplo n.º 2
0
def root():
    question_form = QuestionForm()
    if question_form.validate_on_submit():
        return validate_question(question_form)
    return render_template('index.html',
                           question_form=question_form,
                           username=session.get('USERNAME'))
Exemplo n.º 3
0
def index():
    question_form = QuestionForm()
    session.clear()
    flash('You have logged out!', 'success')
    if question_form.validate_on_submit():
        return validate_question(question_form)
    return render_template('index.html',
                           username=session.get('USERNAME'),
                           question_form=question_form)
Exemplo n.º 4
0
def favorites():
    question_form = QuestionForm()
    if question_form.validate_on_submit():
        return validate_question(question_form)
    viewpoints_in_db = Viewpoint.query.filter(
        Viewpoint.like == True, Viewpoint.user_id == session.get('USERID'))
    answer_ids = []
    for viewpoint in viewpoints_in_db:
        answer_ids.append(viewpoint.answer_id)
    answers = get_answers(answer_ids)
    return render_template('favorites.html',
                           username=session.get('USERNAME'),
                           question_form=question_form,
                           answers=answers,
                           user_id=session.get('USERID'))
Exemplo n.º 5
0
def questions(type):
    question_form = QuestionForm()
    invites_in_db = Invite.query.filter(
        Invite.invitee_id == session.get('USERID'))
    invite_question_ids = []
    for invite in invites_in_db:
        invite_question_ids.append(invite.question_id)
    questions_in_db = Question.query.all()
    my_questions = []
    for question in questions_in_db:
        user = User.query.filter(User.id == question.user_id).first()
        answers_in_db = Answer.query.filter(Answer.question_id == question.id)
        new_question = {
            'id': question.id,
            'username': user.username,
            'title': question.title,
            'description': question.description,
            'answers': answers_in_db.count(),
            'time': question.datetime.strftime("%Y-%m-%d %H:%M:%S")
        }
        if type == 'invitation':
            if question.id in invite_question_ids:
                my_questions.append(new_question)
        else:
            my_questions.append(new_question)
    if question_form.validate_on_submit():
        return validate_question(question_form)
    if type == 'hot':
        my_questions = sorted(my_questions, key=lambda keys: keys['answers'])
        my_questions.reverse()
        return render_template('hot.html',
                               username=session.get('USERNAME'),
                               question_form=question_form,
                               questions=my_questions)
    if type == 'new':
        my_questions = sorted(my_questions, key=lambda keys: keys['time'])
        my_questions.reverse()
        return render_template('new.html',
                               username=session.get('USERNAME'),
                               question_form=question_form,
                               questions=my_questions)
    if type == 'invitation':
        my_questions.reverse()
        return render_template('invitation.html',
                               username=session.get('USERNAME'),
                               question_form=question_form,
                               questions=my_questions)
Exemplo n.º 6
0
def addquestion():
    form = QuestionForm()
    if not session.get("USERNAME") is None:
        if form.validate_on_submit():
            username = session.get("USERNAME")
            user_in_db = User.query.filter(User.username == username).first()

            question_db = Question(title=form.title.data,
                                   body=form.body.data,
                                   anonymity=form.anonymity.data,
                                   user=user_in_db)
            db.session.add(question_db)
            db.session.commit()
            return redirect(url_for('reviewquestions'))
    else:
        flash("User needs to either login or signup first")
        return redirect(url_for('login'))
Exemplo n.º 7
0
def follow():
    question_form = QuestionForm()
    if question_form.validate_on_submit():
        return validate_question(question_form)

    answer_ids = []
    follows_in_db = Follow.query.filter(
        Follow.user_id == session.get('USERID'))
    follow_ids = []
    for follow_item in follows_in_db:
        follow_ids.append(follow_item.followed_id)
    answers_in_db = Answer.query.all()
    for answer in answers_in_db:
        if answer.user_id in follow_ids:
            answer_ids.append(answer.id)

    answers = get_answers(answer_ids=answer_ids)
    return render_template('follow.html',
                           username=session.get('USERNAME'),
                           question_form=question_form,
                           answers=answers,
                           user_id=session.get('USERID'))
Exemplo n.º 8
0
def login():
    question_form = QuestionForm()
    login_form = LoginForm()
    if login_form.validate_on_submit():
        return validate_login(login_form)
    return render_template('login.html', form=login_form)
Exemplo n.º 9
0
def register():
    question_form = QuestionForm()
    register_form = RegisterForm()
    if register_form.validate_on_submit():
        return validate_register(register_form)
    return render_template('register.html', form=register_form)