Exemplo n.º 1
0
def detail(id):
    """
    The individual detail page for gyms that show all of the information
    we have about a gym item.
    """

    gym = db.session.query(Gyms).get(id)
    if gym is None:
        abort(404)
    image = db.session.query(Images).get(gym.pic_id).pic
    gym.name = capwords(gym.name)
    img = unbinary(str(base64.b64encode(image)))

    # Search for the nearest stores.
    stores = db.session.query(Stores).all()
    lat2 = at_get('lat')
    lng2 = at_get('lng')

    lat = lat2(gym)
    lng = lng2(gym)
    store_list = nsmallest(4, stores, lambda x: real_dist(lat, lng, lat2(x), lng2(x)))
    images = []
    for store in store_list:
        s_image = db.session.query(Images).get(store.pic_id).pic
        images.append(unbinary(str(base64.b64encode(s_image))))
    # add some workouts
    workouts = db.session.query(Workouts).filter(or_(Workouts.category == "conditioning exercise")).order_by(func.random()).limit(4).all()

    return render_template('gyms/gymsdetail.html', gym=gym, pic=img, stores=store_list, workouts=workouts, images=images, key=app.config['EMBED_API'])
Exemplo n.º 2
0
def detail(id):
    """
    The individual detail page for stores that show all of the information
    we have about a store item.
    """

    store = db.session.query(Stores).get(id)
    if store is None:
        abort(404)
    store.name = capwords(store.name)
    image = db.session.query(Images).get(store.pic_id).pic
    img = unbinary(str(base64.b64encode(image)))

    # Search for the nearest gyms.
    gyms = db.session.query(Gyms).all()
    lat2 = at_get('lat')
    lng2 = at_get('lng')

    lat = lat2(store)
    lng = lng2(store)
    gym_list = nsmallest(4, gyms, lambda x: real_dist(lat, lng, lat2(x), lng2(x)))
    images = []
    for gym in gym_list:
        g_image = db.session.query(Images).get(gym.pic_id).pic
        images.append(unbinary(str(base64.b64encode(g_image))))
    # add some foods
    foods = db.session.query(Food).order_by(func.random()).limit(4).all()

    return render_template('stores/storesdetail.html', store=store, pic=img, gyms=gym_list, foods=foods, images=images, key=app.config['EMBED_API'])
Exemplo n.º 3
0
def create_item(raw):
    """
    Create a dictionary item that represents the database item with
    some of the spurious things like internal ids and such for 
    presentation and organization on the actual site.  Also do any
    preprocessing like determing the URL for the detail page or processing
    images before being displayed.
    """

    image = db.session.query(Images).get(raw.pic_id).pic
    img = unbinary(str(base64.b64encode(image)))

    # get a dict of all attributes and remove ones we don't care about
    item = vars(raw).copy()  # and don't alter the real thing
    item['name'] = capwords(item['name'])
    item['image'] = img
    item['detail_url'] = "gyms/" + str(item['id'])
    item.pop('_sa_instance_state', None)
    item.pop('phone', None)
    item.pop('pic_id', None)
    item.pop('gid', None)
    item.pop('price_level', None)
    item.pop('lat', None)
    item.pop('lng', None)
    return item
Exemplo n.º 4
0
def detail(id):
    """
    The individual detail page for workouts that show all of the information
    we have about a workout item.
    """

    workout = db.session.query(Workouts).get(id)
    if workout is None:
        abort(404)
    workout.name = capwords(workout.name)

    # calculate number of calories that would be burned off for an average person in an hour
    calorie = workout.met * 62

    foods = []
    query = db.session.query(Food).filter(
        Food.calorie.between(calorie - 50,
                             calorie + 50)).order_by(func.random()).limit(4)
    get_foods = query.all()
    for food in get_foods:
        foods.append(food_create_item(food))

    similar_workouts = []
    workout_query = db.session.query(Workouts).filter(
        Workouts.category == workout.category,
        Workouts.name != workout.name).order_by(func.random()).limit(4)
    for sim_workout in workout_query:
        similar_workouts.append(sim_workout)

    gyms = []
    images = []
    # TODO: Add gyms that have this workouts
    if workout.category == "conditioning exercise":
        gym_query = db.session.query(Gyms).order_by(func.random()).limit(4)
        for gym in gym_query:
            gyms.append(gym)
            image = db.session.query(Images).get(gym.pic_id).pic
            img = unbinary(str(base64.b64encode(image)))
            images.append(img)

    return render_template('workouts/workoutsdetail.html',
                           workout=workout,
                           foods=foods,
                           similar_workouts=similar_workouts,
                           gyms=gyms,
                           images=images)
Exemplo n.º 5
0
def detail(id):
    """
    The individual detail page for foods that show all of the information
    we have about a food item.
    """
    food = db.session.query(Food).get(id)
    if food is None:
        abort(404)
    food.name = capwords(food.name)

    query = db.session.query(Food).filter(Food.aisle == food.aisle,
                                          Food.name != food.name).order_by(
                                              func.random()).limit(4)
    get_foods = query.all()
    similar_foods = [create_item(s) for s in get_foods]

    workout = db.session.query(Workouts).filter(
        or_(Workouts.category == "conditioning exercise",
            Workouts.category == "sports",
            Workouts.category == "bicycling")).order_by(func.random()).limit(4)
    workouts = [item for item in workout]

    stores = []
    images = []
    store_query = db.session.query(Stores).order_by(func.random()).limit(4)
    for store in store_query:
        stores.append(store)
        image = db.session.query(Images).get(store.pic_id).pic
        img = unbinary(str(base64.b64encode(image)))
        images.append(img)

    return render_template('foods/fooddetail.html',
                           food=food,
                           similar_foods=similar_foods,
                           workouts=workouts,
                           stores=stores,
                           images=images)