fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -35,6 +35,7 @@ except ImportError:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LanguageCode(StrEnum):
|
||||
"""支持的语言代码"""
|
||||
|
||||
@@ -51,6 +52,7 @@ class LanguageCode(StrEnum):
|
||||
AR = "ar"
|
||||
HI = "hi"
|
||||
|
||||
|
||||
class RegionCode(StrEnum):
|
||||
"""区域代码"""
|
||||
|
||||
@@ -62,6 +64,7 @@ class RegionCode(StrEnum):
|
||||
LATIN_AMERICA = "latam"
|
||||
MIDDLE_EAST = "me"
|
||||
|
||||
|
||||
class DataCenterRegion(StrEnum):
|
||||
"""数据中心区域"""
|
||||
|
||||
@@ -75,6 +78,7 @@ class DataCenterRegion(StrEnum):
|
||||
CN_NORTH = "cn-north"
|
||||
CN_EAST = "cn-east"
|
||||
|
||||
|
||||
class PaymentProvider(StrEnum):
|
||||
"""支付提供商"""
|
||||
|
||||
@@ -91,6 +95,7 @@ class PaymentProvider(StrEnum):
|
||||
SEPA = "sepa"
|
||||
UNIONPAY = "unionpay"
|
||||
|
||||
|
||||
class CalendarType(StrEnum):
|
||||
"""日历类型"""
|
||||
|
||||
@@ -102,6 +107,7 @@ class CalendarType(StrEnum):
|
||||
PERSIAN = "persian"
|
||||
BUDDHIST = "buddhist"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Translation:
|
||||
id: str
|
||||
@@ -116,6 +122,7 @@ class Translation:
|
||||
reviewed_by: str | None
|
||||
reviewed_at: datetime | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class LanguageConfig:
|
||||
code: str
|
||||
@@ -133,6 +140,7 @@ class LanguageConfig:
|
||||
first_day_of_week: int
|
||||
calendar_type: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class DataCenter:
|
||||
id: str
|
||||
@@ -147,6 +155,7 @@ class DataCenter:
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
@dataclass
|
||||
class TenantDataCenterMapping:
|
||||
id: str
|
||||
@@ -158,6 +167,7 @@ class TenantDataCenterMapping:
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
@dataclass
|
||||
class LocalizedPaymentMethod:
|
||||
id: str
|
||||
@@ -175,6 +185,7 @@ class LocalizedPaymentMethod:
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
@dataclass
|
||||
class CountryConfig:
|
||||
code: str
|
||||
@@ -196,6 +207,7 @@ class CountryConfig:
|
||||
vat_rate: float | None
|
||||
is_active: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class TimezoneConfig:
|
||||
id: str
|
||||
@@ -206,6 +218,7 @@ class TimezoneConfig:
|
||||
region: str
|
||||
is_active: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class CurrencyConfig:
|
||||
code: str
|
||||
@@ -217,6 +230,7 @@ class CurrencyConfig:
|
||||
thousands_separator: str
|
||||
is_active: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class LocalizationSettings:
|
||||
id: str
|
||||
@@ -236,6 +250,7 @@ class LocalizationSettings:
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class LocalizationManager:
|
||||
DEFAULT_LANGUAGES = {
|
||||
LanguageCode.EN: {
|
||||
@@ -731,33 +746,37 @@ class LocalizationManager:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS translations (
|
||||
id TEXT PRIMARY KEY, key TEXT NOT NULL, language TEXT NOT NULL, value TEXT NOT NULL,
|
||||
namespace TEXT DEFAULT 'common', context TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
id TEXT PRIMARY KEY, key TEXT NOT NULL, language TEXT NOT NULL,
|
||||
value TEXT NOT NULL, namespace TEXT DEFAULT 'common', context TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, is_reviewed INTEGER DEFAULT 0,
|
||||
reviewed_by TEXT, reviewed_at TIMESTAMP, UNIQUE(key, language, namespace)
|
||||
)
|
||||
""")
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS language_configs (
|
||||
code TEXT PRIMARY KEY, name TEXT NOT NULL, name_local TEXT NOT NULL, is_rtl INTEGER DEFAULT 0,
|
||||
is_active INTEGER DEFAULT 1, is_default INTEGER DEFAULT 0, fallback_language TEXT,
|
||||
date_format TEXT, time_format TEXT, datetime_format TEXT, number_format TEXT,
|
||||
currency_format TEXT, first_day_of_week INTEGER DEFAULT 1, calendar_type TEXT DEFAULT 'gregorian'
|
||||
code TEXT PRIMARY KEY, name TEXT NOT NULL, name_local TEXT NOT NULL,
|
||||
is_rtl INTEGER DEFAULT 0, is_active INTEGER DEFAULT 1, is_default INTEGER DEFAULT 0,
|
||||
fallback_language TEXT, date_format TEXT, time_format TEXT, datetime_format TEXT,
|
||||
number_format TEXT, currency_format TEXT, first_day_of_week INTEGER DEFAULT 1,
|
||||
calendar_type TEXT DEFAULT 'gregorian'
|
||||
)
|
||||
""")
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS data_centers (
|
||||
id TEXT PRIMARY KEY, region_code TEXT NOT NULL UNIQUE, name TEXT NOT NULL, location TEXT NOT NULL,
|
||||
endpoint TEXT NOT NULL, status TEXT DEFAULT 'active', priority INTEGER DEFAULT 1,
|
||||
supported_regions TEXT DEFAULT '[]', capabilities TEXT DEFAULT '{}',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
id TEXT PRIMARY KEY, region_code TEXT NOT NULL UNIQUE, name TEXT NOT NULL,
|
||||
location TEXT NOT NULL, endpoint TEXT NOT NULL, status TEXT DEFAULT 'active',
|
||||
priority INTEGER DEFAULT 1, supported_regions TEXT DEFAULT '[]',
|
||||
capabilities TEXT DEFAULT '{}', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS tenant_data_center_mappings (
|
||||
id TEXT PRIMARY KEY, tenant_id TEXT NOT NULL UNIQUE, primary_dc_id TEXT NOT NULL,
|
||||
secondary_dc_id TEXT, region_code TEXT NOT NULL, data_residency TEXT DEFAULT 'regional',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (primary_dc_id) REFERENCES data_centers(id),
|
||||
FOREIGN KEY (secondary_dc_id) REFERENCES data_centers(id)
|
||||
@@ -765,20 +784,23 @@ class LocalizationManager:
|
||||
""")
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS localized_payment_methods (
|
||||
id TEXT PRIMARY KEY, provider TEXT NOT NULL UNIQUE, name TEXT NOT NULL, name_local TEXT DEFAULT '{}',
|
||||
supported_countries TEXT DEFAULT '[]', supported_currencies TEXT DEFAULT '[]',
|
||||
is_active INTEGER DEFAULT 1, config TEXT DEFAULT '{}', icon_url TEXT, display_order INTEGER DEFAULT 0,
|
||||
id TEXT PRIMARY KEY, provider TEXT NOT NULL UNIQUE, name TEXT NOT NULL,
|
||||
name_local TEXT DEFAULT '{}', supported_countries TEXT DEFAULT '[]',
|
||||
supported_currencies TEXT DEFAULT '[]', is_active INTEGER DEFAULT 1,
|
||||
config TEXT DEFAULT '{}', icon_url TEXT, display_order INTEGER DEFAULT 0,
|
||||
min_amount REAL, max_amount REAL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS country_configs (
|
||||
code TEXT PRIMARY KEY, code3 TEXT NOT NULL, name TEXT NOT NULL, name_local TEXT DEFAULT '{}',
|
||||
region TEXT NOT NULL, default_language TEXT NOT NULL, supported_languages TEXT DEFAULT '[]',
|
||||
default_currency TEXT NOT NULL, supported_currencies TEXT DEFAULT '[]', timezone TEXT NOT NULL,
|
||||
calendar_type TEXT DEFAULT 'gregorian', date_format TEXT, time_format TEXT, number_format TEXT,
|
||||
address_format TEXT, phone_format TEXT, vat_rate REAL, is_active INTEGER DEFAULT 1
|
||||
code TEXT PRIMARY KEY, code3 TEXT NOT NULL, name TEXT NOT NULL,
|
||||
name_local TEXT DEFAULT '{}', region TEXT NOT NULL, default_language TEXT NOT NULL,
|
||||
supported_languages TEXT DEFAULT '[]', default_currency TEXT NOT NULL,
|
||||
supported_currencies TEXT DEFAULT '[]', timezone TEXT NOT NULL,
|
||||
calendar_type TEXT DEFAULT 'gregorian', date_format TEXT, time_format TEXT,
|
||||
number_format TEXT, address_format TEXT, phone_format TEXT, vat_rate REAL,
|
||||
is_active INTEGER DEFAULT 1
|
||||
)
|
||||
""")
|
||||
cursor.execute("""
|
||||
@@ -1667,8 +1689,10 @@ class LocalizationManager:
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
_localization_manager = None
|
||||
|
||||
|
||||
def get_localization_manager(db_path: str = "insightflow.db") -> LocalizationManager:
|
||||
global _localization_manager
|
||||
if _localization_manager is None:
|
||||
|
||||
Reference in New Issue
Block a user