예제 #1
0
def edit_factor(request, pk):
    factor = Factor.objects.get(pk=pk)
    form = FactorForm(request.POST or None, instance=factor)
    if request.method == "POST" and form.is_valid():
        if "cancel" in request.POST:
            return redirect("/lifespan/factor/%s" % pk)
        with reversion.create_revision():
            form.save()
            reversion.set_user(request.user)
            comment = request.POST["comment"] or "Changed factor"
            reversion.set_comment(comment)
            log(request, factor, comment)
            return redirect("/lifespan/factor/%s" % pk)
    ctx = {"factor": factor, "form": form, "action": "Edit"}
    return render_to_response("lifespan/factor_form.html", ctx, context_instance=RequestContext(request))
예제 #2
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")
예제 #3
0
def edit_factor(request, pk):
    factor = Factor.objects.get(pk=pk)
    form = FactorForm(request.POST or None, instance=factor)
    if request.method == "POST" and form.is_valid():
        if "cancel" in request.POST:
            return redirect('/lifespan/factor/%s' % pk)
        with reversion.create_revision():
            form.save()
            reversion.set_user(request.user)
            comment = request.POST['comment'] or "Changed factor"
            reversion.set_comment(comment)
            log(request, factor, comment)
            return redirect('/lifespan/factor/%s' % pk)
    ctx = {'factor': factor, 'form': form, 'action': 'Edit'}
    return render_to_response('lifespan/factor_form.html', ctx,
        context_instance=RequestContext(request))
예제 #4
0
def add_factor(request):
    form = FactorForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        with reversion.create_revision():
            factor = form.save(commit=False)
            form.save()
            if isinstance(request.user, AnonymousUser):
                request.user = User.objects.get(username="******")
            reversion.set_user(request.user)
            comment = "Added factor. %s" % request.POST["comment"] or ""
            reversion.set_comment(comment)
            log(request, factor, comment)
            msg = "Successfully added factor."
            messages.add_message(request, messages.SUCCESS, ugettext(msg))
            return redirect("/lifespan/factor/%s" % factor.pk)
    ctx = {"form": form, "action": "Add"}
    return render_to_response("lifespan/factor_form.html", ctx, context_instance=RequestContext(request))
예제 #5
0
def edit_factor(request, pk):
    factor = Factor.objects.get(pk=pk)
    form = FactorForm(request.POST or None, instance=factor)
    if request.method == "POST" and form.is_valid():
        if "cancel" in request.POST:
            return redirect('/lifespan/factor/%s' % pk)
        with reversion.create_revision():
            form.save()
            reversion.set_user(request.user)
            comment = request.POST['comment'] or "Changed factor"
            reversion.set_comment(comment)
            log(request, factor, comment)
            return redirect('/lifespan/factor/%s' % pk)
    ctx = {'factor': factor, 'form': form, 'action': 'Edit'}
    return render_to_response('lifespan/factor_form.html',
                              ctx,
                              context_instance=RequestContext(request))
예제 #6
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')
예제 #7
0
def add_factor(request):
    form = FactorForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        with reversion.create_revision():
            factor = form.save(commit=False)
            form.save()
            if isinstance(request.user, AnonymousUser):
                request.user = User.objects.get(username="******")
            reversion.set_user(request.user)
            comment = "Added factor. %s" % request.POST['comment'] or ''
            reversion.set_comment(comment)
            log(request, factor, comment)
            msg = "Successfully added factor."
            messages.add_message(request, messages.SUCCESS, ugettext(msg))
            return redirect('/lifespan/factor/%s' % factor.pk)
    ctx = {'form': form, 'action': 'Add'}
    return render_to_response('lifespan/factor_form.html',
                              ctx,
                              context_instance=RequestContext(request))