fix: correct tojson|safe usage in templates and update validator
- Remove |safe from |tojson in HTML attributes (x-data) - quotes must become " for browsers to parse correctly - Update LANG-002 and LANG-003 architecture rules to document correct |tojson usage patterns: - HTML attributes: |tojson (no |safe) - Script blocks: |tojson|safe - Fix validator to warn when |tojson|safe is used in x-data (breaks HTML attribute parsing) - Improve code quality across services, APIs, and tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,6 @@ This service handles CRUD operations for companies and company-vendor relationsh
|
||||
import logging
|
||||
import secrets
|
||||
import string
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
@@ -26,7 +25,6 @@ class CompanyService:
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize company service."""
|
||||
pass
|
||||
|
||||
def create_company_with_owner(
|
||||
self, db: Session, company_data: CompanyCreate
|
||||
@@ -106,11 +104,15 @@ class CompanyService:
|
||||
Raises:
|
||||
CompanyNotFoundException: If company not found
|
||||
"""
|
||||
company = db.execute(
|
||||
select(Company)
|
||||
.where(Company.id == company_id)
|
||||
.options(joinedload(Company.vendors))
|
||||
).unique().scalar_one_or_none()
|
||||
company = (
|
||||
db.execute(
|
||||
select(Company)
|
||||
.where(Company.id == company_id)
|
||||
.options(joinedload(Company.vendors))
|
||||
)
|
||||
.unique()
|
||||
.scalar_one_or_none()
|
||||
)
|
||||
|
||||
if not company:
|
||||
raise CompanyNotFoundException(company_id)
|
||||
@@ -125,7 +127,7 @@ class CompanyService:
|
||||
search: str | None = None,
|
||||
is_active: bool | None = None,
|
||||
is_verified: bool | None = None,
|
||||
) -> tuple[List[Company], int]:
|
||||
) -> tuple[list[Company], int]:
|
||||
"""
|
||||
Get paginated list of companies with optional filters.
|
||||
|
||||
@@ -209,7 +211,9 @@ class CompanyService:
|
||||
db.flush()
|
||||
logger.info(f"Deleted company ID {company_id} and associated vendors")
|
||||
|
||||
def toggle_verification(self, db: Session, company_id: int, is_verified: bool) -> Company:
|
||||
def toggle_verification(
|
||||
self, db: Session, company_id: int, is_verified: bool
|
||||
) -> Company:
|
||||
"""
|
||||
Toggle company verification status.
|
||||
|
||||
@@ -227,9 +231,7 @@ class CompanyService:
|
||||
company = self.get_company_by_id(db, company_id)
|
||||
company.is_verified = is_verified
|
||||
db.flush()
|
||||
logger.info(
|
||||
f"Company ID {company_id} verification set to {is_verified}"
|
||||
)
|
||||
logger.info(f"Company ID {company_id} verification set to {is_verified}")
|
||||
|
||||
return company
|
||||
|
||||
@@ -251,9 +253,7 @@ class CompanyService:
|
||||
company = self.get_company_by_id(db, company_id)
|
||||
company.is_active = is_active
|
||||
db.flush()
|
||||
logger.info(
|
||||
f"Company ID {company_id} active status set to {is_active}"
|
||||
)
|
||||
logger.info(f"Company ID {company_id} active status set to {is_active}")
|
||||
|
||||
return company
|
||||
|
||||
|
||||
Reference in New Issue
Block a user