def station_save(request): route0 = request.POST['route'] routeName = request.POST['routeName'] transportType = request.POST['routeType'] route = eval(route0) routeName = str(routeName) transportType = str(transportType) transport = Transport.objects.get(name=transportType) new_route = Route(route = routeName, transport_type = transport, interval = 0.12, speed = 12, color = "FFFFFFFF", price = 1) new_route.save() for index in range(len(route)): station_1 = route[str(index)] station_name = station_1[0].decode('utf8') station_y = station_1[1] station_x = station_1[2] station_list = list() one_station_list_with_name = Onestation.objects.filter(name=station_name) if not one_station_list_with_name: one_station = Onestation.objects.create(name=station_name, coordinate_x=station_x, coordinate_y=station_y) else: one_station = one_station_list_with_name[0] matrix_index = list() for station_out_bd in Station.objects.all(): matrix_index += [station_out_bd.matrix_index] matrix_index_max = max(matrix_index) + 1 station_in_bd = Station(route=new_route, name=station_name, coordinate_x=station_x, coordinate_y=station_y, matrix_index=matrix_index_max, notstations=True, order=index, one_station=one_station) if station_name == "temporary": station_name = "temporary" + str(index) station_in_bd = Station(route=new_route, name=station_name, coordinate_x=station_x, coordinate_y=station_y, matrix_index=-1, notstations=False, order=index) station_in_bd.save() return HttpResponse('ok')
def new_station_save_in_route(request): name = request.POST['name'] y = request.POST['lat'] x = request.POST['lon'] route_id = request.POST['route_id'] matrix_index = list() for station_out_bd in Station.objects.all(): matrix_index += [station_out_bd.matrix_index] matrix_index_max = max(matrix_index) + 1 new_station = Station(route_id = route_id, name = name, coordinate_x = x, coordinate_y = y, matrix_index = matrix_index_max) new_station.save() return HttpResponse('OK')