Ejemplo n.º 1
0
def edit(question_id):
    edit = True
    if request.method == 'POST':
        id = question_id
        # view_number = request.form[]
        # vote_number = request.form[]
        title = request.form['question_title']
        message = request.form['question']
        # image = request.form[]

        questions = connection.get_data('question.csv', PATH)
        index = questions.index([q for q in questions
                                 if q[ID] == question_id][0])
        submission_time = questions[index][TIME]
        questions[index] = [id, submission_time, title, message, "image"]

        connection.save_edited_data(PATH, 'question.csv', questions, 'w')

        return redirect(url_for('question', question_id=question_id))
    else:
        questions = connection.get_data('question.csv', PATH)
        question = [q for q in questions if q[0] == question_id][0]

        return render_template('add_question.html',
                               edit=edit,
                               question_id=question_id,
                               question=question,
                               TITLE=TITLE,
                               CONTENT=CONTENT)
Ejemplo n.º 2
0
def add_answer(question_id):
    if request.method == 'POST':
        answers = connection.get_data('answer.csv', PATH)
        question_data = connection.get_data('question.csv', PATH)
        question = [
            q for q in question_data if question_data[0] == question_id
        ]
        answer = request.form['answer']
        answer_to_save = [question_id, answer]

        answers.append(answer_to_save)
        connection.save_data(PATH, 'answer.csv', answer_to_save, 'a')

        return redirect(url_for('question', question_id=question_id))
    else:
        answers = connection.get_data('answer.csv', PATH)
        question_data = connection.get_data('question.csv', PATH)
        question = [
            q for q in question_data if question_data[0] == question_id
        ]
        answer = [a for a in answers if answers[0] == question_id]
        return render_template(
            'add_answer.html',
            question=question,
            answer=answer,
            question_id=question_id,
        )
Ejemplo n.º 3
0
def read_data(file, id=None):
    if file == "answers":
        question_answers = []
        for answer in connection.get_data(ANSWER_PATH):
            if answer['question_id'] == id:
                question_answers.append(answer)
        return question_answers
    elif file == "questions":
        return connection.get_data(QUESTIONS_PATH, id)
    else:
        print("esti prost ai gresit comanda de fisier")  # de sters la final
Ejemplo n.º 4
0
def question(question_id):
    questions = connection.get_data('question.csv', PATH)
    answers = connection.get_data('answer.csv', PATH)
    for q in questions:
        if question_id == q[0]:
            question = q
    answer = [a for a in answers if a[0] == question_id]
    return render_template('question.html',
                           question=question,
                           question_id=question_id,
                           answer=answer)
Ejemplo n.º 5
0
def add_question():
    if request.method == 'POST':
        id = util.id_generator()
        submission_time = util.get_time()
        # view_number = request.form[]
        # vote_number = request.form[]
        title = request.form['question_title']
        message = request.form['question']
        # image = request.form[]
        questions = connection.get_data('question.csv', PATH)
        data_to_save = [id, submission_time, title, message, "image"]

        # question_to_save = questions.append(data_to_save)

        connection.save_data(PATH, 'question.csv', data_to_save, 'a')
        data = connection.get_data('question.csv', PATH)
        return render_template('list.html', data=data, TITLE=TITLE, ID=ID)

    return render_template('add_question.html')
Ejemplo n.º 6
0
def generate_id(filename):
    max_add = 0
    if filename == "questions":
        filename = QUESTIONS_PATH
    elif filename == "answers":
        filename = ANSWER_PATH
    else:
        print("esti prost ai gresit comanda de fisier")  # de sters la final
    for row in connection.get_data(filename):
        if int(row['id']) > max_add:
            max_add = int(row['id'])
    return max_add + 1
Ejemplo n.º 7
0
def read_answer(id=None):
    return connection.get_data(ANSWER_PATH, id)
Ejemplo n.º 8
0
def delete():
    data = connection.get_data('question.csv', PATH)
    return render_template('list.html', data=data)
Ejemplo n.º 9
0
def list():
    data = connection.get_data('question.csv', PATH)

    return render_template('list.html', data=data, TITLE=TITLE, ID=ID)