#!/usr/bin/env python3 """ Create Landing Page for Vendor This script creates a landing page for a vendor with the specified template. Usage: python scripts/create_landing_page.py """ import sys from pathlib import Path # Add project root to path sys.path.insert(0, str(Path(__file__).parent.parent)) from sqlalchemy.orm import Session from app.core.database import SessionLocal from models.database.vendor import Vendor from models.database.content_page import ContentPage from datetime import datetime, timezone def create_landing_page( vendor_subdomain: str, template: str = "default", title: str = None, content: str = None ): """ Create a landing page for a vendor. Args: vendor_subdomain: Vendor subdomain (e.g., 'wizamart') template: Template to use (default, minimal, modern, full) title: Page title (defaults to vendor name) content: HTML content (optional) """ db: Session = SessionLocal() try: # Find vendor vendor = db.query(Vendor).filter( Vendor.subdomain == vendor_subdomain ).first() if not vendor: print(f"❌ Vendor '{vendor_subdomain}' not found!") return False print(f"✅ Found vendor: {vendor.name} (ID: {vendor.id})") # Check if landing page already exists existing = db.query(ContentPage).filter( ContentPage.vendor_id == vendor.id, ContentPage.slug == "landing" ).first() if existing: print(f"⚠️ Landing page already exists (ID: {existing.id})") print(f" Current template: {existing.template}") # Update it existing.template = template existing.title = title or existing.title if content: existing.content = content existing.is_published = True existing.updated_at = datetime.now(timezone.utc) db.commit() print(f"✅ Updated landing page with template: {template}") else: # Create new landing page landing_page = ContentPage( vendor_id=vendor.id, slug="landing", title=title or f"Welcome to {vendor.name}", content=content or f"""
{vendor.description or 'Your trusted shopping destination for quality products.'}
We've been serving customers since 2020, providing exceptional products and service. Our mission is to make online shopping easy, enjoyable, and reliable.
""", content_format="html", template=template, meta_description=f"Shop at {vendor.name} for quality products and great service", is_published=True, published_at=datetime.now(timezone.utc), show_in_footer=False, show_in_header=False, display_order=0 ) db.add(landing_page) db.commit() db.refresh(landing_page) print(f"✅ Created landing page (ID: {landing_page.id})") print(f" Template: {template}") print(f" Title: {landing_page.title}") # Print access URLs print("\n📍 Access your landing page at:") print(f" Path-based: http://localhost:8000/vendors/{vendor.subdomain}/") print(f" Shop page: http://localhost:8000/vendors/{vendor.subdomain}/shop/") return True except Exception as e: print(f"❌ Error: {e}") db.rollback() return False finally: db.close() def list_vendors(): """List all vendors in the system.""" db: Session = SessionLocal() try: vendors = db.query(Vendor).filter(Vendor.is_active == True).all() if not vendors: print("❌ No active vendors found!") return print("\n📋 Active Vendors:") print("=" * 60) for vendor in vendors: print(f" • {vendor.name}") print(f" Subdomain: {vendor.subdomain}") print(f" Code: {vendor.vendor_code}") # Check if has landing page landing = db.query(ContentPage).filter( ContentPage.vendor_id == vendor.id, ContentPage.slug == "landing" ).first() if landing: print(f" Landing Page: ✅ ({landing.template})") else: print(f" Landing Page: ❌ None") print() finally: db.close() def show_templates(): """Show available templates.""" print("\n🎨 Available Templates:") print("=" * 60) templates = [ ("default", "Clean professional layout with 3-column quick links"), ("minimal", "Ultra-simple centered design with single CTA"), ("modern", "Full-screen hero with animations and features"), ("full", "Maximum features with split-screen hero and stats") ] for name, desc in templates: print(f" • {name:<10} - {desc}") print() if __name__ == "__main__": print("\n" + "=" * 60) print(" VENDOR LANDING PAGE CREATOR") print("=" * 60) # List vendors list_vendors() # Show templates show_templates() # Interactive creation print("📝 Create Landing Page") print("-" * 60) vendor_subdomain = input("Enter vendor subdomain (e.g., wizamart): ").strip() if not vendor_subdomain: print("❌ Vendor subdomain is required!") sys.exit(1) print("\nAvailable templates: default, minimal, modern, full") template = input("Enter template (default): ").strip() or "default" if template not in ["default", "minimal", "modern", "full"]: print(f"⚠️ Invalid template '{template}', using 'default'") template = "default" title = input("Enter page title (optional, press Enter to use default): ").strip() print("\n🚀 Creating landing page...") print("-" * 60) success = create_landing_page( vendor_subdomain=vendor_subdomain, template=template, title=title if title else None ) if success: print("\n✅ SUCCESS! Landing page is ready.") print("\n💡 Try different templates:") print(f" python scripts/create_landing_page.py") print(f" # Then choose: minimal, modern, or full") else: print("\n❌ Failed to create landing page") sys.exit(1)