Пример #1
0
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)
Пример #2
0
def flight_add():
    if request.method == 'POST':
        plane_no = request.form['plane_no']
        source = request.form['source']
        destination = request.form['destination']
        plane_timing = request.form['plane_timing']
        total_seats = int(request.form['total_seats'])
        seats_booked = int(request.form['seats_booked'])
        airline_name = request.form['airline_name']
        price = int(request.form['price'])

        Flight(plane_no, source, destination, plane_timing, total_seats,
               seats_booked, airline_name, price).save_to_mongo()
        return redirect(url_for(".index"))
    return render_template('flights/new_flight.html')
Пример #3
0
def flight_add():
    if request.method == 'POST':
        location = request.form['location']
        event_time = request.form['event_time']
        total_seats = int(request.form['total_seats'])
        seats_booked = int(request.form['seats_booked'])
        event_name = request.form['event_name']
        price = int(request.form['price'])

        Flight(location,
               event_time,
               total_seats,
               seats_booked,
               event_name,
               price,
               dates={}).save_to_mongo()
        return redirect(url_for(".index"))
    return render_template('flights/new_flight.html')
Пример #4
0
def delete_flight(flight_id):
    Flight.get_by_id(flight_id).delete()
    return redirect(url_for('.index'))
Пример #5
0
def load_flights(airline_name):
    flights = Flight.get_by_airline_id(airline_name)
    return render_template("flights/flights_load.html", flights=flights)
Пример #6
0
def flight_page(flight_id):
    flight = Flight.get_by_id(flight_id)
    return render_template("flights/flight.html", flight=flight)
Пример #7
0
def index():
    flights = Flight.all()
    return render_template('flights/flight_index.html', flights=flights)