def edit_ship_post(ship_id): edit_ship_form = EditShip(request.form) ship = get_ship_by_id(ship_id) if not ship: flash("This ship doesn't exist") return redirect(url_for('show_all_ships')) if ship.captain_id != current_user.get_id(): flash('You do not own this ship') return redirect(url_for('show_all_ships')) if ship.departure_time < datetime.datetime.now(): flash('This ship already left') return redirect(url_for('show_all_ships')) intended_departure = edit_ship_form.departure_time.data current_date = datetime.date.today() to_compare = datetime.datetime.combine(current_date, intended_departure) if to_compare < datetime.datetime.now(): flash('The time you have entered has already passed') return redirect(url_for('show_all_ships')) destination = edit_ship_form.destination.data edit_ship_by_id(ship.id, to_compare, destination) flash('Your ship has been updated!') return redirect(url_for('show_all_ships'))
def edit_ship(ship_id): ship = get_ship_by_id(ship_id) if not ship: flash("This ship doesn't exist") return redirect(url_for('show_all_ships')) if ship.captain_id != current_user.get_id(): flash('You do not own this ship') return redirect(url_for('show_all_ships')) if ship.departure_time < datetime.datetime.now(): flash('This ship already left') return redirect(url_for('show_all_ships')) form = EditShip() form.destination.data = ship.destination form.departure_time.data = ship.departure_time.time() return render_template( "edit_ship.html", ship=ship, form=form, )