예제 #1
0
def edit(id=0):
    setExits()
    id = cleanRecordID(id)
    if id < 0:
        flash("That is not a valid ID")
        return redirect(g.listURL)
            
    rec = None
    if id > 0:
        rec = Trip.query.get(id)
        if not rec:
            flash(printException("Could not edit that "+g.title + " record. ID="+str(id)+")",'error'))
            return redirect(g.listURL)
    
    form = TripForm(request.form, rec)
    ## choices need to be assigned before rendering the form
    # AND before attempting to validate it
    form.countEvent_ID.choices = getCountEventChoices()
    form.location_ID.choices = getLocationChoices()
    form.traveler_ID.choices = getTravelerChoices()
    form.turnDirection.choices = getTurnDirectionChoices()
    
    if request.method == 'POST' and form.validate():
        if not rec:
            rec = Trip(form.tripCount.data,form.tripDate.data,form.turnDirection.data,form.seqNo.data,form.location_ID.data,form.traveler_ID.data,form.countEvent_ID.data)
            db.session.add(rec)
        form.populate_obj(rec)
        db.session.commit()
        return redirect(g.listURL)
        
    return render_template('genericEditForm.html', rec=rec, form=form)
예제 #2
0
파일: views.py 프로젝트: driftbee/DBdev
def edit_trip(trip_id):
    trip = Trip.query.get_or_404(trip_id)
    if current_user != trip.user:
        abort(403)
    form = TripForm(obj=trip)
    if form.validate_on_submit():
        form.populate_obj(trip)
        db.session.commit()
        flash("Stored '{}'".format(trip.description))
        return redirect(url_for('user', username=current_user.username))
    return render_template('trip_form.html', form=form, title="Edit Trip")
예제 #3
0
def edit(id=0):
    setExits()
    id = cleanRecordID(id)
    if id < 0:
        flash("That is not a valid ID")
        return redirect(g.listURL)

    rec = None
    if id > 0:
        rec = Trip.query.get(id)
        if not rec:
            flash(
                printException(
                    "Could not edit that " + g.title + " record. ID=" +
                    str(id) + ")", 'error'))
            return redirect(g.listURL)

    form = TripForm(request.form, rec)
    ## choices need to be assigned before rendering the form
    # AND before attempting to validate it
    form.countEvent_ID.choices = getCountEventChoices()
    form.location_ID.choices = getLocationChoices()
    form.traveler_ID.choices = getTravelerChoices()
    form.turnDirection.choices = getTurnDirectionChoices()

    if request.method == 'POST' and form.validate():
        if not rec:
            rec = Trip(form.tripCount.data, form.tripDate.data,
                       form.turnDirection.data, form.seqNo.data,
                       form.location_ID.data, form.traveler_ID.data,
                       form.countEvent_ID.data)
            db.session.add(rec)
        form.populate_obj(rec)
        db.session.commit()
        return redirect(g.listURL)

    return render_template('genericEditForm.html', rec=rec, form=form)