Compare commits

...

2 Commits

Author SHA1 Message Date
26554c7f29 修改了年份显示的小样式 2026-01-05 11:47:06 +08:00
51286ae181 更新了年份显示和统计周期的显示 2026-01-05 11:40:08 +08:00
5 changed files with 144 additions and 100 deletions

Binary file not shown.

View File

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

View File

@@ -28,3 +28,47 @@ 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):
"""
获取当前年份
"""
# 只有当value是datetime对象时才使用它否则使用当前时间
if isinstance(value, datetime):
now = value
else:
now = datetime.now()
return now.year
@register.filter
def get_statistic_period(value=None):
"""
计算统计周期
规则:
- 在2026年1月实际统计的是2025年11月至2026年1月
- 在2026年2月实际统计的是2025年12月至2026年2月
- 以此类推
"""
# 只有当value是datetime对象时才使用它否则使用当前时间
if isinstance(value, datetime):
now = value
else:
now = datetime.now()
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