Пример #1
0
def edit(id=0):
    setExits()
    defaultLoc = {'lat': app.config['LOCATION_DEFAULT_LAT'], 'lng': app.config['LOCATION_DEFAULT_LNG']}
    #LOCATION_DEFAULT_LNG
    #LOCATION_DEFAULT_LAT
    
    id = cleanRecordID(id)
    if id < 0:
        flash("That is not a valid ID")
        return redirect(g.listURL)
            
    g.tripTotalCount = getLocationTripTotal(id)
    rec = None
    if id > 0:
        rec = Location.query.get(id)
        if not rec:
            flash(printException("Could not edit that "+g.title + " record. ID="+str(id)+")",'error'))
            return redirect(g.listURL)
    
    form = LocationForm(request.form, rec)

    if request.method == 'POST' and form.validate():
        if not rec:
            rec = Location(form.locationName.data,g.orgID)
            db.session.add(rec)
        form.populate_obj(rec)
        db.session.commit()
        return redirect(g.listURL)
        
    return render_template('location/location_edit.html', rec=rec, form=form, defaultLoc=defaultLoc)
Пример #2
0
def edit(id=0):
    setExits()
    defaultLoc = {
        'lat': app.config['LOCATION_DEFAULT_LAT'],
        'lng': app.config['LOCATION_DEFAULT_LNG']
    }
    #LOCATION_DEFAULT_LNG
    #LOCATION_DEFAULT_LAT

    id = cleanRecordID(id)
    if id < 0:
        flash("That is not a valid ID")
        return redirect(g.listURL)

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

    form = LocationForm(request.form, rec)

    if request.method == 'POST' and form.validate():
        if not rec:
            rec = Location(form.locationName.data, g.orgID)
            db.session.add(rec)
        form.populate_obj(rec)
        db.session.commit()
        return redirect(g.listURL)

    return render_template('location/location_edit.html',
                           rec=rec,
                           form=form,
                           defaultLoc=defaultLoc)