Example #1
0
def do_directions(request, response):
    # get request parameters
    start_time = get_start_time(request)
    view_mode = request.get('out', 'html')
    engine = request.get('e', 'o')
    force = request.get('f', '')
    try:
        date = datetime.datetime.strptime(request.get('date', ''), '%Y-%m-%d')
    except:
        date = datetime.date.today() + datetime.timedelta(days=1)
        
    # get from and to (hotel name, attraction name or if not found - address)
    [from_place, from_location] = get_place(request, 'from', 'fll')
    [to_place, to_location] = get_place(request, 'to', 'tll')

    # produce data            
    data = itinerary.get_directions(from_place, from_location, to_place, to_location, date, start_time, engine, force)              
    
    # populate the requested view
    if view_mode == 'none':
        view.empty(response);
    elif view_mode == 'json':
        view.to_json(data, response)
    else:
        view.to_html(data, 'directions', request, response)
Example #2
0
def get_rating(hotel, ratings, place_name):
    sight_ratings = [x for x in ratings if x.place_name == place_name]
    sight_rating = None
    if len(sight_ratings) > 0:
        sight_rating = sight_ratings[0]
    else:
        [to_place, to_location] = place.get_by_name(place_name)
        if to_place == None:
            raise Exception(place_name)
        date = datetime.date.today() + datetime.timedelta(days=1)
        time = datetime.time(hour=10, minute=0)
        trip = itinerary.get_directions(hotel, hotel.get_point(), to_place, to_location, date, time, 'o')
            
        if trip.duration != None:
            sight_rating = RatingPart()
            sight_rating.hotel_name = hotel.name
            sight_rating.place_name = to_place.name
            sight_rating.place_name_rus = to_place.name_rus
            sight_rating.duration = trip.duration
            sight_rating.expenses = trip.expenses
            sight_rating.metric = trip.metric
            sight_rating.put()
    return sight_rating