Beispiel #1
0
def main_page():
    if 'username' in session:
        return render_template('index.html',
                               user_id=util.get_username_id(
                                   session['username']),
                               username=session['username'])
    return render_template('index.html')
Beispiel #2
0
def new_answers(question_id):
    if request.method == 'POST':
        message = request.form['message']
        if 'username' in session:
            data_manager.write_to_answers(
                question_id, message,
                util.get_username_id(session['username']))
        else:
            data_manager.write_to_answers(question_id, message)
        return redirect(url_for('show_questions', question_id=question_id))
    return render_template('new_answer.html', question_id=question_id)
Beispiel #3
0
def add_comment_to_answer(answer_id):
    if request.method == 'POST':
        message = request.form['message']
        if 'username' in session:
            data_manager.comment_for_answer(
                message, answer_id, util.get_username_id(session['username']))
        else:
            data_manager.comment_for_answer(message, answer_id)
        return redirect(
            url_for('show_questions',
                    question_id=util.get_question_id(answer_id)))
    return render_template("comment_for_answer.html", answer_id=answer_id)
Beispiel #4
0
def add_question():
    if request.method == 'POST':
        message = request.form['message']
        title = request.form['title']
        if 'username' in session:
            data_manager.write_to_questions(
                message, title, util.get_username_id(session['username']))
        else:
            data_manager.write_to_questions(message, title)
        question_id = data_manager.generate_id()
        return redirect(url_for('show_questions', question_id=question_id))
    return render_template('add-question.html')
Beispiel #5
0
def main_page():
    if 'username' in session:
        if request.method == 'POST':
            order = request.form['order']
            return render_template('index.html',
                                   table_elements=util.sort_questions(order),
                                   user_id=util.get_username_id(
                                       session['username']),
                                   username=session['username'])
        if request.args:
            search_phrase = request.args.get('phrase')
            util.search_a_phrase(search_phrase)
            return render_template(
                'index.html',
                table_elements=util.search_a_phrase(search_phrase),
                search_phrase=search_phrase,
                user_id=util.get_username_id(session['username']),
                username=session['username'])
        return render_template('index.html',
                               table_elements=util.sort_questions(),
                               user_id=util.get_username_id(
                                   session['username']),
                               username=session['username'])
    else:
        if request.method == 'POST':
            order = request.form['order']
            return render_template('index.html',
                                   table_elements=util.sort_questions(order))
        if request.args:
            search_phrase = request.args.get('phrase')
            util.search_a_phrase(search_phrase)
            return render_template(
                'index.html',
                table_elements=util.search_a_phrase(search_phrase),
                search_phrase=search_phrase)
        return render_template('index.html',
                               table_elements=util.sort_questions())
    return render_template('index.html', table_elements=util.sort_questions())
Beispiel #6
0
def show_questions(question_id):
    util.increase_view(question_id)
    user_id = util.get_user_id_by_question_id(question_id)
    if 'username' in session and user_id != None:
        return render_template(
            'question.html',
            question_elements=sorting_functions.title_and_message(question_id),
            answer_elements=util.answer_elements(),
            question_id=question_id,
            comments=util.comment_elements(),
            question_user=util.get_username_by_id(user_id),
            username=session['username'],
            usr_id=util.get_username_id(session['username']))
    return render_template(
        'question.html',
        question_elements=sorting_functions.title_and_message(question_id),
        answer_elements=util.answer_elements(),
        question_id=question_id,
        comments=util.comment_elements())
Beispiel #7
0
def add_vote(planet):
    user = util.get_username_id(session['username'])
    util.insert_to_votes(planet, user)
    return redirect(url_for('main_page'))