diff --git a/app/bookings/routes.py b/app/bookings/routes.py index 70ade7f94e52700d66e1023bf5ed67087776871d..293918668cc68b8add30afc656ba957304ffc9b7 100644 --- a/app/bookings/routes.py +++ b/app/bookings/routes.py @@ -12,5 +12,5 @@ def redirect_index(): @bp.route('/listings') def listings(): - all_listings = Listings.get_all_listings() - return render_template('bookings/listings.html', all_listings=all_listings) + top_listings = Listings.get_top_listings(5) + return render_template('bookings/listings.html', top_listings=top_listings) diff --git a/app/models/listings.py b/app/models/listings.py index 423a2e30340efad9cccd63bf099bb1e137231353..3a51845608f4c391273f3f7690a665a2c1899756 100644 --- a/app/models/listings.py +++ b/app/models/listings.py @@ -29,9 +29,17 @@ class Listings(db.Model): business_tickets=business_tickets, economy_tickets=economy_tickets) - # Add the new flight to the session and commit + # Add the new flight to the database and commit db.session.add(new_flight) db.session.commit() return new_flight - #return cls.query.all() + #return cls.query.all() + + @classmethod + def get_top_listings(cls, amount_of_listings = 5): + return cls.query.order_by( + cls.economy_tickets, + cls.business_tickets + ).limit(amount_of_listings).all() + \ No newline at end of file diff --git a/app/static/listings_slider.css b/app/static/listings_slider.css new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/templates/base.html b/app/templates/base.html index 77f0c5f2bcabb4b21db4d69f250f79edc2b054e5..983c0b203890328a3c0c36361b55eb17f38a3d21 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -40,10 +40,6 @@ </ul> </li> </ul> - <form class="d-flex"> - <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> - <button class="btn btn-outline-success" type="submit">Search</button> - </form> </div> </div> </nav> diff --git a/app/templates/bookings/listings.html b/app/templates/bookings/listings.html index 47a201fd4ac5bdfdedbdd2ec963d8e0856e5920c..a832f2b4b57fa45d9c11a47db716fedcfc09bc56 100644 --- a/app/templates/bookings/listings.html +++ b/app/templates/bookings/listings.html @@ -1,32 +1,40 @@ {% extends 'base.html' %} - +# Implements CSS Slider from https://swiffyslider.com/docs/ {% block content %} + <head> + <!-- <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='listings.css')}}"> --> + <script src="https://cdn.jsdelivr.net/npm/swiffy-slider@1.6.0/dist/js/swiffy-slider.min.js" crossorigin="anonymous" defer></script> + <link href="https://cdn.jsdelivr.net/npm/swiffy-slider@1.6.0/dist/css/swiffy-slider.min.css" rel="stylesheet" crossorigin="anonymous"> + </head> <div class="content"> - <div class="content"> - <p>{{all_listings}}</p> - <h1>All Listings</h1> - <table border="1"> - <thead> - <tr> - {% for column in column_names %} - <th>{{ column.replace('_', ' ').title() }}</th> - {% endfor %} - </tr> - </thead> - <tbody> - {% for listing in all_listings %} - <tr> - {% for column in column_names %} - <td>{{ getattr(listing, column) }}</td> - {% endfor %} - </tr> - {% else %} - <tr> - <td colspan="{{ column_names | length }}">No listings available.</td> - </tr> - {% endfor %} - </tbody> - </table> + <div class="swiffy-slider slider-item-show2 slider-item-reveal slider-nav-outside slider-nav-round slider-nav-visible slider-indicators-outside slider-indicators-round slider-indicators-dark slider-nav-animation slider-nav-animation-fadein slider-item-first-visible"> + <ul class="slider-container py-4"> + {% for listing in top_listings %} + <li class="slide-visible"> + <div class="card shadow h-100"> + <div class="ratio ratio-16x9"> + <img src="../uploads/listing_images/{{listing.}}.jpg" class="card-img-top" loading="lazy" alt="..."> + </div> + <div class="card-body p-3 p-xl-4"> + <h3 class="card-title h5">{{listing.destination_location}}</h3> + <p class="card-text">Add Location description here once implemented</p> + <div><a href="#" class="btn btn-primary">Book now</a> + </div> + </div> + </div> + </li> + {% endfor %} + </ul> + + <button type="button" class="slider-nav" aria-label="Go left"></button> + <button type="button" class="slider-nav slider-nav-next" aria-label="Go left"></button> + + <div class="slider-indicators"> + <button class="active" aria-label="Go to slide"></button> + <button aria-label="Go to slide" class=""></button> + <button aria-label="Go to slide" class=""></button> + <button aria-label="Go to slide" class=""></button> + </div> </div> </div> {% endblock %} \ No newline at end of file