def add_place(): city = request.form.get('add_city') district = request.form.get('add_district') places = Place(city, district).get_objects() if len(places) == 0: Place(city, district).save() return redirect(url_for(views.admin_places_page.__name__))
def setUp(self): self.p1 = Place(name='Demon Dogs', address='944 W. Fullerton') self.p1.save() self.p2 = Place(name='Ace Hardware', address='1013 N. Ashland') self.p2.save() self.r = Restaurant(place=self.p1, serves_hot_dogs=True, serves_pizza=False) self.r.save()
def test_find_all(mock, client): p1 = {'name': 'first'} p2 = {'name': 'second'} created1 = Place(**p1) created2 = Place(**p2) mock.return_value = [created1, created2] res = client.get('/places') assert res.status_code == 200 assert 2 == len(json.loads(res.get_data()))
def home(): if "email" not in session: return redirect(url_for("login")) form = AddressForm() places = [] my_coordinates = [37.4221, -122.0844] if request.method == "POST": if not form.validate(): return render_template("home.html", form=form) else: # get address address = form.address.data # query for places p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return results return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places) elif request.method == "GET": return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (66, -99) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) else: address = form.address.data print(address) p = Place() my_coordinates = p.address_to_latlng(address) places = p.get_places(*my_coordinates) return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (33.7489, -84.3789) # Based on the city of Atlanta if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: # get the address address = form.address.data # query for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return those results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
def home(): if 'email' not in session: return redirect(url_for('LogIn')) #return render_template('home.html',email=session['email']) form = AddressForm() places = [] my_coor = (37.4221, -122.0844) if request.method == 'POST': if (form.validate == False): return render_template('home.html', form=form) else: #get address address = form.address.data #use address with api p = Place() my_coor = p.address_to_lat_lon(address) places = p.query(address) #return result return render_template('home.html', form=form, my_coor=my_coor, places=places) elif request.method == 'GET': return render_template('home.html', form=form, my_coor=my_coor, places=places)
def home(): form = AddressForm() places = [] my_coordinates = (34.023076, -118.2870456) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: # get the address address = form.address.data # query for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return those results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (37.4221, -122.0844) if request.method == 'POST': if form.validate() == False: return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places) else: address = form.address.data p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places) if request.method == 'GET': return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places) return render_template("home.html")
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (40.7127750, -74.0059730) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: #get address address = form.address.data #search places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) #return results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places)
def home(): form = AddressForm() places = [] my_coordinates = (37.4221, -122.0844) if 'email' not in session: return redirect(url_for('login')) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: #get the address address = form.address.data #want to use geodata api - make a model (models.py) #query places around address p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def home(): if 'email' not in session: return redirect(url_for("login")) form=AddressForm() places = [] my_coordinates = (30.620949, -96.350764) if request.method=="POST": if form.validate() == False: return render_template("home.html", form=form) else: # get the address address=form.address.data print("Hello") # query for places around it p=Place() my_coordinates = p.address_to_latlng(address) print(my_coordinates) places=p.query(address) # return those results return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places) elif request.method=="GET": return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def home(): #protects the home page, turn off to turn on home if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (0.0000,0.0000) #null island if request.method =="POST": if form.validate == False: return render_template("home.html", form = form) else: #handle form submission #pass address = form.address.data p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) return render_template('home.html',form=form, my_coordinates, places=places) elif request.method == "GET": return render_template('home.html',form=form, my_coordinates, places=places)
def create_place(city_id): ''' Creates a new Place object and saves it to storage ''' city = storage.get("City", city_id) if not city: abort(404) if not request.json: abort(400) return jsonify({"error": "Not a JSON"}) place_dict = request.get_json() if "user_id" not in place_dict: abort(400) return jsonify({"error": "Missing user_id"}) elif "name" not in place_dict: abort(400) return jsonify({"error": "Missing name"}) # Check that user_id is linked to actual User object user_check = storage.get("User", place_dict["user_id"]) if not user_check: abort(404) place_name = place_dict["name"] user_id = place_dict["user_id"] place = Place(name=place_name, user_id=user_id, city_id=city_id) for k, v in place_dict.items(): setattr(place, k, v) place.save() return jsonify(place.to_dict()), 201
def list_events_modified_by_users(self) -> List[Tuple[Event, int]]: self.cursor.execute(self.sql_list_event_modified_by_users) query_result = self.cursor.fetchall() events = [] for event_id, title, poster, short, desc, cost, place_name, \ place_address, place_url, types, source_event_id, user_id in query_result: if types: types = [t for t in types.split(' ')] else: types = [] if cost: cost = [int(c) for c in cost.split(' ')] place = Place(place_name, place_address, place_url) event = Event(title, desc, place, [], "", short_description=short, poster=poster, event_tags=types, cost=cost, event_id=event_id, source_event_id=source_event_id) events.append((event, user_id)) return events
def post_place(city_id): """Creates a Place Args: city_id: id of the city in uuid format Returns: jsonified version of created place """ if storage.get("City", city_id) is None: abort(404) if not request.json: return jsonify({"error": "Not a JSON"}), 400 place_dict = request.get_json() if "user_id" not in place_dict: return jsonify({"error": "Missing user_id"}), 400 if storage.get("User", place_dict["user_id"]) is None: abort(404) if "name" not in place_dict: return jsonify({"error": "Missing name"}), 400 else: p_user_id = place_dict["user_id"] p_name = place_dict["name"] place = Place(user_id=p_user_id, name=p_name, city_id=city_id) for key, value in place_dict.items(): setattr(place, key, value) place.save() return jsonify(place.to_dict()), 201
def map_response_to_place(self, response): # Obligatory fields: try: name = response['name'] id = response['id'] locaction = response['location'] link = response['link'] picture = response['picture'] except (KeyError, TypeError) as e: print( 'ERROR - not all required field are present in the response from the facebook api' ) return None # Compulsory fields: description = self.get_reponse_field(response, 'description') rating = self.get_reponse_field(response, 'overall_star_rating') rating_count = self.get_reponse_field(response, 'rating_count') return Place(name=name, id=id, description=description, location=locaction, link=link, picture=picture, rating=rating, rating_count=rating_count)
def nearby(tid): """Nearby uses flask_wtform and wikipedia apis. Get the address, query for places around it (currently wikipedia, may become locations of tickets), return results. """ tid = tid ticket = Ticket.query.get(tid) pickup_address = ticket.pickup_address pickup_ll = geocoder.google(pickup_address) p_lat, p_lng = pickup_ll.lat, pickup_ll.lng form = AddressForm() places = [] my_coordinates = (p_lat, p_lng) lat_lng = (p_lat, p_lng) if request.method == 'POST': if form.validate() is False: return render_template('nearby.html', form=form, tid=tid, ticket=ticket) else: address = form.address.data p = Place() my_coordinates = p.address_to_latlng(address) places = p.main(address) return render_template('nearby.html', form=form, places=places, my_coordinates=my_coordinates, tid=tid, lat_lng=lat_lng, ticket=ticket) elif request.method == 'GET': return render_template("nearby.html", form=form, places=places, my_coordinates=my_coordinates, tid=tid, lat_lng=lat_lng, ticket=ticket)
def newPlace(): # check user id, only admin can create points user_id = getUserId(login_session['email']) # add place to database on POST if request.method == 'POST': category = request.form['category'] category_id = getCategoryId(user_id, category) print "adding new point:" print request.form['name'] print request.form['description'] print request.form['lat'] print request.form['lng'] print category_id print request.form['category'] print user_id newPlace = Place(name=request.form['name'], description=request.form['description'], lat=request.form['lat'], lng=request.form['lng'], yelpData='false', category_id=category_id, user_id=user_id) session.add(newPlace) session.commit() # redirect to main page return redirect(url_for('showMainPage')) else: # show forms to create new place on GET return redirect(url_for('showMainPage'))
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (45.975589, 15.060825) if request.method == 'POST': if not form.validate(): return render_template('home.html', form=form) else: # get the address address = form.address.data # query for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return those results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) return render_template('home.html')
def create_place(city_id): ''' creates a place linked to a city using the city id''' try: content = request.get_json() except: return (jsonify({"error": "Not a JSON"}), 400) my_city = storage.get("City", city_id) if my_city is None: abort(404) user_id = content.get("user_id") if user_id is None: return (jsonify({"error": "Missing user_id"}), 400) my_user = storage.get("User", user_id) if my_user is None: abort(404) name = content.get("name") if name is None: return (jsonify({"error": "Missing name"}), 400) new_place = Place() new_place.city_id = my_city.id for key, val in content.items(): setattr(new_place, key, val) new_place.save() return (jsonify(new_place.to_dict()), 201)
def home(id=None): if 'email' not in session: # used to avoid login page if user already login return redirect(url_for('login')) # q = User.query.get(id) user = User.query.filter_by(email=session['email']).first() form = AddressForm() places = [] my_coord = (37.4332, -122.0844) if request.method == 'POST': if form.validate() == False: return render_template("home.html", **dict(user=user, form=form)) else: #get the add address = form.address.data #query for add p = Place() my_coord = p.address_to_latlang(address) places = p.query(address) # return those results return render_template( 'home.html', **dict(user=user, form=form, my_coord=my_coord, places=places)) elif request.method == 'GET': return render_template( "home.html", **dict(user=user, form=form, my_coord=my_coord, places=places)) else: return "else"
def home(): #enable this to have user login and permission # if 'email' not in session: # return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (43.6629, -79.3957) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: # get the address address = form.address.data # query for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return those results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def save_place(self, name, geojson): owner = self.auth.user.auth_id place = Place(name=name, owner=owner, geojson=geojson) place.put() key = str(place.key()) self.session['current_place'] = key return {'key': str(place.key())}
def places_of_a_city(city_id): ''' GET: list all places in a specific city POST: add a place to a specific city ''' my_city = storage.get('City', city_id) if my_city is None: abort(404) if request.method == 'POST': place_dict = request.get_json() if place_dict is None: return 'Not a JSON', 400 if 'user_id' not in place_dict.keys(): return 'Missing user_id', 400 if 'name' not in place_dict.keys(): return 'Missing name', 400 place_dict['city_id'] = city_id try: my_place = Place(**place_dict) my_place.save() except: abort(404) return jsonify(my_place.to_dict()), 201 my_places = [ place.to_dict() for place in storage.all('Place').values() if place.city_id == city_id ] return jsonify(my_places)
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (37.4221, -122.0844) if request.method == "POST": if form.validate() == False: return render_template("home.html", form=form) else: #handle good case # Get the address address = form.address.data # Search for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # Return the results return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places) elif request.method == "GET": return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def test_issue_7276(self): # Regression test for #7276: calling delete() on a model with # multi-table inheritance should delete the associated rows from any # ancestor tables, as well as any descendent objects. place1 = Place(name="Guido's House of Pasta", address='944 W. Fullerton') place1.save_base(raw=True) restaurant = Restaurant(place_ptr=place1, serves_hot_dogs=True, serves_pizza=False) restaurant.save_base(raw=True) italian_restaurant = ItalianRestaurant(restaurant_ptr=restaurant, serves_gnocchi=True) italian_restaurant.save_base(raw=True) ident = ItalianRestaurant.objects.all()[0].id self.assertEqual(Place.objects.get(pk=ident), place1) xx = Restaurant.objects.create(name='a', address='xx', serves_hot_dogs=True, serves_pizza=False) # This should delete both Restuarants, plus the related places, plus # the ItalianRestaurant. Restaurant.objects.all().delete() self.assertRaises(Place.DoesNotExist, Place.objects.get, pk=ident) self.assertRaises(ItalianRestaurant.DoesNotExist, ItalianRestaurant.objects.get, pk=ident)
def home(): if 'email' not in session: #checks to see if logged in or not return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (41.7508, 88.1535) if request.method == 'POST': if form.validate() == False: my_coordinates = (41.7508, 88.1535) return render_template('home.html', form=form, my_coordinates=my_coordinates) else: # get the address address = form.address.data # query for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return those results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def home(): if 'email' not in session: return redirect(url_for('login')) form = AddressForm() places = [] my_coordinates = (37.4221, -122.0844) if request.method == 'POST': if form.validate() == False: return render_template('home.html', form=form) else: # get the address address = form.address.data #address = add # query for places around it p = Place() my_coordinates = p.address_to_latlng(address) places = p.query(address) # return those results return render_template('home.html', form=form, my_coordinates=my_coordinates, places=places) elif request.method == 'GET': return render_template("home.html", form=form, my_coordinates=my_coordinates, places=places)
def create_place(city_id): """ Creates new place. If request body not valid JSON, raises 400 If dict does not contain 'name' key, raise 400 Returns place object with status 201 """ if not request.get_json(): abort(400, "Not a JSON") kwargs = request.get_json() a = storage.get("City", city_id) if a is None: abort(404) if not kwargs.get('user_id'): abort(400, "Missing user_id") if not kwargs.get('name'): abort(400, 'Missing name') a = storage.get("User", kwargs['user_id']) if a is None: abort(404) my_place = Place(city_id=city_id, **kwargs) storage.new(my_place) storage.save() return jsonify(my_place.to_dict()), 201