This commit completes the migration to a fully module-driven architecture: ## Models Migration - Moved all domain models from models/database/ to their respective modules: - tenancy: User, Admin, Vendor, Company, Platform, VendorDomain, etc. - cms: MediaFile, VendorTheme - messaging: Email, VendorEmailSettings, VendorEmailTemplate - core: AdminMenuConfig - models/database/ now only contains Base and TimestampMixin (infrastructure) ## Schemas Migration - Moved all domain schemas from models/schema/ to their respective modules: - tenancy: company, vendor, admin, team, vendor_domain - cms: media, image, vendor_theme - messaging: email - models/schema/ now only contains base.py and auth.py (infrastructure) ## Routes Migration - Moved admin routes from app/api/v1/admin/ to modules: - menu_config.py -> core module - modules.py -> tenancy module - module_config.py -> tenancy module - app/api/v1/admin/ now only aggregates auto-discovered module routes ## Menu System - Implemented module-driven menu system with MenuDiscoveryService - Extended FrontendType enum: PLATFORM, ADMIN, VENDOR, STOREFRONT - Added MenuItemDefinition and MenuSectionDefinition dataclasses - Each module now defines its own menu items in definition.py - MenuService integrates with MenuDiscoveryService for template rendering ## Documentation - Updated docs/architecture/models-structure.md - Updated docs/architecture/menu-management.md - Updated architecture validation rules for new exceptions ## Architecture Validation - Updated MOD-019 rule to allow base.py in models/schema/ - Created core module exceptions.py and schemas/ directory - All validation errors resolved (only warnings remain) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
228 lines
6.9 KiB
Python
Executable File
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 app.modules.tenancy.models 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)
|