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:
2025-12-13 22:59:51 +01:00
parent 94d268f330
commit 9920430b9e
123 changed files with 1408 additions and 840 deletions

View File

@@ -18,6 +18,7 @@ from pathlib import Path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
def test_logging_endpoints():
"""Test logging-related API endpoints."""
print("\n" + "=" * 70)
@@ -34,7 +35,7 @@ def test_logging_endpoints():
# Create an exception log
try:
raise ValueError("Test exception for logging")
except Exception as e:
except Exception:
logging.error("Test exception logging", exc_info=True)
print(" ✓ Test logs created")
@@ -69,9 +70,12 @@ def test_logging_endpoints():
print(f" ✓ Database logs count: {count}")
if count > 0:
recent = db.query(ApplicationLog).order_by(
ApplicationLog.timestamp.desc()
).limit(5).all()
recent = (
db.query(ApplicationLog)
.order_by(ApplicationLog.timestamp.desc())
.limit(5)
.all()
)
print(" Recent logs:")
for log in recent:
@@ -90,9 +94,15 @@ def test_logging_endpoints():
db = SessionLocal()
try:
log_level = admin_settings_service.get_setting_value(db, "log_level", "INFO")
max_size = admin_settings_service.get_setting_value(db, "log_file_max_size_mb", 10)
retention = admin_settings_service.get_setting_value(db, "db_log_retention_days", 30)
log_level = admin_settings_service.get_setting_value(
db, "log_level", "INFO"
)
max_size = admin_settings_service.get_setting_value(
db, "log_file_max_size_mb", 10
)
retention = admin_settings_service.get_setting_value(
db, "db_log_retention_days", 30
)
print(f" ✓ Log Level: {log_level}")
print(f" ✓ Max File Size: {max_size} MB")
@@ -118,6 +128,7 @@ def test_logging_endpoints():
if __name__ == "__main__":
# Set up logging first
from app.core.logging import setup_logging
setup_logging()
success = test_logging_endpoints()