更新了年份显示和统计周期的显示

This commit is contained in:
2026-01-05 11:40:08 +08:00
parent 9cbc90cc37
commit 51286ae181
5 changed files with 138 additions and 100 deletions

Binary file not shown.

View File

@@ -15,7 +15,9 @@
<header class="bg-gray-50 dark:bg-gray-800 dark:border-gray-700 p-4 text-center text-xl font-bold">
分支机构活动管理
<br>
2025
{{ ''|get_current_year }}
<br>
统计周期:{{ ''|get_statistic_period }}
</header>
<!-- 主体内容:左右两侧栏布局 -->

View File

@@ -28,3 +28,39 @@ def format_chinese_full_date(value):
weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
weekday = weekdays[date_obj.weekday()]
return f"{date_obj.year}{date_obj.month}{date_obj.day}{weekday}"
@register.filter
def get_current_year(value=None):
"""
获取当前年份
"""
now = datetime.now() if value is None else value
return now.year
@register.filter
def get_statistic_period(value=None):
"""
计算统计周期
规则:
- 在2026年1月实际统计的是2025年11月至2026年1月
- 在2026年2月实际统计的是2025年12月至2026年2月
- 以此类推
"""
now = datetime.now() if value is None else value
current_year = now.year
current_month = now.month
# 计算统计周期的开始月份和年份
if current_month <= 2:
start_year = current_year - 1
start_month = 11 + current_month
else:
start_year = current_year
start_month = current_month - 2
# 构建统计周期字符串
period = f"{start_year}{start_month}月至{current_year}{current_month}"
return period