Beispiel #1
0
def route_index():
    global update_views
    update_views = True
    global param
    global sort_ord
    show_sort = True
    question_headers = connection.return_questions_headers()
    if request.method == 'GET':
        param = request.values.get('param')
        sort_ord = request.values.get('sort_ord')
        print(param, sort_ord)
        if param is None and sort_ord is None:
            update_views = True
            questions_ordered = data_manager.sort_questions('submission_time', 'desc')

            return render_template('index.html', question_headers=question_headers, questions=questions_ordered,
                                   param_display='Submission Time', order_display='Descending', show_sort=show_sort)
        else:
            update_views = True
            questions_ordered = data_manager.sort_questions(param, sort_ord)
            if sort_ord == 'asc':
                order_display = 'Ascending'
            elif sort_ord == 'desc':
                order_display = 'Descending'
            if param == 'submission_time':
                param_display = 'Submission Time'
            elif param == 'title':
                param_display = 'Title'
            elif param == 'vote_number':
                param_display = 'Vote Number'
            elif param == 'view_number':
                param_display = 'View Number'
            return render_template('index.html', question_headers=question_headers, questions=questions_ordered,
                                   order_display=order_display, param_display=param_display, show_sort=show_sort)
Beispiel #2
0
def route_list():
    if 'user_name' not in session:
        return redirect("/")
    user_name = session['user_name']
    order = request.args.get('sort')
    if order is None:
        questions = data_manager.sort_questions("ORDER BY id ASC")
    else:
        questions = data_manager.sort_questions(order)

    is_admin = True if user_name == 'Admin' else False

    return render_template("list.html", is_admin=is_admin, questions=questions)
Beispiel #3
0
def sort():
    if request.args.get('order_by') is None:
        data = data_manager.get_all_questions("submission_time", "DESC")
    else:
        data = data_manager.sort_questions(request.args.get('order_by'),
                                           request.args.get('order_direction'))
    return render_template('list.html', all_questions=data)
Beispiel #4
0
def list_all_questions():
    questions = data_manager.get_questions()
    if request.args.get('order') is not None:
        questions = data_manager.sort_questions(request.args.get('sort'),
                                                request.args.get('order'),
                                                questions)

    return render_template('list.html', questions=questions, link=False)
Beispiel #5
0
def sorting_questions(conditions):
    attribute = fv.remove_parentheses(conditions['attribute'])
    attribute = fv.check_is_not_empty(attribute)
    order = fv.remove_parentheses(conditions['order'])
    order = fv.check_is_not_empty(order)
    if fv.check_conditions_of_sorting(conditions):
        conditions = {'attribute': attribute, 'order': order}
        sorted_data = dm.sort_questions(conditions)
        return sorted_data
    else:
        return []
Beispiel #6
0
def list_all_questions():
    sort_by = ''
    direction = ''
    if request.method == "POST":
        sort_by = request.form.get('sort')
        direction = request.form.get('direction')
        data = data_manager.sort_questions(sort_by, direction)
    else:
        data = data_manager.get_questions()

    return render_template('all_questions.html',
                           questions=data,
                           sort_by=sort_by,
                           direction=direction,
                           searching=True)
Beispiel #7
0
def route_list():
    order_direction = request.form.get("order_direction", "DESC")
    order_by = request.form.get("order_by", "submission_time")
    sorted_questions = dm.sort_questions(order_by, order_direction)
    return render_template('list.html', questions=sorted_questions)