def location(): form = LocationForm() if form.validate_on_submit(): cityname = form.cityname.data return redirect(url_for('forecast', cityname=cityname)) return render_template('location.html', form=form)
def admin_home(): locform = LocationForm() if locform.validate_on_submit(): ids = request.form.getlist('id') name = request.form.getlist('name') longitude = request.form.getlist('longitude') latitude = request.form.getlist('latitude') type = request.form.getlist('types') for (i, id) in enumerate(ids): if id.isdigit(): loc = Location.query.get(id) loc.longitude = longitude[i] loc.latitude = latitude[i] loc.name = name[i] loc.type = type[i].lower() db.session.commit() else: if longitude[i] and latitude[i] and name[i]: loc = Location(float(longitude[i]), float(latitude[i]), name[i], 'N/A', 'N/A') loc.type = type[i].lower() db.session.add(loc) db.session.commit() locations = Location.query.all() type_list = list() for type in location_type._asdict().values(): type_list.append(type.capitalize()) return render_template('admin.html', locations=locations, location_types=type_list, form=locform, username=current_user.username)
def admin_home(): locform = LocationForm() if locform.validate_on_submit() : ids = request.form.getlist('id') name = request.form.getlist('name') longitude = request.form.getlist('longitude') latitude = request.form.getlist('latitude') type = request.form.getlist('types') for (i, id) in enumerate(ids) : if id.isdigit() : loc = Location.query.get(id) loc.longitude = longitude[i] loc.latitude = latitude[i] loc.name = name[i] loc.type = type[i].lower() db.session.commit() else : if longitude[i] and latitude[i] and name[i] : loc = Location(float(longitude[i]), float(latitude[i]), name[i], 'N/A', 'N/A') loc.type = type[i].lower() db.session.add(loc) db.session.commit() locations = Location.query.all() type_list = list() for type in location_type._asdict().values(): type_list.append(type.capitalize()) return render_template('admin.html', locations=locations, location_types=type_list, form=locform, username=current_user.username)
def index(): form = LocationForm() if form.validate_on_submit(): town = form.town.data plz = str(form.plz.data) if not backend.validate_location(town, plz): flash("Der eingegebene Ort ist ungültig.", "alert-error") else: return redirect(url_for("restaurants", town=town, plz=plz)) return render_template("index.html", form=form)
def editlocation(id): user = User.query.get(session['user_id']) locationForm = LocationForm() if locationForm.validate_on_submit(): user.lat = locationForm.lat.data user.lng = locationForm.lng.data user.location = locationForm.loc.data db.session.commit() flash('Location Sucessfully Updated') return redirect(url_for('show', id=user.id)) flash('Previous Location Saved') return redirect(url_for('show', id=user.id))
def weather(): form = LocationForm() weather = dict() if form.validate_on_submit(): return render_template( 'weather.html', form=form, weather=get_weather(city=form.city.data, key=form.weatherbit_api_key.data), banners=get_rtb_banners(), ) return render_template( 'weather.html', form=form, weather=dict(), banners=get_rtb_banners(), )
def addlocation(): form = LocationForm() if form.validate_on_submit() or request.method == 'POST': location = Location(locationName=form.locationName.data, locationAddress=form.locationAddress.data) try: db.session.add(location) db.session.commit() flash('Location has been added.', 'success') return redirect(url_for("locations")) except: flash('Database Error.', 'danger') return redirect(url_for("locations")) return render_template('addlocation.html', title="Locations", form=form, legend='Add New location')
def create_location(): form = LocationForm() if form.validate_on_submit(): location = Location() location.name = form.name.data location.capacity = form.capacity.data location.country = form.country.data location.zipcode = form.zipcode.data location.city = form.city.data location.street = form.street.data location.address_additions = form.address_additions.data location.google_maps_url = form.google_maps_url.data db_session.add(location) db_session.commit() return redirect(url_for('list_locations')) return render_template("admin/create_location.html", form=form)
def updatelocation(locationId): location = Location.query.get_or_404(locationId) form = LocationForm() if form.validate_on_submit() or request.method == 'POST': location.locationName = form.locationName.data location.locationAddress = form.locationAddress.data try: db.session.commit() flash('Location Name has been updated.', 'success') return redirect(url_for("locations")) except: flash('Database Error.', 'danger') return redirect(url_for("locations")) form.locationName.data = location.locationName form.locationAddress.data = location.locationAddress return render_template('addlocation.html', form=form, legend='Update Location')
def maps(): form = LocationForm() if form.validate_on_submit(): coors = [ re.sub(r' ', '\+', str(form.x_coor.data)), re.sub(r' ', '\+', str(form.y_coor.data)) ] # print(form.image) file_name = images.save(form.image.data) # print('Prepocessing') preprocessing(file_name) # print('Done') # print('Processing') # print(form.crs.data) coors = list(processing(file_name, int(form.crs.data))) # print('Done') os.remove(f'./imgtxtenh/{file_name}') os.remove(f'./imgtxtenh/pre_{file_name}') try: response = requests.get( f'https://maps.googleapis.com/maps/api/geocode/json?latlng={coors[0]},{coors[1]}&key=AIzaSyCaRkfQYahP3fTIL31Da9Ppv5rnNWcG1F0' ) # access JSOn content jsonResponse = response.json() coors.append(jsonResponse["results"][0]["formatted_address"]) print(jsonResponse["results"][0]["formatted_address"]) except HTTPError as http_err: print(f'HTTP error occurred: {http_err}') except Exception as err: print(f'Other error occurred: {err}') return render_template('maps.html', title='Google Maps API', form=form, posts=coors) return render_template('maps.html', title='Google Maps API', form=form)
def createLocation(): # define an error variable to be passed through if any errors that need to be prompted to the user occur error= None # initalise the location form location_form = LocationForm() # if the submit button is clicked if request.method == 'POST': # and all wtform validation is successful if location_form.validate_on_submit(): # and the name of the location is not already in use. if Location.query.filter_by(name=location_form.name.data).first() is None: # create an object intance of the location class new_location = Location(location_form.name.data, location_form.coordinates.data, location_form.checkFrequency.data) # add this new record to the locations table and commit to the database db.session.add(new_location) db.session.commit() # redirect the user back to the homepage return redirect(url_for('dashboard.home')) # if wtform validation returns erros else: # prompt login error error="Invalid location name, already defined as a location." # render the add-location template return render_template("locations/add-location.html", location_form=location_form, error=error)