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)
def get_location(): location_form = LocationForm(csrf_enabled=False) if request.method == 'POST' and location_form.validate(): location = location_form.zip_code.data return redirect(url_for('.show_weather', location=location)) return render_template('index.html', form=location_form)
def new_location(): """ Add a new location """ form = LocationForm(request.form) if request.method == 'POST' and form.validate(): # save the location save_changes('location', Location(), form, new=True) flash('Location created successfully!') return redirect('/') return render_template('new_location.html', form=form)
def edit(id): qry = db_session.query(Location).filter( Location.id==id) location = qry.first() if location: form = LocationForm(formdata=request.form, obj=location) if request.method == 'POST' and form.validate(): # save edits save_changes('location', location, form) flash('Location updated successfully!') return redirect('/') return render_template('edit_location.html', form=form) else: return 'Error loading #{id}'.format(id=id)
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)