def validate_train_id(self, field): a = mydb.train_get() a.train_id = field.data if not a.find(field.data): raise ValidationError("Train doesn't exisit") if not a.delete_train(): raise ValidationError("Failed to delete train")
def build_finish(): if request.method == 'POST': print(request.form) train_id = request.form['train_id'] train_id = train_id[0:len(train_id) - 1] train_name = request.form['train_name'] train_name = train_name[0:len(train_name) - 1] list_seat = json.loads(request.form['seat_list']) station_num = int(request.form['inputlen']) num_price = len(list_seat) a = mydb.train_get() a.train_id = train_id a.name = train_name a.catalog = request.form['catalog'] # print(station_num, num_price) # print(type(station_num), type(num_price)) a.generate_list(station_num, num_price) for i in range(0, num_price): a.ticket_name[i] = list_seat[i] for i in range(1, station_num + 1): a.station_name[i - 1] = request.form['loca' + str(i)] a.start_time[i - 1] = request.form['begintime' + str(i)] a.arriv_time[i - 1] = request.form['endtime' + str(i)] a.stopover_time[i - 1] = request.form['overtime' + str(i)] for j in range(0, num_price): a.price[i - 1][j] = request.form['seat' + str(i) + str(j)] # a.arriv_time[i] = re # a. print("num:", a.num_price, a.num_station) a.add_train() flash("You build a train successfully") return redirect((url_for('.build_train')))
def validate_train_id(self, field): a = mydb.train_get() a.train_id = field.data print("this:", a.train_id) # print(a.find(field.data)) if a.find(field.data): flash("Train exisits")