fix(lint): auto-fix ruff violations and tune lint rules
- Auto-fixed 4,496 lint issues (import sorting, modern syntax, etc.) - Added ignore rules for patterns intentional in this codebase: E402 (late imports), E712 (SQLAlchemy filters), B904 (raise from), SIM108/SIM105/SIM117 (readability preferences) - Added per-file ignores for tests and scripts - Excluded broken scripts/rename_terminology.py (has curly quotes) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,22 +13,18 @@ from app.exceptions import WizamartException
|
||||
class CoreException(WizamartException):
|
||||
"""Base exception for core module."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class MenuConfigurationError(CoreException):
|
||||
"""Error in menu configuration."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class SettingsError(CoreException):
|
||||
"""Error in platform settings."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DashboardError(CoreException):
|
||||
"""Error in dashboard operations."""
|
||||
|
||||
pass
|
||||
|
||||
@@ -6,9 +6,9 @@ This is the canonical location for core module models.
|
||||
"""
|
||||
|
||||
from app.modules.core.models.admin_menu_config import (
|
||||
MANDATORY_MENU_ITEMS,
|
||||
AdminMenuConfig,
|
||||
FrontendType,
|
||||
MANDATORY_MENU_ITEMS,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -33,10 +33,10 @@ from sqlalchemy import (
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
from models.database.base import TimestampMixin
|
||||
|
||||
# Import FrontendType and MANDATORY_MENU_ITEMS from the central location
|
||||
from app.modules.enums import FrontendType, MANDATORY_MENU_ITEMS
|
||||
from app.modules.enums import MANDATORY_MENU_ITEMS, FrontendType
|
||||
from models.database.base import TimestampMixin
|
||||
|
||||
|
||||
class AdminMenuConfig(Base, TimestampMixin):
|
||||
|
||||
@@ -11,8 +11,8 @@ Aggregates all admin core routes:
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .admin_dashboard import admin_dashboard_router
|
||||
from .admin_settings import admin_settings_router
|
||||
from .admin_menu_config import router as admin_menu_config_router
|
||||
from .admin_settings import admin_settings_router
|
||||
|
||||
admin_router = APIRouter()
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ from app.modules.core.schemas.dashboard import (
|
||||
PlatformStatsResponse,
|
||||
ProductStatsResponse,
|
||||
StatsResponse,
|
||||
UserStatsResponse,
|
||||
StoreStatsResponse,
|
||||
UserStatsResponse,
|
||||
)
|
||||
from app.modules.core.services.stats_aggregator import stats_aggregator
|
||||
from app.modules.core.services.widget_aggregator import widget_aggregator
|
||||
|
||||
@@ -28,9 +28,9 @@ from app.api.deps import (
|
||||
get_db,
|
||||
)
|
||||
from app.modules.core.services.menu_service import MenuItemConfig, menu_service
|
||||
from app.modules.tenancy.services.platform_service import platform_service
|
||||
from app.modules.enums import FrontendType # noqa: API-007 - Enum for type safety
|
||||
from app.utils.i18n import translate, DEFAULT_LANGUAGE
|
||||
from app.modules.tenancy.services.platform_service import platform_service
|
||||
from app.utils.i18n import DEFAULT_LANGUAGE, translate
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -19,10 +19,9 @@ from app.api.deps import get_current_admin_api
|
||||
from app.core.config import settings as app_settings
|
||||
from app.core.database import get_db
|
||||
from app.exceptions import ResourceNotFoundException
|
||||
from app.modules.tenancy.exceptions import ConfirmationRequiredException
|
||||
from app.modules.core.services.admin_settings_service import admin_settings_service
|
||||
from app.modules.core.services.audit_aggregator import audit_aggregator
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.exceptions import ConfirmationRequiredException
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
AdminSettingCreate,
|
||||
AdminSettingDefaultResponse,
|
||||
@@ -33,6 +32,7 @@ from app.modules.tenancy.schemas.admin import (
|
||||
RowsPerPageResponse,
|
||||
RowsPerPageUpdateResponse,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_settings_router = APIRouter(prefix="/settings")
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -664,7 +664,7 @@ def send_test_email(
|
||||
to_email=request.to_email,
|
||||
to_name=None,
|
||||
subject="Wizamart Platform - Test Email",
|
||||
body_html="""
|
||||
body_html=f"""
|
||||
<html>
|
||||
<body style="font-family: Arial, sans-serif; padding: 20px;">
|
||||
<h2 style="color: #6b46c1;">Test Email from Wizamart</h2>
|
||||
@@ -672,15 +672,12 @@ def send_test_email(
|
||||
<p>If you received this email, your email settings are working correctly!</p>
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 20px 0;">
|
||||
<p style="color: #6b7280; font-size: 12px;">
|
||||
Provider: {provider}<br>
|
||||
From: {from_email}
|
||||
Provider: {app_settings.email_provider}<br>
|
||||
From: {app_settings.email_from_address}
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
""".format(
|
||||
provider=app_settings.email_provider,
|
||||
from_email=app_settings.email_from_address,
|
||||
),
|
||||
""",
|
||||
body_text=f"Test email from Wizamart platform.\n\nProvider: {app_settings.email_provider}\nFrom: {app_settings.email_from_address}",
|
||||
is_platform_email=True,
|
||||
)
|
||||
@@ -702,11 +699,10 @@ def send_test_email(
|
||||
success=True,
|
||||
message=f"Test email sent to {request.to_email}",
|
||||
)
|
||||
else:
|
||||
return TestEmailResponse(
|
||||
success=False,
|
||||
message=email_log.error_message or "Failed to send test email. Check server logs for details.",
|
||||
)
|
||||
return TestEmailResponse(
|
||||
success=False,
|
||||
message=email_log.error_message or "Failed to send test email. Check server logs for details.",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to send test email: {e}")
|
||||
|
||||
@@ -14,7 +14,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_store_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.core.services.platform_settings_service import platform_settings_service
|
||||
from app.modules.core.services.platform_settings_service import (
|
||||
platform_settings_service,
|
||||
)
|
||||
from app.modules.tenancy.services.store_service import store_service
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_optional, get_db, require_menu_access
|
||||
from app.modules.core.utils.page_context import get_admin_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -15,7 +15,11 @@ from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_merchant_from_cookie_or_header, get_current_merchant_optional, get_db
|
||||
from app.api.deps import (
|
||||
get_current_merchant_from_cookie_or_header,
|
||||
get_current_merchant_optional,
|
||||
get_db,
|
||||
)
|
||||
from app.modules.core.utils.page_context import get_context_for_frontend
|
||||
from app.modules.enums import FrontendType
|
||||
from app.templates_config import templates
|
||||
|
||||
@@ -13,8 +13,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_store_from_cookie_or_header, get_db
|
||||
from app.modules.core.utils.page_context import get_store_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ from app.modules.core.schemas.dashboard import (
|
||||
PlatformStatsResponse,
|
||||
ProductStatsResponse,
|
||||
StatsResponse,
|
||||
UserStatsResponse,
|
||||
StoreCustomerStats,
|
||||
StoreDashboardStatsResponse,
|
||||
StoreInfo,
|
||||
@@ -19,6 +18,7 @@ from app.modules.core.schemas.dashboard import (
|
||||
StoreProductStats,
|
||||
StoreRevenueStats,
|
||||
StoreStatsResponse,
|
||||
UserStatsResponse,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -14,7 +14,6 @@ from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# User Statistics
|
||||
# ============================================================================
|
||||
|
||||
@@ -15,13 +15,17 @@ from app.modules.core.services.admin_settings_service import (
|
||||
admin_settings_service,
|
||||
)
|
||||
from app.modules.core.services.auth_service import AuthService, auth_service
|
||||
from app.modules.core.services.menu_service import MenuItemConfig, MenuService, menu_service
|
||||
from app.modules.core.services.menu_discovery_service import (
|
||||
DiscoveredMenuItem,
|
||||
DiscoveredMenuSection,
|
||||
MenuDiscoveryService,
|
||||
menu_discovery_service,
|
||||
)
|
||||
from app.modules.core.services.menu_service import (
|
||||
MenuItemConfig,
|
||||
MenuService,
|
||||
menu_service,
|
||||
)
|
||||
from app.modules.core.services.platform_settings_service import (
|
||||
PlatformSettingsService,
|
||||
platform_settings_service,
|
||||
|
||||
@@ -17,10 +17,12 @@ from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.tenancy.exceptions import InvalidCredentialsException, UserNotActiveException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
InvalidCredentialsException,
|
||||
UserNotActiveException,
|
||||
)
|
||||
from app.modules.tenancy.models import Store, StoreUser, User
|
||||
from middleware.auth import AuthManager
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import Store, StoreUser
|
||||
from models.schema.auth import UserLogin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -34,7 +34,7 @@ from dataclasses import dataclass, field
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.base import MenuItemDefinition, MenuSectionDefinition
|
||||
from app.modules.base import MenuSectionDefinition
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.service import module_service
|
||||
|
||||
@@ -112,7 +112,7 @@ class MenuDiscoveryService:
|
||||
ft: [] for ft in FrontendType
|
||||
}
|
||||
|
||||
for module_code, module_def in MODULES.items():
|
||||
for _module_code, module_def in MODULES.items():
|
||||
for frontend_type, sections in module_def.menus.items():
|
||||
all_menus[frontend_type].extend(deepcopy(sections))
|
||||
|
||||
|
||||
@@ -29,15 +29,14 @@ Usage:
|
||||
"""
|
||||
|
||||
import logging
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.service import module_service
|
||||
from app.modules.core.models import AdminMenuConfig
|
||||
from app.modules.core.services.menu_discovery_service import menu_discovery_service
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.service import module_service
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -160,7 +159,7 @@ class MenuService:
|
||||
|
||||
# Filter by module enablement if platform is specified
|
||||
if platform_id:
|
||||
module_available_items = module_service.get_module_menu_items(
|
||||
module_service.get_module_menu_items(
|
||||
db, platform_id, frontend_type
|
||||
)
|
||||
# Only keep items from enabled modules (or items not associated with any module)
|
||||
@@ -715,8 +714,7 @@ class MenuService:
|
||||
)
|
||||
if platform_id:
|
||||
return q.filter(AdminMenuConfig.platform_id == platform_id)
|
||||
else:
|
||||
return q.filter(AdminMenuConfig.user_id == user_id)
|
||||
return q.filter(AdminMenuConfig.user_id == user_id)
|
||||
|
||||
# Check if any visible records exist (valid opt-in config)
|
||||
visible_count = scope_query().filter(
|
||||
@@ -730,7 +728,7 @@ class MenuService:
|
||||
total_count = scope_query().count()
|
||||
if total_count > 0:
|
||||
# Clean up old records first
|
||||
deleted = scope_query().delete(synchronize_session='fetch')
|
||||
deleted = scope_query().delete(synchronize_session="fetch")
|
||||
db.flush() # Ensure deletes are applied before inserts
|
||||
logger.info(f"Cleaned up {deleted} old menu config records before initialization")
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ from typing import TYPE_CHECKING, Any
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.contracts.metrics import (
|
||||
MetricValue,
|
||||
MetricsContext,
|
||||
MetricsProviderProtocol,
|
||||
MetricValue,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
@@ -39,7 +39,6 @@ class StorageBackend(ABC):
|
||||
Returns:
|
||||
Public URL to access the file
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def delete(self, file_path: str) -> bool:
|
||||
@@ -52,7 +51,6 @@ class StorageBackend(ABC):
|
||||
Returns:
|
||||
True if file was deleted, False if not found
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_url(self, file_path: str) -> str:
|
||||
@@ -65,7 +63,6 @@ class StorageBackend(ABC):
|
||||
Returns:
|
||||
Public URL to access the file
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def exists(self, file_path: str) -> bool:
|
||||
@@ -78,7 +75,6 @@ class StorageBackend(ABC):
|
||||
Returns:
|
||||
True if file exists
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class LocalStorageBackend(StorageBackend):
|
||||
@@ -227,10 +223,9 @@ class R2StorageBackend(StorageBackend):
|
||||
if self.public_url:
|
||||
# Use custom domain
|
||||
return f"{self.public_url.rstrip('/')}/{file_path}"
|
||||
else:
|
||||
# Use default R2 public URL pattern
|
||||
# Note: Bucket must have public access enabled
|
||||
return f"https://{self.bucket_name}.{settings.r2_account_id}.r2.dev/{file_path}"
|
||||
# Use default R2 public URL pattern
|
||||
# Note: Bucket must have public access enabled
|
||||
return f"https://{self.bucket_name}.{settings.r2_account_id}.r2.dev/{file_path}"
|
||||
|
||||
async def exists(self, file_path: str) -> bool:
|
||||
"""Check if file exists in R2."""
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
"""Core module utilities."""
|
||||
|
||||
from .page_context import (
|
||||
get_context_for_frontend,
|
||||
get_admin_context,
|
||||
get_context_for_frontend,
|
||||
get_platform_context,
|
||||
get_store_context,
|
||||
get_storefront_context,
|
||||
get_platform_context,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
||||
Reference in New Issue
Block a user