style: apply black and isort formatting across entire codebase

- Standardize quote style (single to double quotes)
- Reorder and group imports alphabetically
- Fix line breaks and indentation for consistency
- Apply PEP 8 formatting standards

Also updated Makefile to exclude both venv and .venv from code quality checks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 19:30:17 +01:00
parent 13f0094743
commit 21c13ca39b
236 changed files with 8450 additions and 6545 deletions

View File

@@ -26,39 +26,39 @@ This script is idempotent when run normally.
"""
import sys
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from pathlib import Path
from typing import Dict, List
from datetime import datetime, timezone, timedelta
from decimal import Decimal
# Add project root to path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from sqlalchemy.orm import Session
from sqlalchemy import select, delete
from app.core.database import SessionLocal
from app.core.config import settings
from app.core.environment import is_production, get_environment
from models.database.user import User
from models.database.vendor import Vendor, VendorUser, Role
from models.database.vendor_domain import VendorDomain
from models.database.vendor_theme import VendorTheme
from models.database.customer import Customer, CustomerAddress
from models.database.product import Product
from models.database.marketplace_product import MarketplaceProduct
from models.database.marketplace_import_job import MarketplaceImportJob
from models.database.order import Order, OrderItem
from models.database.admin import PlatformAlert
from middleware.auth import AuthManager
# =============================================================================
# MODE DETECTION (from environment variable set by Makefile)
# =============================================================================
import os
SEED_MODE = os.getenv('SEED_MODE', 'normal') # normal, minimal, reset
from sqlalchemy import delete, select
from sqlalchemy.orm import Session
from app.core.config import settings
from app.core.database import SessionLocal
from app.core.environment import get_environment, is_production
from middleware.auth import AuthManager
from models.database.admin import PlatformAlert
from models.database.customer import Customer, CustomerAddress
from models.database.marketplace_import_job import MarketplaceImportJob
from models.database.marketplace_product import MarketplaceProduct
from models.database.order import Order, OrderItem
from models.database.product import Product
from models.database.user import User
from models.database.vendor import Role, Vendor, VendorUser
from models.database.vendor_domain import VendorDomain
from models.database.vendor_theme import VendorTheme
SEED_MODE = os.getenv("SEED_MODE", "normal") # normal, minimal, reset
# =============================================================================
# DEMO DATA CONFIGURATION
@@ -147,6 +147,7 @@ THEME_PRESETS = {
# HELPER FUNCTIONS
# =============================================================================
def print_header(text: str):
"""Print formatted header."""
print("\n" + "=" * 70)
@@ -178,6 +179,7 @@ def print_error(text: str):
# SAFETY CHECKS
# =============================================================================
def check_environment():
"""Prevent running demo seed in production."""
@@ -196,9 +198,7 @@ def check_environment():
def check_admin_exists(db: Session) -> bool:
"""Check if admin user exists."""
admin = db.execute(
select(User).where(User.role == "admin")
).scalar_one_or_none()
admin = db.execute(select(User).where(User.role == "admin")).scalar_one_or_none()
if not admin:
print_error("No admin user found!")
@@ -214,6 +214,7 @@ def check_admin_exists(db: Session) -> bool:
# DATA DELETION (for reset mode)
# =============================================================================
def reset_all_data(db: Session):
"""Delete ALL data from database (except admin user)."""
@@ -258,13 +259,14 @@ def reset_all_data(db: Session):
# SEEDING FUNCTIONS
# =============================================================================
def create_demo_vendors(db: Session, auth_manager: AuthManager) -> List[Vendor]:
"""Create demo vendors with users."""
vendors = []
# Determine how many vendors to create based on mode
vendor_count = 1 if SEED_MODE == 'minimal' else settings.seed_demo_vendors
vendor_count = 1 if SEED_MODE == "minimal" else settings.seed_demo_vendors
vendors_to_create = DEMO_VENDORS[:vendor_count]
users_to_create = DEMO_VENDOR_USERS[:vendor_count]
@@ -320,7 +322,9 @@ def create_demo_vendors(db: Session, auth_manager: AuthManager) -> List[Vendor]:
db.add(vendor_user_link)
# Create vendor theme
theme_colors = THEME_PRESETS.get(vendor_data["theme_preset"], THEME_PRESETS["modern"])
theme_colors = THEME_PRESETS.get(
vendor_data["theme_preset"], THEME_PRESETS["modern"]
)
theme = VendorTheme(
vendor_id=vendor.id,
theme_name=vendor_data["theme_preset"],
@@ -355,7 +359,9 @@ def create_demo_vendors(db: Session, auth_manager: AuthManager) -> List[Vendor]:
return vendors
def create_demo_customers(db: Session, vendor: Vendor, auth_manager: AuthManager, count: int) -> List[Customer]:
def create_demo_customers(
db: Session, vendor: Vendor, auth_manager: AuthManager, count: int
) -> List[Customer]:
"""Create demo customers for a vendor."""
customers = []
@@ -367,10 +373,11 @@ def create_demo_customers(db: Session, vendor: Vendor, auth_manager: AuthManager
customer_number = f"CUST-{vendor.vendor_code}-{i:04d}"
# Check if customer already exists
existing_customer = db.query(Customer).filter(
Customer.vendor_id == vendor.id,
Customer.email == email
).first()
existing_customer = (
db.query(Customer)
.filter(Customer.vendor_id == vendor.id, Customer.email == email)
.first()
)
if existing_customer:
customers.append(existing_customer)
@@ -412,19 +419,22 @@ def create_demo_products(db: Session, vendor: Vendor, count: int) -> List[Produc
product_id = f"{vendor.vendor_code}-PROD-{i:03d}"
# Check if this product already exists
existing_product = db.query(Product).filter(
Product.vendor_id == vendor.id,
Product.product_id == product_id
).first()
existing_product = (
db.query(Product)
.filter(Product.vendor_id == vendor.id, Product.product_id == product_id)
.first()
)
if existing_product:
products.append(existing_product)
continue # Skip creation, product already exists
# Check if marketplace product already exists
existing_mp = db.query(MarketplaceProduct).filter(
MarketplaceProduct.marketplace_product_id == marketplace_product_id
).first()
existing_mp = (
db.query(MarketplaceProduct)
.filter(MarketplaceProduct.marketplace_product_id == marketplace_product_id)
.first()
)
if existing_mp:
marketplace_product = existing_mp
@@ -485,6 +495,7 @@ def create_demo_products(db: Session, vendor: Vendor, count: int) -> List[Produc
# MAIN SEEDING
# =============================================================================
def seed_demo_data(db: Session, auth_manager: AuthManager):
"""Seed demo data for development."""
@@ -501,7 +512,7 @@ def seed_demo_data(db: Session, auth_manager: AuthManager):
sys.exit(1)
# Step 3: Reset data if in reset mode
if SEED_MODE == 'reset':
if SEED_MODE == "reset":
print_step(3, "Resetting data...")
reset_all_data(db)
@@ -513,20 +524,13 @@ def seed_demo_data(db: Session, auth_manager: AuthManager):
print_step(5, "Creating demo customers...")
for vendor in vendors:
create_demo_customers(
db,
vendor,
auth_manager,
count=settings.seed_customers_per_vendor
db, vendor, auth_manager, count=settings.seed_customers_per_vendor
)
# Step 6: Create products
print_step(6, "Creating demo products...")
for vendor in vendors:
create_demo_products(
db,
vendor,
count=settings.seed_products_per_vendor
)
create_demo_products(db, vendor, count=settings.seed_products_per_vendor)
# Commit all changes
db.commit()
@@ -558,17 +562,18 @@ def print_summary(db: Session):
print(f" Subdomain: {vendor.subdomain}.{settings.platform_domain}")
# Query custom domains separately
custom_domain = db.query(VendorDomain).filter(
VendorDomain.vendor_id == vendor.id,
VendorDomain.is_active == True
).first()
custom_domain = (
db.query(VendorDomain)
.filter(VendorDomain.vendor_id == vendor.id, VendorDomain.is_active == True)
.first()
)
if custom_domain:
# Try different possible field names (model field might vary)
domain_value = (
getattr(custom_domain, 'domain', None) or
getattr(custom_domain, 'domain_name', None) or
getattr(custom_domain, 'name', None)
getattr(custom_domain, "domain", None)
or getattr(custom_domain, "domain_name", None)
or getattr(custom_domain, "name", None)
)
if domain_value:
print(f" Custom: {domain_value}")
@@ -584,8 +589,12 @@ def print_summary(db: Session):
print(f" Email: {vendor_data['email']}")
print(f" Password: {vendor_data['password']}")
if vendor:
print(f" Login: http://localhost:8000/vendor/{vendor.vendor_code}/login")
print(f" or http://{vendor.subdomain}.localhost:8000/vendor/login")
print(
f" Login: http://localhost:8000/vendor/{vendor.vendor_code}/login"
)
print(
f" or http://{vendor.subdomain}.localhost:8000/vendor/login"
)
print()
print(f"\n🛒 Demo Customer Credentials:")
@@ -600,7 +609,9 @@ def print_summary(db: Session):
print("" * 70)
for vendor in vendors:
print(f" {vendor.name}:")
print(f" Path-based: http://localhost:8000/vendors/{vendor.vendor_code}/shop/")
print(
f" Path-based: http://localhost:8000/vendors/{vendor.vendor_code}/shop/"
)
print(f" Subdomain: http://{vendor.subdomain}.localhost:8000/")
print()
@@ -621,6 +632,7 @@ def print_summary(db: Session):
# MAIN ENTRY POINT
# =============================================================================
def main():
"""Main entry point."""
@@ -647,6 +659,7 @@ def main():
print_header("❌ SEEDING FAILED")
print(f"\nError: {e}\n")
import traceback
traceback.print_exc()
sys.exit(1)