feat: 打磨报告页和内容详情页
This commit is contained in:
@@ -28,6 +28,14 @@ def from_json_filter(value: str | None) -> list:
|
||||
return parsed if isinstance(parsed, list) else []
|
||||
|
||||
|
||||
def from_json_object_filter(value: str | None) -> dict:
|
||||
try:
|
||||
parsed = json.loads(value) if value else {}
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
return {}
|
||||
return parsed if isinstance(parsed, dict) else {}
|
||||
|
||||
|
||||
def progress_percent(processed_count: int, total_count: int) -> int:
|
||||
if total_count <= 0:
|
||||
return 0
|
||||
@@ -40,8 +48,19 @@ def rate_percent(rate: float | None) -> int:
|
||||
return min(100, max(0, round(rate * 100)))
|
||||
|
||||
|
||||
def sentiment_label(sentiment: str) -> str:
|
||||
return {
|
||||
"positive": "正向",
|
||||
"neutral": "中性",
|
||||
"negative": "负向",
|
||||
"unknown": "未知",
|
||||
}.get(sentiment, sentiment)
|
||||
|
||||
|
||||
templates.env.globals["status_badge_config"] = status_badge_config
|
||||
templates.env.globals["progress_percent"] = progress_percent
|
||||
templates.env.globals["rate_percent"] = rate_percent
|
||||
templates.env.globals["sentiment_label"] = sentiment_label
|
||||
templates.env.filters["platform_label"] = platform_label
|
||||
templates.env.filters["from_json"] = from_json_filter
|
||||
templates.env.filters["from_json_object"] = from_json_object_filter
|
||||
|
||||
Reference in New Issue
Block a user