fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -830,30 +830,30 @@ class LocalizationManager:
|
||||
""")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_translations_key ON translations(key)")
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_translations_lang ON translations(language)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_translations_lang ON translations(language)",
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_translations_ns ON translations(namespace)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_translations_ns ON translations(namespace)",
|
||||
)
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_dc_region ON data_centers(region_code)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_dc_status ON data_centers(status)")
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_tenant_dc ON tenant_data_center_mappings(tenant_id)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_tenant_dc ON tenant_data_center_mappings(tenant_id)",
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_payment_provider ON localized_payment_methods(provider)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_payment_provider ON localized_payment_methods(provider)",
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_payment_active ON localized_payment_methods(is_active)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_payment_active ON localized_payment_methods(is_active)",
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_country_region ON country_configs(region)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_country_region ON country_configs(region)",
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_tz_country ON timezone_configs(country_code)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_tz_country ON timezone_configs(country_code)",
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_locale_settings_tenant ON localization_settings(tenant_id)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_locale_settings_tenant ON localization_settings(tenant_id)",
|
||||
)
|
||||
conn.commit()
|
||||
logger.info("Localization tables initialized successfully")
|
||||
@@ -963,7 +963,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def get_translation(
|
||||
self, key: str, language: str, namespace: str = "common", fallback: bool = True
|
||||
self, key: str, language: str, namespace: str = "common", fallback: bool = True,
|
||||
) -> str | None:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -979,7 +979,7 @@ class LocalizationManager:
|
||||
lang_config = self.get_language_config(language)
|
||||
if lang_config and lang_config.fallback_language:
|
||||
return self.get_translation(
|
||||
key, lang_config.fallback_language, namespace, False
|
||||
key, lang_config.fallback_language, namespace, False,
|
||||
)
|
||||
if language != "en":
|
||||
return self.get_translation(key, "en", namespace, False)
|
||||
@@ -1019,7 +1019,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def _get_translation_internal(
|
||||
self, conn: sqlite3.Connection, key: str, language: str, namespace: str
|
||||
self, conn: sqlite3.Connection, key: str, language: str, namespace: str,
|
||||
) -> Translation | None:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
@@ -1121,7 +1121,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def list_data_centers(
|
||||
self, status: str | None = None, region: str | None = None
|
||||
self, status: str | None = None, region: str | None = None,
|
||||
) -> list[DataCenter]:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1146,7 +1146,7 @@ class LocalizationManager:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT * FROM tenant_data_center_mappings WHERE tenant_id = ?", (tenant_id,)
|
||||
"SELECT * FROM tenant_data_center_mappings WHERE tenant_id = ?", (tenant_id,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
@@ -1156,7 +1156,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def set_tenant_data_center(
|
||||
self, tenant_id: str, region_code: str, data_residency: str = "regional"
|
||||
self, tenant_id: str, region_code: str, data_residency: str = "regional",
|
||||
) -> TenantDataCenterMapping:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1222,7 +1222,7 @@ class LocalizationManager:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT * FROM localized_payment_methods WHERE provider = ?", (provider,)
|
||||
"SELECT * FROM localized_payment_methods WHERE provider = ?", (provider,),
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
if row:
|
||||
@@ -1232,7 +1232,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def list_payment_methods(
|
||||
self, country_code: str | None = None, currency: str | None = None, active_only: bool = True
|
||||
self, country_code: str | None = None, currency: str | None = None, active_only: bool = True,
|
||||
) -> list[LocalizedPaymentMethod]:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1255,7 +1255,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def get_localized_payment_methods(
|
||||
self, country_code: str, language: str = "en"
|
||||
self, country_code: str, language: str = "en",
|
||||
) -> list[dict[str, Any]]:
|
||||
methods = self.list_payment_methods(country_code=country_code)
|
||||
result = []
|
||||
@@ -1270,7 +1270,7 @@ class LocalizationManager:
|
||||
"min_amount": method.min_amount,
|
||||
"max_amount": method.max_amount,
|
||||
"supported_currencies": method.supported_currencies,
|
||||
}
|
||||
},
|
||||
)
|
||||
return result
|
||||
|
||||
@@ -1287,7 +1287,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def list_country_configs(
|
||||
self, region: str | None = None, active_only: bool = True
|
||||
self, region: str | None = None, active_only: bool = True,
|
||||
) -> list[CountryConfig]:
|
||||
conn = self._get_connection()
|
||||
try:
|
||||
@@ -1345,14 +1345,14 @@ class LocalizationManager:
|
||||
return dt.strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
def format_number(
|
||||
self, number: float, language: str = "en", decimal_places: int | None = None
|
||||
self, number: float, language: str = "en", decimal_places: int | None = None,
|
||||
) -> str:
|
||||
try:
|
||||
if BABEL_AVAILABLE:
|
||||
try:
|
||||
locale = Locale.parse(language.replace("_", "-"))
|
||||
return numbers.format_decimal(
|
||||
number, locale=locale, decimal_quantization=(decimal_places is not None)
|
||||
number, locale=locale, decimal_quantization=(decimal_places is not None),
|
||||
)
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
@@ -1514,7 +1514,7 @@ class LocalizationManager:
|
||||
self._close_if_file_db(conn)
|
||||
|
||||
def detect_user_preferences(
|
||||
self, accept_language: str | None = None, ip_country: str | None = None
|
||||
self, accept_language: str | None = None, ip_country: str | None = None,
|
||||
) -> dict[str, str]:
|
||||
preferences = {"language": "en", "country": "US", "timezone": "UTC", "currency": "USD"}
|
||||
if accept_language:
|
||||
|
||||
Reference in New Issue
Block a user