Example #1
0
def edit_factor(id):
    """
    Edit a factor
    """

    add_factor = False

    factor = Factor.query.get_or_404(id)
    form = FactorForm(obj=factor)
    if form.validate_on_submit():
        factor.factor_A = form.factor_A.data
        factor.factor_B = form.factor_B.data
        factor.relation_weight = form.relation_weight.data
        factor.temp_aspect_id = form.temp_aspect_id.data.id
        factor.temp_imp_id = form.temp_imp_id.data.id
        factor.operator_id = form.operator_id.data.id
        factor.factor_C = form.factor_C.data
        factor.factor_D = form.factor_D.data
        factor.notes_A = form.notes_A.data
        factor.notes_B = form.notes_B.data
        factor.notes_C = form.notes_C.data
        factor.notes_D = form.notes_D.data
        factor.notes_relation = form.notes_relation.data

        db.session.add(factor)
        db.session.commit()
        flash('You have successfully edited the new factor.')

        # redirect to the factors page
        return redirect(url_for('auth.list_factors'))

    form.factor_A.data = factor.factor_A
    form.factor_B.data = factor.factor_B
    form.relation_weight.data = factor.relation_weight
    form.temp_aspect_id.data = factor.temp_aspect_id
    form.temp_imp_id.data = factor.temp_imp_id
    form.operator_id.data = factor.operator_id
    form.factor_C.data = factor.factor_C
    form.factor_D.data = factor.factor_D
    form.notes_A.data = factor.notes_A
    form.notes_B.data = factor.notes_B
    form.notes_C.data = factor.notes_C
    form.notes_D.data = factor.notes_D
    form.notes_relation.data = factor.notes_relation
    return render_template('auth/factors/factor.html',
                           add_factor=add_factor,
                           form=form,
                           title="Edit Factor")
Example #2
0
def add_factor():
    """
    Add a factor to the database
    """

    add_factor = True

    form = FactorForm()
    if form.validate_on_submit():
        factor = Factor(
            expert_id=current_user.get_id(),
            factor_A=form.factor_A.data,
            factor_B=form.factor_B.data,
            relation_weight=form.relation_weight.data,
            temp_aspect_id=form.temp_aspect_id.data.id,
            temp_imp_id=form.temp_imp_id.data.id,
            operator_id=form.operator_id.data.id,
            factor_C=form.factor_C.data,
            factor_D=form.factor_D.data,
            notes_A=form.notes_A.data,
            notes_B=form.notes_B.data,
            notes_C=form.notes_A.data,
            notes_D=form.notes_B.data,
            notes_relation=form.notes_relation.data,
        )

        try:
            # add factor to the database
            db.session.add(factor)
            db.session.commit()
            flash('You have successfully added a new factor.')
        except:
            # in case factor name already exists
            flash(
                'Error: Something went wrong with sending your request to the database! Please email [email protected] about this behaviour.'
            )

        # redirect to the factors page
        return redirect(url_for('auth.list_factors'))

    # load factor template
    return render_template('auth/factors/factor.html',
                           add_factor=add_factor,
                           form=form,
                           title='Add Factor')