Files
orion/scripts/create_landing_page.py
Samir Boulahtit ec4ec045fc feat: complete CMS as fully autonomous self-contained module
Transform CMS from a thin wrapper into a fully self-contained module with
all code living within app/modules/cms/:

Module Structure:
- models/: ContentPage model (canonical location with dynamic discovery)
- schemas/: Pydantic schemas for API validation
- services/: ContentPageService business logic
- exceptions/: Module-specific exceptions
- routes/api/: REST API endpoints (admin, vendor, shop)
- routes/pages/: HTML page routes (admin, vendor)
- templates/cms/: Jinja2 templates (namespaced)
- static/: JavaScript files (admin/vendor)
- locales/: i18n translations (en, fr, de, lb)

Key Changes:
- Move ContentPage model to module with dynamic model discovery
- Create Pydantic schemas package for request/response validation
- Extract API routes from app/api/v1/*/ to module
- Extract page routes from admin_pages.py/vendor_pages.py to module
- Move static JS files to module with dedicated mount point
- Update templates to use cms_static for module assets
- Add module static file mounting in main.py
- Delete old scattered files (no shims - hard errors on old imports)

This establishes the pattern for migrating other modules to be
fully autonomous and independently deployable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 22:42:46 +01:00

228 lines
6.9 KiB
Python
Executable File

#!/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 datetime import UTC, datetime
from sqlalchemy.orm import Session
from app.core.database import SessionLocal
from app.modules.cms.models import ContentPage
from models.database.vendor import Vendor
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(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"""
<h2>About {vendor.name}</h2>
<p>{vendor.description or "Your trusted shopping destination for quality products."}</p>
<h3>Why Choose Us?</h3>
<ul>
<li><strong>Quality Products:</strong> Carefully curated selection</li>
<li><strong>Fast Shipping:</strong> Quick delivery to your door</li>
<li><strong>Great Service:</strong> Customer satisfaction guaranteed</li>
</ul>
<h3>Our Story</h3>
<p>We've been serving customers since 2020, providing exceptional products and service.
Our mission is to make online shopping easy, enjoyable, and reliable.</p>
""",
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(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(" 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(" python scripts/create_landing_page.py")
print(" # Then choose: minimal, modern, or full")
else:
print("\n❌ Failed to create landing page")
sys.exit(1)