admin / Bid-Sentinel
publicBid Scrape and Tracking Application with AI Capability
Bid-Sentinel / bid-sentinel-v2 / backend / app / appsettings.py
1071 B · main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Tiny key/value application-settings store (used for the AI toggle).""" from __future__ import annotations from sqlalchemy.ext.asyncio import AsyncSession from app.models import AppSetting AI_ENABLED_KEY = "ai_enabled" # When "true", a notice must match a CPV code even if it declares no CPV data. # Default "false" = only narrow notices that actually carry a CPV classification. CPV_STRICT_KEY = "cpv_strict" async def get_setting(db: AsyncSession, key: str, default: str | None = None) -> str | None: row = await db.get(AppSetting, key) return row.value if row else default async def set_setting(db: AsyncSession, key: str, value: str) -> None: row = await db.get(AppSetting, key) if row: row.value = value else: db.add(AppSetting(key=key, value=value)) await db.commit() async def get_ai_enabled(db: AsyncSession) -> bool: return (await get_setting(db, AI_ENABLED_KEY, "false")) == "true" async def get_cpv_strict(db: AsyncSession) -> bool: return (await get_setting(db, CPV_STRICT_KEY, "false")) == "true" |