def set_authentication_password(password):
     new_password = generate_password_hash(password=password,
                                           method='pbkdf2:sha256',
                                           salt_length=8)
     password_data = {"secret_password": new_password}
     data.update(password_data)
     update_data(data)
def update_configuration(configuration,
                         form,
                         new_email=False,
                         flash_message=None):
    data = get_data()
    try:
        keys = CONFIG_KEYS[configuration]
    except KeyError:
        return abort(400)
    else:
        new_data = {
            configuration: {
                key:
                form[key].data if key != 'support_email' and new_email is False
                else data[configuration]['support_email']
                for key in keys
            }
        }
        new_configuration = new_data[configuration]
        keys_lst = list(new_configuration.keys())
        values_lst = list(new_configuration.values())
        log_changes(configuration=configuration,
                    new_configuration=new_configuration,
                    keys_lst=keys_lst,
                    values_lst=values_lst)
        data.update(new_data)
        update_data(data)
        flash(flash_message) if flash_message else None
        return redirect(url_for('website_settings.menu', mode='admin'))
def answer_edit(answer_id):
    columns = ['id', 'message', 'question_id']
    answer = data_manager.get_data_by_id(columns, 'answer', answer_id, 'id')
    if request.method == 'GET':
        return render_template("edit_answer.html", answer=answer)
    if request.method == 'POST':
        message = request.form['message']
        data_manager.update_data('message', 'answer', message, answer_id)
        return redirect('/question/' + str(answer[0]['question_id']))
Ejemplo n.º 4
0
def delete_answers_related_to_question(question_id):
    '''
    Deletes answers retated to question from csv
    :param question_id:
    :param filename:
    :return: nothing
    '''
    filename = 'sample_data/answer.csv'
    answers = data_manager.import_data(filename)
    for answer in answers:
        if answer["question_id"] == question_id:
            answers.remove(answer)
        global answer_labels
    data_manager.update_data(filename, answer_data, answers)
def edit_question(question_id):
    if request.method == 'GET':
        columns = ['id', 'title', 'message']
        question_data = data_manager.get_data_by_id(columns, 'question',
                                                    question_id, 'id')
        return render_template('form.html',
                               form_type=2,
                               question_data=question_data)
    if request.method == 'POST':
        title = request.form['title']
        message = request.form['message']
        data_manager.update_data('message', 'question', message, question_id)
        data_manager.update_data('title', 'question', title, question_id)
        return redirect('/question/' + question_id)
Ejemplo n.º 6
0
def handle_support_confirmation(token, email):
    load_token(token=token, salt='support-verify')
    if not any(email):
        return abort(400)
    config_data = get_data()
    try:
        if config_data["contact_configuration"]["support_email"] != email:
            config_data["contact_configuration"]["support_email"] = email
            update_data(config_data)
            flash("This email was successfully set as the support email.")
            return redirect(url_for('home.home_page', category='success'))
        else:
            flash("This email is already set as the support email.")
            return redirect(url_for('home.home_page', category='danger'))
    except KeyError:
        return abort(500)
Ejemplo n.º 7
0
def delete_question(id_):
    '''
    1. Delete question form list of dictionaries
    2. write it to file
    3. Delete answers retated to question from csv
    :param id_: str - id of question record to be deleted
    :param filename: str
    :return: nothing
    '''
    filename = 'sample_data/question.csv'
    questions = data_manager.import_data(filename)
    for question in questions:
        if question["id"] in id_:
            questions.remove(question)
    global QUESTION_LABELS
    data_manager.update_data(filename, QUESTION_LABELS, questions)
    delete_answers_related_to_question(id_)
def edit_comment(comment_id):
    columns = ['id', 'question_id', 'answer_id', 'message', 'edited_count']
    comment = data_manager.get_data_by_id(columns, 'comment', comment_id, 'id')
    if request.method == 'GET':
        return render_template('edit_comment.html', comment=comment)
    elif request.method == 'POST':
        message = request.form['message']
        edited_count = comment[0]['edited_count'] + 1
        data_manager.update_data('message', 'comment', message, comment_id)
        data_manager.update_data('edited_count', 'comment', edited_count,
                                 comment_id)
        if comment[0]['question_id'] is None:
            columns_for_answer = ['id', 'question_id']
            question = data_manager.get_data_by_id(columns_for_answer,
                                                   'answer',
                                                   comment[0]['answer_id'],
                                                   'id')
            return redirect('/question/' + str(question[0]['question_id']))
        else:
            return redirect('/question/' + str(comment[0]['question_id']))
def answer_accept(answer_id):
    columns = ['id', 'message', 'question_id']
    answer = data_manager.get_data_by_id(columns, 'answer', answer_id, 'id')
    data_manager.update_data('answer_state', 'answer', 'accepted', answer_id)
    data_manager.gain_reputation('answer_accept', answer_id)
    return redirect('/question/' + str(answer[0]['question_id']))