def flight_book(flight_id): flights = Flight.get_by_id(flight_id) if request.method == 'POST': plane_no = flights.plane_no price = float(flights.price) tickets = int(request.form['rooms']) date_from = request.form['date-from'] total = price * tickets airline_name = flights.airline_name airline = Airline.get_by_name(airline_name) if flights.total_seats <= tickets: try: Flight.is_flight_full() except UserErrors.UserError as e: return e.message for k, v in flights.dates.items(): tr = 0 if k == date_from: for m in flights.dates[k]: for k, v in m.items(): tr += v if flights.total_seats <= tr: try: Flight.is_flight_full() except UserErrors.UserError as e: return e.message airline.bank_balance += total flights.save_to_mongo() airline.save_to_mongo() order = { "Plane_no": plane_no, "price": price, "tickets": tickets, "total": total } user = User.find_by_email(session['email']) user.orders = {uuid.uuid4().hex: order} user.points_earned += (price / 100) user.save_to_mongo() if date_from in flights.dates: diction = {user.name: tickets} flights.dates[date_from].append(diction) else: summary = {user.name: tickets} flights.dates[date_from] = [] flights.dates[date_from].insert(0, summary) flights.save_to_mongo() return redirect(url_for('users.user_dashboard')) return render_template('flight_book.html', flights=flights)
def delete_flight(flight_id): Flight.get_by_id(flight_id).delete() return redirect(url_for('.index'))
def flight_page(flight_id): flight = Flight.get_by_id(flight_id) return render_template("flights/flight.html", flight=flight)