--- a/service.py Wed Jun 21 18:25:09 2017 +0300 +++ b/service.py Thu Jun 22 19:01:31 2017 +0300 @@ -60,12 +60,15 @@ from math import ceil trip_length = schedule_entry['trip'].length - schedule_entry['stop'].traveled_distance sign = reduce_schedule(schedule_entry['trip'].concise_schedule(schedule_entry['stop']), trip_length = trip_length) - sign = [tr(place, 'paikat') for place in sign] - sign_representation = ' - '.join(sign) - #if len(sign_representation) > 25: - # k = ceil(len(sign) / 2) - # sign_representation = ' - '.join(sign[:k]) + '\n' + ' - '.join(sign[k:]) - return sign_representation + if sign: + sign = [tr(place, 'paikat') for place in sign] + sign_representation = ' - '.join(sign) + #if len(sign_representation) > 25: + # k = ceil(len(sign) / 2) + # sign_representation = ' - '.join(sign[:k]) + '\n' + ' - '.join(sign[k:]) + return sign_representation + else: + return schedule_entry['trip'].schedule[-1].stop.name @app.route('/pysäkki/<reference>') def bus_stop_schedule(reference): @@ -86,7 +89,7 @@ return render_template( 'stop.html', schedule = schedule, - name = reference + ' ' + tr(bus_stop.name, 'bus_stops'), + name = bus_stop.code + ' ' + tr(bus_stop.name, 'bus_stops'), link_to_map = bus_stop.location.link_to_map, region = bus_stop.region, location = bus_stop.location, @@ -125,11 +128,13 @@ 'trip': schedule_entry['stop'].trip.name, 'night': is_night_time(schedule_entry['time']), 'stop_id': schedule_entry['stop'].stop.reference, + 'stop_code': schedule_entry['stop'].stop.code, 'stop_name': tr(schedule_entry['stop'].stop.name, 'bus_stops'), }) stops_in_cluster = sorted( ({ 'id': stop.reference, + 'code': stop.code, 'name': tr(stop.name, 'bus_stops'), } for stop in cluster.stops), key = lambda stop: (len(stop['id']), stop['id']) @@ -161,7 +166,8 @@ formatted_time = time_representation(stop_time) schedule.append({ 'time': formatted_time, - 'reference': halt.stop.reference, + 'id': halt.stop.reference, + 'code': halt.stop.code, 'region': tr(halt.stop.region or '', 'paikat'), 'name': tr(halt.stop.name, 'bus_stops'), }) @@ -174,7 +180,10 @@ }) used_areas.add(region) sign = reduce_schedule([k['region'] for k in concise_schedule], whole = True, trip_length = trip.length) - sign = [sign[0], sign[-1]] + try: + sign = [sign[0], sign[-1]] + except IndexError: + sign = [trip.schedule[0].stop.name, trip.schedule[-1].stop.name] for entry in concise_schedule: entry['region'] = tr(entry['region'], 'paikat') return render_template('trip.html',