feat(product-suite): compact controls and remember settings
This commit is contained in:
+18
-5
@@ -9,7 +9,11 @@ FIXED_CATEGORIES = ("白底图", "场景图", "卖点图")
|
||||
DEFAULT_CATEGORY_COUNTS = OrderedDict(
|
||||
(("白底图", 1), ("场景图", 2), ("卖点图", 2))
|
||||
)
|
||||
PLATFORMS = ("Shopee", "Lazada", "TikTok Shop", "Amazon")
|
||||
COUNTRIES = ("中国台湾", "新加坡", "马来西亚", "菲律宾", "泰国", "越南")
|
||||
LANGUAGES = ("繁体中文", "简体中文", "英文", "泰文", "越南文")
|
||||
RATIOS = ("1:1", "3:4", "4:3", "16:9", "9:16")
|
||||
LAST_SETTING_KEYS = ("platform", "country", "language", "ratio")
|
||||
MAX_CATEGORY_NAME_LENGTH = 10
|
||||
MAX_GENERATION_COUNT_WITHOUT_CONFIRM = 16
|
||||
|
||||
@@ -29,11 +33,10 @@ def default_suite_settings():
|
||||
def normalize_suite_settings(value=None):
|
||||
raw = dict(value or {}) if isinstance(value, dict) else {}
|
||||
normalized = default_suite_settings()
|
||||
normalized["platform"] = str(raw.get("platform") or "Shopee")
|
||||
normalized["country"] = str(raw.get("country") or "中国台湾")
|
||||
normalized["language"] = str(raw.get("language") or "繁体中文")
|
||||
ratio = str(raw.get("ratio") or "1:1")
|
||||
normalized["ratio"] = ratio if ratio in RATIOS else "1:1"
|
||||
normalized["platform"] = _choice(raw.get("platform"), PLATFORMS, "Shopee")
|
||||
normalized["country"] = _choice(raw.get("country"), COUNTRIES, "中国台湾")
|
||||
normalized["language"] = _choice(raw.get("language"), LANGUAGES, "繁体中文")
|
||||
normalized["ratio"] = _choice(raw.get("ratio"), RATIOS, "1:1")
|
||||
normalized["per_image_primary"] = bool(raw.get("per_image_primary", False))
|
||||
|
||||
raw_categories = raw.get("categories") if isinstance(raw.get("categories"), dict) else {}
|
||||
@@ -56,6 +59,11 @@ def normalize_suite_settings(value=None):
|
||||
return normalized
|
||||
|
||||
|
||||
def last_suite_settings(value=None):
|
||||
normalized = normalize_suite_settings(value)
|
||||
return {key: normalized[key] for key in LAST_SETTING_KEYS}
|
||||
|
||||
|
||||
def suite_name_error(name, existing=None, old_name=""):
|
||||
value = str(name or "")
|
||||
if not value.strip():
|
||||
@@ -146,3 +154,8 @@ def _count(value):
|
||||
return max(0, int(value or 0))
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
|
||||
def _choice(value, choices, default):
|
||||
text = str(value or "").strip()
|
||||
return text if text in choices else default
|
||||
|
||||
Reference in New Issue
Block a user