def restaurant_all(): filter = "" if request.form['q']: filter = request.form['q'] rest = Restaurants() restaurants = rest.filter(filter) return jsonify(restaurants)
def restaurant_delete(): restaurants = None if request.args['id']: rest = Restaurants() restaurants = rest.filter_geo(request.args['id']) else: restaurants = [{"error": "El id es un campo obligatorio para la eliminación del registro"}] return jsonify(restaurants)
def register(): if request.method == "POST": username = request.form["username"] password = sha256_crypt.hash(request.form["password"]) name = request.form["rest_name"] address = request.form["rest_address"] owner_name = request.form["owner_name"] new_key = randomString(15) new_user = Restaurants(r_username=username, r_password=password, r_name=name, r_adress=address, r_ownername=owner_name, r_key=new_key) db.session.add(new_user) #db.session.commit() app.logger.info("new user registered") ###add basic restaurant settings rest_name = Restaurants.query.filter_by(r_username=username).first() rest_id = rest_name.id for i in range(1, 8): new_day = ReSettings(d_days=i, d_close=1, d_open_time="19:30", d_close_time="23:30", d_freespot_max=20, d_r_id=rest_id) db.session.add(new_day) db.session.commit() return render_template("register.html")
def restaurant_geo(): """ Api de estadisticas por tipo y filtros de busqueda @distancia = distancia en metros default 100 mtrs @lat = Parametro de la latitud del punto central ***Obligatorio*** @lng = Parametro de la longitud del punto central ***Obligatorio*** """ restaurants = None if request.args['lat'] and request.args['lng']: rest = Restaurants() distancia = 100 if request.args['distancia']: distancia = request.args['distancia'] data = [request.args['lat'], request.args['lng'], distancia] restaurants = rest.filter_geo(data) return jsonify(restaurants)
def test_3_Restaurants_delete(self): ''' Testing Deletion of Records on Restaurants ''' food_types = ["Italian", "Italian", None, None, None, None] new_r = Restaurants(u"0003", u"Little Italy 3", u"little_italy", 78701, 1.0000, 1.0000, u"Austin", u"123 f", u"(512)123123", u"$", 3.0, u"test_review", u"Today", 123, u"www.web.com", u"www.web.com/img.jpg", *food_types) self.session_token.add(new_r) self.session_token.commit() rst = self.session_token.query(Restaurants).filter_by( name="Little Italy 3").first() self.session_token.delete(rst) self.session_token.commit() rst = self.session_token.query(Restaurants).filter_by( name="Little Italy 3").first() assert rst is None print("Passed Test3")
def test_2_Restaurants_manual_integrity(self): ''' Testing query data on Restaurants ''' food_types = ["Italian", "Italian", None, None, None, None] new_r = Restaurants(u"0002", u"Little Italy2", u"little_italy", 78701, 1.0000, 1.0000, u"Austin", u"123 f", u"(512)123123", u"$", 3.0, u"test_review", u"Today", 123, u"www.web.com", u"www.web.com/img.jpg", *food_types) self.session_token.add(new_r) self.session_token.commit() restaurant_1 = self.session_token.query(Restaurants).filter_by( name="Little Italy2").first() # test serialize assert isinstance(restaurant_1.to_dict(), dict) # test data types assert not self.session_token.query(Restaurants) is None assert restaurant_1.id == "0002" assert restaurant_1.name == "Little Italy2" assert restaurant_1.location == 78701 assert restaurant_1.lat == 1.0000 assert restaurant_1.long == 1.0000 assert restaurant_1.city == "Austin" assert restaurant_1.price == "$" assert restaurant_1.rating == 3.0 assert restaurant_1.food_type == "Italian" assert restaurant_1.review == "test_review" assert restaurant_1.review_date == "Today" print("Passed Test2")
def restaurant_new(): """ @rating: Number between 0 and 4 @name: Name of the restaurant @site: Url of the restaurant @email: Email of the restaurant @phone: Phone of the restaurant @street: Street of the restaurant @city: City of the restaurant @state: State of the restaurant @lat: Latitude of the restaurant @lng: Longitude of the restaurant :return: Notification of query """ rest = Restaurants() rest.create(request.args) restaurants = [{"success": "El registro de restaurante es satisfactorio"}] return jsonify(restaurants)
def restaurant_edit(): """ @id: Unique Identifier of Restaurant @rating: Number between 0 and 4 @name: Name of the restaurant @site: Url of the restaurant @email: Email of the restaurant @phone: Phone of the restaurant @street: Street of the restaurant @city: City of the restaurant @state: State of the restaurant @lat: Latitude of the restaurant @lng: Longitude of the restaurant :return: Notification of query """ restaurants = None if request.args['id']: rest = Restaurants() restaurants = rest.update(request.args) else: restaurants = [{"error": "El id es un campo obligatorio para la actualización"}] return jsonify(restaurants)
def restaurant_estadisticas(): """ Api de estadisticas por tipo y filtros de busqueda @tipo = 1(Estado, ciudad, raiting), 2(Estado, raiting), 3(Raiting) ***Obligatorio*** @q = Parametro de filtrado por nombre, ciudad, estado, raiting """ filter = "" restaurants = None if request.args: try: tipo = int(request.args['tipo']) try: if request.args['q']: filter = request.args['q'] except: pass rest = Restaurants() restaurants = rest.raiting(tipo, filter) except: restaurants = [{"error": "El tipo de filtro es obligatorio y de valor numerico"}] else: restaurants = [{"error": "No se recibio ningun parametro de filtrado"}] return jsonify(restaurants)
def load_restaurant_info_to_db(restaurant_info): biz_id = restaurant_info["biz_id"] name = restaurant_info["name"] yelp_name = restaurant_info["yelp_name"] avg_rating = float(restaurant_info["avg_rating"]) location = restaurant_info["location"] stars = int(restaurant_info["stars"]) temp_rest_obj = Restaurants(biz_id=biz_id, common_name=name, yelp_name=yelp_name, location=location, avg_yelp_rating=avg_rating, michelin_stars=stars) db.session.add(temp_rest_obj) db.session.commit() print "restaurant info added!"
def create_pos_dicts(biz_id): restaurant = Restaurants.from_biz_id(biz_id) pos_dict = restaurant.determine_pos() return pos_dict