From b4e0fc2a67c40c661e283d005e62b281126e1d16 Mon Sep 17 00:00:00 2001 From: xiaji Date: Mon, 16 Mar 2026 18:26:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AE=B6=E5=BA=AD=E4=BA=8B=E9=A1=B9):=20?= =?UTF-8?q?=E6=8C=89=E5=88=B0=E6=9C=9F=E6=97=B6=E9=97=B4=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=EF=BC=8C=E4=B8=80=E4=B8=AA=E6=9C=88=E5=86=85?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AF=A6=E6=83=85=EF=BC=8C=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=9C=88=E6=98=BE=E7=A4=BA=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改视图逻辑,将未完成事项分为即将到期(一个月内)和远期事项 - 即将到期的事项显示完整详情表格 - 超过一个月的远期事项只显示数量,不显示详情 - 支持显示已过期的事项(红色标记) --- core/templates/core/family_tasks.html | 50 ++++++++++++++++++++++----- core/views.py | 26 +++++++++++--- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/core/templates/core/family_tasks.html b/core/templates/core/family_tasks.html index d40f1dc..322be08 100644 --- a/core/templates/core/family_tasks.html +++ b/core/templates/core/family_tasks.html @@ -13,15 +13,16 @@ -
+ +
- 家庭事项列表 + 即将到期的事项
- {{ tasks|length }} 项 + {{ upcoming_tasks|length }} 项
- {% if tasks %} + {% if upcoming_tasks %}
@@ -35,8 +36,8 @@ - {% for task in tasks %} - + {% for task in upcoming_tasks %} + @@ -49,13 +50,13 @@
{{ task.get_type_display }} - + {{ task.get_status_display }} {% if task.deadline %} - + {{ task.deadline }} {% else %} @@ -78,6 +79,37 @@
{% else %} +
+ +

没有即将到期的家庭事项

+
+ {% endif %} +
+
+ + +{% if future_tasks_count > 0 %} +
+
+
+ 远期事项 +
+ {{ future_tasks_count }} 项 +
+
+
+ + 还有 {{ future_tasks_count }} 个将在一个月后到期的家庭事项 + (这些事项较远,暂不显示详情) +
+
+
+{% endif %} + + +{% if not upcoming_tasks and future_tasks_count == 0 %} +
+
太棒了!没有未完成的家庭事项
@@ -86,7 +118,7 @@ 添加家庭事项
- {% endif %}
+{% endif %} {% endblock %} diff --git a/core/views.py b/core/views.py index abbb7dd..8c72316 100644 --- a/core/views.py +++ b/core/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.http import HttpResponse, JsonResponse from django.utils import timezone +from django.db import models from django.db.models import Count from django.core.mail import send_mail, EmailMessage from django.conf import settings @@ -397,13 +398,30 @@ def delete_summary(request, pk): # 家庭事项视图 @login_required def family_tasks(request): - """家庭事项 - 显示所有未完成的事项(非completed状态)""" + """家庭事项 - 显示未完成的事项,一个月内显示详情,超过一个月显示数量""" logger.info("用户访问家庭事项页面") - # 排除已完成的事项,显示所有未完成的事项 - tasks = FamilyTask.objects.exclude(status__name='completed') + + today = timezone.now().date() + one_month_later = today + timedelta(days=30) + + # 获取所有未完成的事项 + all_pending_tasks = FamilyTask.objects.exclude(status__name='completed') + + # 一个月内到期的事项(显示详情) + # 包括:有截止日期且在一个月内,或者没有截止日期的事项 + upcoming_tasks = all_pending_tasks.filter( + models.Q(deadline__isnull=True) | models.Q(deadline__lte=one_month_later) + ) + + # 超过一个月到期的事项(只显示数量) + future_tasks = all_pending_tasks.filter(deadline__gt=one_month_later) + future_tasks_count = future_tasks.count() context = { - 'tasks': tasks, + 'upcoming_tasks': upcoming_tasks, + 'future_tasks_count': future_tasks_count, + 'total_pending_count': all_pending_tasks.count(), + 'today': today, } return render(request, 'core/family_tasks.html', context)