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
def internal_clipper_iframe(): if not (g.session_info.visitor_id or g.session_info.email): return render_template('clipper_iframe_not_logged_in.html') trip_plan_service = serviceimpls.TripPlanService(g.session_info) all_trip_plans = trip_plan_service.get(serviceimpls.TripPlanGetRequest()).trip_plans source_url = trip_plan_creator.canonicalize_url(request.values.get('url')) current_trip_plan = None for trip_plan in all_trip_plans: if trip_plan.source_url == source_url: current_trip_plan = trip_plan break if not current_trip_plan: admin_service = serviceimpls.AdminService(g.session_info) parse_request = serviceimpls.ParseTripPlanRequest(url=source_url, augment_entities=False) parse_response = admin_service.parsetripplan(parse_request) current_trip_plan = parse_response.trip_plan all_trip_plans.append(current_trip_plan) def comp(x, y): if x is current_trip_plan: return -1 if y is current_trip_plan: return 1 return x.compare(y) sorted_trip_plans = sorted(all_trip_plans, cmp=comp) return render_template('internal_clipper_iframe.html', all_trip_plans_json=serializable.to_json_str(sorted_trip_plans), all_datatype_values=values.ALL_VALUES)
def clipper_iframe(): if not (g.session_info.visitor_id or g.session_info.email): return render_template('clipper_iframe_not_logged_in.html') trip_plan_service = serviceimpls.TripPlanService(g.session_info) all_trip_plans = trip_plan_service.get(serviceimpls.TripPlanGetRequest()).trip_plans or [] sorted_trip_plans = sorted(all_trip_plans, cmp=lambda x, y: x.compare(y)) return render_template('clipper_iframe.html', all_trip_plans_json=serializable.to_json_str(sorted_trip_plans), all_datatype_values=values.ALL_VALUES)
def admin_editor(trip_plan_id): if not g.session_info.is_admin(): return '', 404 trip_plan_service = serviceimpls.TripPlanService(g.session_info) trip_plan = trip_plan_service.get(serviceimpls.TripPlanGetRequest([trip_plan_id])).trip_plans[0] entity_service = serviceimpls.EntityService(g.session_info) entities = entity_service.get(serviceimpls.EntityGetRequest(trip_plan_id)).entities return render_template('admin_editor.html', trip_plan=trip_plan, entities_json=serializable.to_json_str(entities), all_datatype_values=values.ALL_VALUES, account_info=g.account_info)