updates
This commit is contained in:
315
Backend/seeders/banner_seeder.py
Normal file
315
Backend/seeders/banner_seeder.py
Normal file
@@ -0,0 +1,315 @@
|
||||
"""
|
||||
Banner Seeder
|
||||
Seeds the database with comprehensive banners for different positions
|
||||
All images are from Unsplash (free stock photos)
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
# Add parent directory to path to import modules
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
from src.shared.config.database import SessionLocal
|
||||
from src.content.models.banner import Banner
|
||||
from src.shared.config.logging_config import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
def get_banner_data():
|
||||
"""Generate comprehensive banner data with Unsplash images"""
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
future_date = now + timedelta(days=365) # Banners active for 1 year
|
||||
|
||||
banners = [
|
||||
# Home Page Banners
|
||||
{
|
||||
'title': 'Welcome to Luxury',
|
||||
'description': 'Experience unparalleled elegance and world-class service at our award-winning hotel. Discover sophisticated rooms, exceptional dining, and modern amenities.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/rooms',
|
||||
'position': 'home',
|
||||
'display_order': 1,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Special Summer Offer',
|
||||
'description': 'Book now and save up to 30% on your summer getaway! Perfect for families, couples, and solo travelers. Limited time offer.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/book',
|
||||
'position': 'home',
|
||||
'display_order': 2,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Fine Dining Experience',
|
||||
'description': 'Savor exquisite cuisine at our Michelin-starred restaurants. Enjoy international flavors, local specialties, and expertly curated wine pairings.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1414235077428-338989a2e8c0?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/services',
|
||||
'position': 'home',
|
||||
'display_order': 3,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Luxury Spa & Wellness',
|
||||
'description': 'Rejuvenate at our world-class spa with personalized treatments, therapeutic massages, steam rooms, saunas, and yoga classes.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1544161515-4ab6ce6db874?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/services',
|
||||
'position': 'home',
|
||||
'display_order': 4,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Business Events & Conferences',
|
||||
'description': 'Host your corporate event in our state-of-the-art facilities. Versatile spaces for intimate meetings to large conferences with cutting-edge technology.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1497366216548-37526070297c?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/contact',
|
||||
'position': 'home',
|
||||
'display_order': 5,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
|
||||
# Rooms Page Banners
|
||||
{
|
||||
'title': 'Luxurious Suites',
|
||||
'description': 'Elegantly designed suites with spacious layouts, separate living areas, marble bathrooms, and private balconies with panoramic views. Smart room controls and premium amenities included.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1618773928121-c32242e63f39?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/rooms',
|
||||
'position': 'rooms',
|
||||
'display_order': 1,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Presidential Suite',
|
||||
'description': 'Ultimate luxury in our exclusive 2,000+ sq ft suite. Features grand living room, formal dining, fully equipped kitchen, private terrace, and personal butler service. Perfect for VIP guests.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1596394516093-501ba68a0ba6?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/rooms',
|
||||
'position': 'rooms',
|
||||
'display_order': 2,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Ocean View Rooms',
|
||||
'description': 'Breathtaking ocean views from private balconies. Spacious rooms with floor-to-ceiling windows, coastal decor, and premium furnishings. Perfect for romantic getaways.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1631049307264-da0ec9d70304?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/rooms',
|
||||
'position': 'rooms',
|
||||
'display_order': 3,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
|
||||
# About Page Banners
|
||||
{
|
||||
'title': 'Our Story',
|
||||
'description': 'Discover our rich heritage spanning three decades. Founded to redefine luxury hospitality, we\'ve grown into an internationally recognized destination with timeless elegance.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1520250497591-112f2f40a3f4?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/about',
|
||||
'position': 'about',
|
||||
'display_order': 1,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Award-Winning Service',
|
||||
'description': 'Recognized globally for exceptional hospitality with prestigious awards including five-star ratings and "Best Luxury Hotel" honors. Our trained team delivers service beyond expectations.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1579621970563-ebec7560ff3e?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/about',
|
||||
'position': 'about',
|
||||
'display_order': 2,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
|
||||
# Contact Page Banner
|
||||
{
|
||||
'title': 'Get in Touch',
|
||||
'description': 'Our friendly team is available 24/7 for reservations, inquiries, and special requests. Reach us by phone, email, or visit our front desk. Concierge assistance available.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1556761175-5973dc0f32e7?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/contact',
|
||||
'position': 'contact',
|
||||
'display_order': 1,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
|
||||
# Services Page Banners
|
||||
{
|
||||
'title': 'Premium Services',
|
||||
'description': 'Enjoy personalized butler service, private airport transfers, VIP lounge access, and priority reservations. Business center, city tours, and special occasion planning available.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1441986300917-64674bd600d8?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/services',
|
||||
'position': 'services',
|
||||
'display_order': 1,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': '24/7 Concierge Service',
|
||||
'description': 'Our dedicated concierge team is available around the clock. We assist with restaurant reservations, event tickets, transportation, exclusive experiences, and special occasions.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1556761175-5973dc0f32e7?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/services',
|
||||
'position': 'services',
|
||||
'display_order': 2,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
|
||||
# Promotional Banners (can be used across pages)
|
||||
{
|
||||
'title': 'Early Bird Special',
|
||||
'description': 'Book 30 days in advance and save 20%! Perfect for travelers who plan ahead. Applies to all room types. Terms and conditions apply.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1564501049412-61c2a3083791?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/book',
|
||||
'position': 'home',
|
||||
'display_order': 6,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Weekend Getaway Package',
|
||||
'description': 'All-inclusive weekend package with luxurious accommodation, daily breakfast, and full spa access. Late checkout included. Available Friday through Sunday.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1590490360182-c33d57733427?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/book',
|
||||
'position': 'home',
|
||||
'display_order': 7,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Honeymoon Package',
|
||||
'description': 'Romantic honeymoon package includes luxurious suite, breakfast in bed, candlelit dinner with champagne, couples spa treatments, and special amenities.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1611892440504-42a792e24d32?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/book',
|
||||
'position': 'home',
|
||||
'display_order': 8,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
|
||||
# Footer/General Banners
|
||||
{
|
||||
'title': 'Join Our Loyalty Program',
|
||||
'description': 'Earn points with every stay. Redeem for free nights, upgrades, dining credits, and spa treatments. Multiple tier levels from Silver to Platinum. Join free today!',
|
||||
'image_url': 'https://images.unsplash.com/photo-1519389950473-47ba0277781c?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/loyalty',
|
||||
'position': 'home',
|
||||
'display_order': 9,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
},
|
||||
{
|
||||
'title': 'Gift Cards Available',
|
||||
'description': 'Give the gift of luxury with our hotel gift cards. Perfect for any occasion. Usable for accommodations, dining, spa, and all services. Never expire. Purchase online or at front desk.',
|
||||
'image_url': 'https://images.unsplash.com/photo-1606761568499-6d2451b23c66?w=1920&h=1080&fit=crop',
|
||||
'link_url': '/gift-cards',
|
||||
'position': 'home',
|
||||
'display_order': 10,
|
||||
'is_active': True,
|
||||
'start_date': now,
|
||||
'end_date': future_date
|
||||
}
|
||||
]
|
||||
|
||||
return banners
|
||||
|
||||
|
||||
def seed_banners(db: Session, clear_existing: bool = False):
|
||||
"""Seed banners into the database"""
|
||||
try:
|
||||
if clear_existing:
|
||||
logger.info('Clearing existing banners...')
|
||||
db.query(Banner).delete()
|
||||
db.commit()
|
||||
|
||||
banners_data = get_banner_data()
|
||||
created_count = 0
|
||||
updated_count = 0
|
||||
|
||||
for banner_data in banners_data:
|
||||
# Check if banner with same title and position already exists
|
||||
existing = db.query(Banner).filter(
|
||||
Banner.title == banner_data['title'],
|
||||
Banner.position == banner_data['position']
|
||||
).first()
|
||||
|
||||
if existing:
|
||||
logger.info(f'Updating existing banner: {banner_data["title"]} ({banner_data["position"]})')
|
||||
# Update existing banner
|
||||
for key, value in banner_data.items():
|
||||
setattr(existing, key, value)
|
||||
existing.updated_at = datetime.now(timezone.utc)
|
||||
updated_count += 1
|
||||
else:
|
||||
logger.info(f'Creating new banner: {banner_data["title"]} ({banner_data["position"]})')
|
||||
# Create new banner
|
||||
banner = Banner(**banner_data)
|
||||
db.add(banner)
|
||||
created_count += 1
|
||||
|
||||
db.commit()
|
||||
logger.info(f'Banner seeding completed! Created: {created_count}, Updated: {updated_count}')
|
||||
return created_count, updated_count
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f'Error seeding banners: {str(e)}', exc_info=True)
|
||||
db.rollback()
|
||||
raise
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function to run the seeder"""
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='Seed banners into the database')
|
||||
parser.add_argument(
|
||||
'--clear',
|
||||
action='store_true',
|
||||
help='Clear existing banners before seeding'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
logger.info('Starting banner seeder...')
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
created, updated = seed_banners(db, clear_existing=args.clear)
|
||||
logger.info(f'Banner seeder completed successfully! Created: {created}, Updated: {updated}')
|
||||
except Exception as e:
|
||||
logger.error(f'Failed to seed banners: {str(e)}', exc_info=True)
|
||||
sys.exit(1)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user