From 4bf3505fe2ace08c5e7793d28a6f996036ca1437 Mon Sep 17 00:00:00 2001
From: Ethan Clay <Ethan2.Clay@live.uwe.ac.uk>
Date: Tue, 25 Feb 2025 10:30:37 +0000
Subject: [PATCH] Updating and fixing minor bugs

---
 app/__init__.py                             |  5 +++++
 app/bookings/routes.py                      |  3 +++
 app/main/routes.py                          | 10 +++++++---
 app/main/utils.py                           |  3 ++-
 app/templates/admin/reports.html            |  3 +--
 app/templates/bookings/payment_success.html |  2 +-
 app/templates/errors/error.html             |  1 +
 7 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/app/__init__.py b/app/__init__.py
index 6d7ee36..b23450f 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -127,6 +127,7 @@ def create_app(config_class=Config):
             else:
                 auth_logger.debug(f'No role found for user {identity.user.username}.')
 
+
     # Add global template variables
     @app.context_processor
     def set_global_html_variable_values():
@@ -150,6 +151,7 @@ def create_app(config_class=Config):
                 'user_permission': g.user_permission,
                 'super_admin_permission': g.super_admin_permission
             }
+
     
     # Prevent site being loaded using iFrames
     @app.after_request
@@ -157,18 +159,21 @@ def create_app(config_class=Config):
         response.headers['X-Frame-Options'] = 'SAMEORIGIN'
         return response
 
+
     @app.errorhandler(Exception)
     def handle_exception(e):
         app.logger.error(f"Unhandled exception: {e}")
         session['error_message'] = str(e)
         return redirect(url_for('errors.error'))
 
+
     @app.errorhandler(403)
     def handle_exception(e):
         app.logger.debug(f"Unauthorized: {e}")
         session['error_message'] = str(e)
         return redirect(url_for('errors.no_permission'))
 
+
     @app.before_request
     def before_request():
         g.admin_permission = None
diff --git a/app/bookings/routes.py b/app/bookings/routes.py
index b839799..1900123 100644
--- a/app/bookings/routes.py
+++ b/app/bookings/routes.py
@@ -1,4 +1,5 @@
 from flask import render_template, redirect, url_for, request, jsonify, session, flash, g, send_file
+from flask_login import current_user
 from app.bookings import bp
 from app.models import Listings, Bookings, ListingAvailability
 from app import db
@@ -390,6 +391,8 @@ def generate_ticket(id):
 @permission_required(user_permission)
 def get_user_bookings():
     query = db.session.query(Bookings).join(Listings)
+    
+    query = query.filter(Bookings.user_id == current_user.id)
 
     depart_location = request.args.get('depart_location')
     destination_location = request.args.get('destination_location')
diff --git a/app/main/routes.py b/app/main/routes.py
index 9530d1f..90558f2 100644
--- a/app/main/routes.py
+++ b/app/main/routes.py
@@ -27,10 +27,14 @@ def upload_file(filename):
     try:
         upload_folder = os.path.join(os.getcwd(), 'app/uploads')
         file_directory = send_from_directory(upload_folder, f'listing_images/{filename}')
-    except:
-        #Fall back for when image is not associated with a booking
+    except FileNotFoundError as e:
+        app_logger.debug(f"FileNotFoundError: {e}")
         file_directory = send_from_directory(upload_folder, f'listing_images/booking_image_not_found.jpg')
-        app_logger.debug(f"Can't find {filename} within uploads folder")
+    except Exception as e:
+        app_logger.debug(f"General Exception: {e}")
+        file_directory = send_from_directory(upload_folder, f'listing_images/booking_image_not_found.jpg')
+    except OSError as e:
+        pass
     return file_directory
 
 # Should only be used by ajax calls
diff --git a/app/main/utils.py b/app/main/utils.py
index 9aa91c9..dfe9c1c 100644
--- a/app/main/utils.py
+++ b/app/main/utils.py
@@ -1,7 +1,7 @@
 # utils.py
 
 from flask import current_app
-from datetime import time, datetime, date
+from datetime import time, datetime
 from datetime import datetime 
 from fpdf import FPDF
 import barcode
@@ -11,6 +11,7 @@ from io import BytesIO
 import os
 from PIL import Image
 from pystrich.datamatrix import DataMatrixEncoder
+import tempfile 
 
 def allowed_image_files(filename):
     return '.' in filename and filename.rsplit('.', 1)[1].lower() in current_app.config['ALLOWED_EXTENSIONS']
diff --git a/app/templates/admin/reports.html b/app/templates/admin/reports.html
index 0437f90..d782b8f 100644
--- a/app/templates/admin/reports.html
+++ b/app/templates/admin/reports.html
@@ -4,14 +4,13 @@
 <html>
 <head>
     <title>Reporting</title>
-    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
     <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
     <style>
         .chart-container {
             position: relative;
             width: 100%;
             height: 300px;
-            margin-bottom: 30px; /* Margin at the bottom to prevent overlap */
+            margin-bottom: 30px;
         }
         .card h3 {
             text-align: center;
diff --git a/app/templates/bookings/payment_success.html b/app/templates/bookings/payment_success.html
index 5cfb912..5419377 100644
--- a/app/templates/bookings/payment_success.html
+++ b/app/templates/bookings/payment_success.html
@@ -6,7 +6,7 @@
         <p class="lead">Your payment has been processed successfully.</p>
         <p>Click the buttons below to download your receipt and plane ticket:</p>
         <div class="mt-4">
-            <form action="{{ url_for('bookings.generate_receipt', id=id) }}" method="get" class="d-inline">
+            <form action="{{ url_for('bookings.generate_receipt', id=id) }}" method="get" class="d-inline" style="margin-right: 25px;">
                 <button type="submit" class="btn btn-success btn-lg">Download Receipt</button>
             </form>
             <form action="{{ url_for('bookings.generate_ticket', id=id) }}" method="get" class="d-inline">
diff --git a/app/templates/errors/error.html b/app/templates/errors/error.html
index fda2e0f..61e13de 100644
--- a/app/templates/errors/error.html
+++ b/app/templates/errors/error.html
@@ -2,6 +2,7 @@
 <head>
     <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='base.css') }}">
     <script src="https://kit.fontawesome.com/11fd621de6.js" crossorigin="anonymous"></script>
+    <title> HT | Something went wrong </title>
 </head>
 <div class="quandary-div">
     <h1>Something went wrong</h1>
-- 
GitLab