def addspots(): form = SellerForm(request.form) if request.method == 'POST': user = current_user uid = user.uid if form.validate(uid) == False: return render_template('addspots.html', form=form) val_address = form.address.data + "," + form.city.data + "," + form.state.data + " " + str( form.zipcode.data) val_add = validate_address(val_address, gmaps) if val_add: valid_address, valid_city, valid_state, valid_zipcode, valid_latitude, \ valid_longitude = parse_valid_data(val_add) parking_spot = Parking_Spot(uid, valid_address, valid_city, valid_state, valid_zipcode, form.ps_size.data, valid_latitude, valid_longitude) else: flash('Invalid Address') return render_template('addspots.html', form=form) db.session.add(parking_spot) db.session.commit() return redirect(url_for('seller')) return render_template('addspots.html', form=form)
def view_message(message_id): form = ApprovalForm() message = Message.get_message_by_id(message_id, current_user.uid) # Not your message!!! if message is None: return render_template('notallowed.html') if request.method == 'POST': message.approved = 1 # Mark the parking spot as taken parking_spot = Parking_Spot.get_parking_spot_by_id(message.psid) parking_spot.availible = 0 db.session.commit() return redirect(url_for('profile')) # Messages that are already approved should not have the approved field if message.approved: return render_template('view_message.html', form=None, message=message, get_user=User.get_user_name) return render_template('view_message.html', form=form, message=message, get_user=User.get_user_name)
def delete_spot(parking_id): user = current_user parking_spot = Parking_Spot.get_user_parking_spot_by_id( parking_id, user.uid) # Deletes by simply setting the validity to zero parking_spot.validity = 0 db.session.commit() return render_template('delete_spot.html', parking_spot=parking_spot)
def release_spot(parking_id): user = current_user parking_spot = Parking_Spot.get_parking_spot_by_id(parking_id) parking_spot.availible = 1 db.session.commit() approved_messages = user.get_my_messages_by_status(approved=1, expired=0) approved_message = [a for a in approved_messages if a.psid == parking_id] a.expired = True db.session.commit() return redirect(url_for('approved_requests'))
def validate(self, uid): if not Form.validate(self): return False # Looks to see if that parking space is already listed by this user. For now, only allow one parking # space for a seller for one type of car full_address_dict = {'address':self.address.data.title(), 'city':self.city.data.title(), 'state': self.state.data.title(), 'zipcode':self.zipcode.data} if Parking_Spot.spot_exists(uid, full_address_dict): self.address.errors.append("You already added this spot to your garage.") return False return True
def buyer_search(): form = BuyerForm(request.form) if request.method == 'POST': if form.validate() == False: return render_template('buyer_search.html', form=form) val_address = form.address.data + "," + form.city.data + "," + form.state.data + " " + str( form.zipcode.data) val_add = validate_address(val_address, gmaps) if val_add: # Query is unicode. Need to format it in a parseable way lat_lon = tuple(val_add[1]) query = str(lat_lon[0]) + '%' + str(lat_lon[1]) + '%' + str( form.zipcode.data) + '%' + str(val_add[0]) #displaying results. user = current_user uid = user.uid lat_lon, zipcode, search_add = parse_search_query(query) search_results = Parking_Spot.vicinity_search( lat_lon, zipcode, uid) if search_results: center, features = get_mapbox_features(search_results, lat_lon, search_add) features = json.dumps(features) center = json.dumps(center) return render_template('buyer_search_map.html', mapbox_features=features, map_center=center) # When none are found return render_template('buyer_search_results.html', spots=None) #return redirect(url_for('buyer_search_results', query=query)) else: flash('Invalid Address') return render_template('buyer_search.html', form=form) # print("Print here") # print(search_results) # GET request return render_template('buyer_search.html', form=form)
def message(parking_id): form = MessageForm(request.form) user = current_user # Get the information related to this parking spot parking_spot = Parking_Spot.get_parking_spot_by_id(parking_id) if request.method == 'POST': message = Message(user.uid, parking_spot.ownerid, parking_spot.psid, form.message.data) db.session.add(message) db.session.commit() return redirect(url_for('profile')) return render_template('message.html', parking_spot=parking_spot, form=form)
def approved_requests(): #form = ReleaseForm() user = current_user approved_messages = user.get_my_messages_by_status(approved=1, expired=0) if not approved_messages: flash('You have no approved requests!') return redirect(url_for('buyer_profile')) # Get a list of the approved parking spots (psid) approved_spots = [a.psid for a in approved_messages] for i, psid in enumerate(approved_spots): approved_spots[i] = Parking_Spot.get_parking_spot_by_id(psid) return render_template('approved_requests.html', approved_spots=approved_spots, get_user=User.get_user_name)
def buyer_search_results(query): user = current_user uid = user.uid # Parse the query lat_lon, zipcode, search_add = parse_search_query(query) search_results = Parking_Spot.vicinity_search(lat_lon, zipcode, uid) if search_results: center, features = get_mapbox_features(search_results, lat_lon, search_add) features = json.dumps(features) center = json.dumps(center) return render_template('buyer_search_map.html', mapbox_features=features, map_center=center) # When none are found return render_template('buyer_search_results.html', spots=None)
def update_spot(parking_id): form = UpdateParkingSpotForm(request.form) user = current_user parking_spot = Parking_Spot.get_user_parking_spot_by_id( parking_id, user.uid) if request.method == 'POST': val_address = form.address.data + "," + form.city.data + "," + form.state.data + " " + str( form.zipcode.data) val_add = validate_address(val_address, gmaps) if val_add: valid_address, valid_city, valid_state, valid_zipcode, valid_latitude, \ valid_longitude = parse_valid_data(val_add) else: flash('Invalid Address') return render_template('update_spot.html', parking_spot=parking_spot, form=form) parking_spot.address = valid_address parking_spot.city = valid_city parking_spot.state = valid_state parking_spot.zipcode = valid_zipcode parking_spot.size = form.ps_size.data parking_spot.lat = valid_latitude parking_spot.lon = valid_longitude db.session.commit() return redirect(url_for('profile')) if parking_spot: return render_template('update_spot.html', parking_spot=parking_spot, form=form) return render_template('notallowed.html')
def parking(parking_id): user = current_user parking_spot = Parking_Spot.get_user_parking_spot_by_id( parking_id, user.uid) return render_template('parking.html', parking_spot=parking_spot)