From 90212c25549391e3598e54dd888f3140b83a8070 Mon Sep 17 00:00:00 2001 From: Ethan-clay03 <ethanclay2017@gmail.com> Date: Mon, 10 Feb 2025 20:47:02 +0000 Subject: [PATCH] Adding checkout page --- app/bookings/routes.py | 17 +++++++++++++---- app/templates/bookings/checkout.html | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 app/templates/bookings/checkout.html diff --git a/app/bookings/routes.py b/app/bookings/routes.py index d5ef06a..26b7464 100644 --- a/app/bookings/routes.py +++ b/app/bookings/routes.py @@ -5,6 +5,7 @@ from app import db from app.logger import error_logger from app.main.utils import calculate_discount, pretty_time import json +from datetime import datetime @bp.route('/') @@ -69,9 +70,9 @@ def listing_apply_update(): def checkout(): if not session['checkout_cache']: flash("Please select a booking", 'error') - depart_date = request.args.get('date') - num_seats = request.args.get('seats') - listing_id = request.args.get('listing_id') + depart_date = session['checkout_cache']['depart_date'] + num_seats = session['checkout_cache']['num_seats'] + listing_id = session['checkout_cache']['listing_id'] session['checkout_cache'] = { 'depart_date': depart_date, @@ -79,7 +80,15 @@ def checkout(): 'listing_id': listing_id } - return redirect(url_for('bookings.checkout')) + listing = Listings.search_listing(listing_id) + listing.depart_time = pretty_time(listing.depart_time) + listing.destination_time = pretty_time(listing.destination_time) + + # Parse depart_date as a date object + depart_date_obj = datetime.strptime(depart_date, '%Y-%m-%d') + depart_date_formatted = depart_date_obj.strftime('%d-%m-%Y') + + return render_template('bookings/checkout.html', listing=listing, num_seats=num_seats, depart_date=depart_date_formatted) @bp.route('/payment') def payment(): diff --git a/app/templates/bookings/checkout.html b/app/templates/bookings/checkout.html new file mode 100644 index 0000000..cc8a28e --- /dev/null +++ b/app/templates/bookings/checkout.html @@ -0,0 +1,22 @@ +{% extends 'base.html' %} +{% block content %} +<div class="container mt-5"> + <h2 class="mb-4" style="text-align: center; margin-top: 40px;">Booking Details</h2> + <div class="row"> + <div class="col-md-12"> + <div class="card mb-4"> + <div class="card-body"> + <h2 class="card-title">Summary</h2> + <p><strong>Departure Date:</strong> {{ depart_date }}</p> + <p><strong>Number of Seats:</strong> {{ num_seats }}</p> + <p><strong>Departure Location:</strong> {{ listing.depart_location }}</p> + <p><strong>Departure Time:</strong> {{ listing.depart_time }}</p> + <p><strong>Destination Location:</strong> {{ listing.destination_location }}</p> + <p><strong>Destination Time:</strong> {{ listing.destination_time }}</p> + <p><strong>Total Cost:</strong> £{{ listing.fair_cost * num_seats|int }}</p> + </div> + </div> + </div> + </div> +</div> +{% endblock %} -- GitLab