Example #1
0
def guide_by_id(trip_plan_id):
    trip_plan_service = serviceimpls.TripPlanService(g.session_info)
    entity_service = serviceimpls.EntityService(g.session_info)

    current_trip_plan = trip_plan_service.get(serviceimpls.TripPlanGetRequest([trip_plan_id])).trip_plans[0]
    if current_user and not current_user.is_anonymous() and current_user.email == '*****@*****.**':
        all_trip_plans = []
    else:
        all_trip_plans = trip_plan_service.get(serviceimpls.TripPlanGetRequest()).trip_plans
    entities = entity_service.get(serviceimpls.EntityGetRequest(trip_plan_id)).entities
    sorted_trip_plans = sorted(all_trip_plans, cmp=lambda x, y: x.compare(y))
    allow_editing = current_trip_plan and current_trip_plan.editable_by(g.session_info)
    if allow_editing:
        # We have it we won't use it since there's no shopping cart.
        active_trip_plan = None
    else:
        active_trip_plan = sorted_trip_plans[0] if sorted_trip_plans else None

    active_entities = None 
    if not allow_editing and active_trip_plan:
        active_entities = entity_service.get(
            serviceimpls.EntityGetRequest(active_trip_plan.trip_plan_id)).entities     
    else:
        # We have them but we won't use them since there's no shopping cart.
        pass

    guide_config_for_destination = guide_config.find_most_prominent_nearby_city_config(
        current_trip_plan.location_latlng)
    has_guides = bool(guide_config_for_destination)
    flashed_messages = [data.FlashedMessage(message, category) for category, message in get_flashed_messages(with_categories=True)]

    response_str = render_template('trip_plan.html',
        plan=current_trip_plan,
        entities_json=serializable.to_json_str(entities),
        all_trip_plans=sorted_trip_plans,
        active_trip_plan=active_trip_plan,
        allow_editing=allow_editing,
        account_info=g.account_info,
        bookmarklet_url=constants.BASE_URL + '/bookmarklet.js',
        all_datatype_values=values.ALL_VALUES,
        sample_sites_json=serializable.to_json_str(sample_sites.SAMPLE_SITES),
        has_guides=has_guides,
        guide_config_for_destination=guide_config_for_destination,
        flashed_messages=flashed_messages)

    response = make_response(response_str)
    response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate'
    return response
Example #2
0
def process_cookies():
    if request.path.startswith('/static/') or request.path == '/user/sign-out':
        return
    try:
        old_sessionid = int(request.cookies.get('sessionid'))
    except:
        old_sessionid = None
    visitor_id = cookies.visitor_id_from_token(request.cookies.get('visitor'))
    if not visitor_id:
        visitor_id = old_sessionid or cookies.generate_visitor_id()
        visitor_token = cookies.make_visitor_token(visitor_id)
        @after_this_request
        def set_visitor_cookie(response):
            set_cookie(response, 'visitor', visitor_token)
        if old_sessionid:
            @after_this_request
            def clear_old_sessionid(response):
                clear_cookie(response, 'sessionid')

    old_email = request.cookies.get('email')
    db_user = current_user if not current_user.is_anonymous() else None
    email = db_user.email if db_user else None
    display_name = db_user.display_name if db_user else old_email

    referral_source = request.args.get('source') or request.cookies.get('rsource')
    if request.args.get('source'):
        @after_this_request
        def set_referral_source(response):
            set_cookie(response, 'rsource', request.args.get('source'))
    referral_source_info = request.args.get('sinfo') or request.cookies.get('sinfo')
    if request.args.get('sinfo'):
        @after_this_request
        def set_source_info(response):
            set_cookie(response, 'sinfo', request.args.get('sinfo'))

    g.session_info = data.SessionInfo(email, old_email, visitor_id, db_user,
        referral_source, referral_source_info, experiments.parse_from_cookies(request.cookies))
    display_user = data.DisplayUser(db_user.public_id if db_user else None, display_name, g.session_info.public_visitor_id)
    g.account_info = data.AccountInfo(email, display_user)