def get(self): upload_url = blobstore.create_upload_url('/tripmanager/upload') user,_,url,url_linktext = self.get_user() #get specific trip trip_key = self.request.get('trip_id') tripk = ndb.Key(urlsafe=trip_key) trip = tripk.get() #get id of user for given trip trip_user = tripk.parent().id() #get tracks for trip track_query = Track.query(ancestor=tripk).order(-Track.creation_date) tracks = track_query.fetch(20) #get number of tracks num = len(tracks) #get global statistic for trip stat_query = TrackStatistic.query(ancestor=trip.key).fetch(1) #get blobInfo objects from blob_key bli = [] for track in tracks: bli.append(BlobInfo(track.blob_key)) #get trip cities cities = trip.cities #create list of lon,lat pares for every city cordinates = [] for city in cities: try: city = city.lower().replace(" ", "+") api_url = "http://api.geonames.org/searchJSON?formatted=true&name={0}&maxRows=1&lang=es&username=wsanjaw&style=short".format(city) result = urlfetch.fetch(api_url) cordinates.append(helper.procesCity(result.content)) except: cordinates.append([0,0]) #create template template_values = {'user': user, 'url': url, 'url_linktext': url_linktext,'trip':trip,'upload':upload_url, 'tracks':tracks,'blobs':bli,'num':num,'trip_user':trip_user,'stats':stat_query,'cordinates':cordinates} template = JINJA_ENVIRONMENT.get_template('templates/new/onetrip.html') #set cookie value to this page url self.response.set_cookie('redirect_url', self.request.url) self.response.write(template.render(template_values))
def get(self): upload_url = blobstore.create_upload_url('/tripmanager/upload') user,id,url,url_linktext = self.get_user() tree = self.create_trip_tree(id) #get specific trip trip_key = self.request.get('trip_id') tripk = ndb.Key(urlsafe=trip_key) trip = tripk.get() #get tracks for trip track_query = Track.query(ancestor=tripk).order(-Track.creation_date) tracks = track_query.fetch(20) #get number of tracks num = len(tracks) #get blobInfo objects from blob_key bli = [] for track in tracks: bli.append(BlobInfo(track.blob_key)) #get trip cities cities = trip.cities #create list of lon,lat pares for every city cordinates = [] cities_string = "" for city in cities: if city == cities[-1]: cities_string += str(city) else: cities_string += str(city)+"," city = city.lower().replace(" ", "+") try: api_url = "http://api.geonames.org/searchJSON?formatted=true&name={0}&maxRows=1&lang=es&username=wsanjaw&style=short".format(city) result = urlfetch.fetch(api_url) cordinates.append(helper.procesCity(result.content)) except: cordinates.append([0,0]) #get statistic track_stat_query= TrackStatistic.query(ancestor=tripk) stats = track_stat_query.fetch() #create data for total climb chart and bubble chart climb_data = [] bubble_data = [] for s in stats: climb_data.append([s.name,s.total_climb]) bubble_data.append([s.key.parent().id(),s.name[0:3].upper(),s.total_distance,s.total_climb,"tracks",helper.time_to_sec(s.total_time)]) tags = self.get_all_tags(id) #create template template_values = {'user': user, 'url': url, 'url_linktext': url_linktext,'tree':tree,'trip':trip, 'climb_data':map(json.dumps, climb_data),'bubble_data':map(json.dumps, bubble_data), 'tracks':tracks,'blobs':bli,'num':num,'stats':track_stat_query,'cordinates':cordinates, 'upload':upload_url,'cities':cities_string,'sug_location':tags[0],'sug_type':tags[1],'sug_season':tags[2], 'location':self.get_location_filters(),'type':self.get_type_filters(),'season':self.get_season_filters(), 'trip_loc':[str(x) for x in trip.trip_tags.location],'trip_type':[str(x) for x in trip.trip_tags.type], 'trip_ses':[str(x) for x in trip.trip_tags.season]} template = JINJA_ENVIRONMENT.get_template('templates/new/onetriptrackmanager.html') self.response.write(template.render(template_values))