feat(家庭事项): 按到期时间分类显示,一个月内显示详情,超过一个月显示数量

- 修改视图逻辑,将未完成事项分为即将到期(一个月内)和远期事项
- 即将到期的事项显示完整详情表格
- 超过一个月的远期事项只显示数量,不显示详情
- 支持显示已过期的事项(红色标记)
This commit is contained in:
2026-03-16 18:26:47 +08:00
parent ec21ff68e3
commit b4e0fc2a67
2 changed files with 63 additions and 13 deletions

View File

@@ -13,15 +13,16 @@
</div> </div>
</div> </div>
<div class="card"> <!-- 即将到期的事项(一个月内) -->
<div class="card mb-4">
<div class="card-header bg-primary text-white d-flex justify-content-between align-items-center"> <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
<h5 class="card-title mb-0"> <h5 class="card-title mb-0">
<i class="bi bi-house-door me-2"></i>家庭事项列表 <i class="bi bi-house-door me-2"></i>即将到期的事项
</h5> </h5>
<span class="badge bg-light text-primary">{{ tasks|length }} 项</span> <span class="badge bg-light text-primary">{{ upcoming_tasks|length }} 项</span>
</div> </div>
<div class="card-body"> <div class="card-body">
{% if tasks %} {% if upcoming_tasks %}
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-hover"> <table class="table table-hover">
<thead> <thead>
@@ -35,8 +36,8 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for task in tasks %} {% for task in upcoming_tasks %}
<tr class="{% if task.status == 'completed' %}table-success{% endif %}"> <tr>
<td> <td>
<span class="badge bg-secondary">{{ task.get_type_display }}</span> <span class="badge bg-secondary">{{ task.get_type_display }}</span>
</td> </td>
@@ -49,13 +50,13 @@
</span> </span>
</td> </td>
<td> <td>
<span class="badge {% if task.status == 'completed' %}bg-success{% else %}bg-warning{% endif %}"> <span class="badge bg-warning">
{{ task.get_status_display }} {{ task.get_status_display }}
</span> </span>
</td> </td>
<td> <td>
{% if task.deadline %} {% if task.deadline %}
<span class="{% if task.is_overdue %}text-danger{% else %}text-muted{% endif %}"> <span class="{% if task.deadline < today %}text-danger{% else %}text-muted{% endif %}">
<i class="bi bi-calendar me-1"></i>{{ task.deadline }} <i class="bi bi-calendar me-1"></i>{{ task.deadline }}
</span> </span>
{% else %} {% else %}
@@ -78,6 +79,37 @@
</table> </table>
</div> </div>
{% else %} {% else %}
<div class="text-center py-4">
<i class="bi bi-check-all text-success" style="font-size: 3rem;"></i>
<p class="text-muted mt-2">没有即将到期的家庭事项</p>
</div>
{% endif %}
</div>
</div>
<!-- 远期事项(超过一个月) -->
{% if future_tasks_count > 0 %}
<div class="card">
<div class="card-header bg-info text-white d-flex justify-content-between align-items-center">
<h5 class="card-title mb-0">
<i class="bi bi-calendar-event me-2"></i>远期事项
</h5>
<span class="badge bg-light text-info">{{ future_tasks_count }} 项</span>
</div>
<div class="card-body">
<div class="alert alert-info mb-0">
<i class="bi bi-info-circle-fill me-2"></i>
还有 <strong>{{ future_tasks_count }}</strong> 个将在一个月后到期的家庭事项
<span class="text-muted">(这些事项较远,暂不显示详情)</span>
</div>
</div>
</div>
{% endif %}
<!-- 全部完成的状态 -->
{% if not upcoming_tasks and future_tasks_count == 0 %}
<div class="card">
<div class="card-body">
<div class="text-center py-5"> <div class="text-center py-5">
<i class="bi bi-check-all text-success" style="font-size: 5rem;"></i> <i class="bi bi-check-all text-success" style="font-size: 5rem;"></i>
<h5 class="text-muted mt-3">太棒了!没有未完成的家庭事项</h5> <h5 class="text-muted mt-3">太棒了!没有未完成的家庭事项</h5>
@@ -86,7 +118,7 @@
<i class="bi bi-plus-lg me-1"></i>添加家庭事项 <i class="bi bi-plus-lg me-1"></i>添加家庭事项
</a> </a>
</div> </div>
{% endif %}
</div> </div>
</div> </div>
{% endif %}
{% endblock %} {% endblock %}

View File

@@ -1,6 +1,7 @@
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
from django.utils import timezone from django.utils import timezone
from django.db import models
from django.db.models import Count from django.db.models import Count
from django.core.mail import send_mail, EmailMessage from django.core.mail import send_mail, EmailMessage
from django.conf import settings from django.conf import settings
@@ -397,13 +398,30 @@ def delete_summary(request, pk):
# 家庭事项视图 # 家庭事项视图
@login_required @login_required
def family_tasks(request): def family_tasks(request):
"""家庭事项 - 显示所有未完成的事项非completed状态""" """家庭事项 - 显示未完成的事项,一个月内显示详情,超过一个月显示数量"""
logger.info("用户访问家庭事项页面") 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 = { 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) return render(request, 'core/family_tasks.html', context)