diff --git a/app/__init__.py b/app/__init__.py index 1c4f8d4..0120dc5 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -61,10 +61,11 @@ def create_app(config_name='default'): app.logger.info('PT黑名单系统启动') # 注册自定义过滤器 - from .filters import translate_status, translate_reason, translate_reasons_list + from .filters import translate_status, translate_reason, translate_reasons_list, to_beijing_time app.jinja_env.filters['translate_status'] = translate_status app.jinja_env.filters['translate_reason'] = translate_reason app.jinja_env.filters['translate_reasons_list'] = translate_reasons_list + app.jinja_env.filters['to_beijing_time'] = to_beijing_time # 注册蓝图 from .routes import main as main_blueprint diff --git a/app/filters.py b/app/filters.py index 417a63d..02c1e12 100644 --- a/app/filters.py +++ b/app/filters.py @@ -1,4 +1,5 @@ """Jinja2模板过滤器""" +from datetime import timedelta STATUS_TRANSLATIONS = { 'pending': '待审核', @@ -45,3 +46,9 @@ def translate_reasons_list(reasons): if not reasons: return [] return [REASON_TRANSLATIONS.get(r, r) for r in reasons] + +def to_beijing_time(utc_dt): + """UTC时间转北京时间(UTC+8)""" + if utc_dt is None: + return None + return utc_dt + timedelta(hours=8) diff --git a/app/templates/admin/appeal_list.html b/app/templates/admin/appeal_list.html index 3799f8c..bc66899 100644 --- a/app/templates/admin/appeal_list.html +++ b/app/templates/admin/appeal_list.html @@ -34,7 +34,7 @@ {{ appeal.status | translate_status }} - {{ appeal.updated_at.strftime('%Y-%m-%d %H:%M') }} + {{ (appeal.updated_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} 查看详情 diff --git a/app/templates/admin/manage_users.html b/app/templates/admin/manage_users.html index 1410a51..5c26e6b 100644 --- a/app/templates/admin/manage_users.html +++ b/app/templates/admin/manage_users.html @@ -30,7 +30,7 @@ {{ user.email }} {{ user.pt_site }} / {{ user.uid }} - {{ user.created_at.strftime('%Y-%m-%d') }} + {{ (user.created_at | to_beijing_time).strftime('%Y-%m-%d') }} {% if user.id == 1 %}
角色: {{ user.role }}
diff --git a/app/templates/admin/pending_users.html b/app/templates/admin/pending_users.html index 8e923ee..a021afc 100644 --- a/app/templates/admin/pending_users.html +++ b/app/templates/admin/pending_users.html @@ -27,7 +27,7 @@ {{ user.email }} {{ user.pt_site }} {{ user.uid }} - {{ user.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (user.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }}
diff --git a/app/templates/admin/report_detail.html b/app/templates/admin/report_detail.html index cf4b8f9..47df627 100644 --- a/app/templates/admin/report_detail.html +++ b/app/templates/admin/report_detail.html @@ -74,7 +74,7 @@ #{{ r.id }} - {{ r.reason_category | translate_reason }} {{ r.status | translate_status }} - {{ r.created_at.strftime('%Y-%m-%d') }} | 举报人: {{ r.reporter.username }} + {{ (r.created_at | to_beijing_time).strftime('%Y-%m-%d') }} | 举报人: {{ r.reporter.username }} {% endfor %} @@ -95,7 +95,7 @@

{{ comment.body | safe }}

- {{ comment.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (comment.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} {% else %} diff --git a/app/templates/admin/report_list.html b/app/templates/admin/report_list.html index a661e93..75803c4 100644 --- a/app/templates/admin/report_list.html +++ b/app/templates/admin/report_list.html @@ -30,7 +30,7 @@ {{ report.reporter.username }} {{ report.status | translate_status }} - {{ report.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (report.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} 查看详情 {% else %} diff --git a/app/templates/appeal_detail.html b/app/templates/appeal_detail.html index d6eddeb..8d77181 100644 --- a/app/templates/appeal_detail.html +++ b/app/templates/appeal_detail.html @@ -68,7 +68,7 @@
{{ appeal.appealer.username }} - {{ appeal.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (appeal.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }}

[初始申诉理由]

@@ -82,10 +82,10 @@
{% if message.author.role == 'admin' %} {{ message.author.username }} (管理员) - {{ message.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (message.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} {% else %} {{ message.author.username }} - {{ message.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (message.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} {% endif %}
diff --git a/app/templates/index.html b/app/templates/index.html index 11b451b..b6b8964 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -57,7 +57,7 @@ 未知 {% endif %} -
  • 记录时间: {{ search_result.created_at.strftime('%Y-%m-%d') }}
  • +
  • 记录时间: {{ (search_result.created_at | to_beijing_time).strftime('%Y-%m-%d') }}
  • 为保护隐私,仅展示必要的脱敏信息。具体违规描述不对外公开。

    diff --git a/app/templates/my_appeals.html b/app/templates/my_appeals.html index e87821c..d4ad319 100644 --- a/app/templates/my_appeals.html +++ b/app/templates/my_appeals.html @@ -31,8 +31,8 @@ {{ appeal.status | translate_status }} - {{ appeal.created_at.strftime('%Y-%m-%d %H:%M') }} - {{ appeal.updated_at.strftime('%Y-%m-%d %H:%M') }} + {{ (appeal.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} + {{ (appeal.updated_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} 查看详情 diff --git a/app/templates/my_reports.html b/app/templates/my_reports.html index fb6828f..7d0b462 100644 --- a/app/templates/my_reports.html +++ b/app/templates/my_reports.html @@ -36,7 +36,7 @@ {{ report.status | translate_status }} - {{ report.created_at.strftime('%Y-%m-%d %H:%M') }} + {{ (report.created_at | to_beijing_time).strftime('%Y-%m-%d %H:%M') }} 查看详情