fix: the unfiltered by year in tasklist view

This commit is contained in:
raiots 2022-01-04 17:15:16 +08:00
parent 92971237f5
commit 69af43c01c
3 changed files with 24 additions and 10 deletions

View File

@ -8,22 +8,31 @@ register = template.Library()
@register.filter(name='quarter_cate') @register.filter(name='quarter_cate')
def quarter_cate(value, quarter): def quarter_cate(value, quarter):
year_now = datetime.now().strftime('%Y')
month = value.deadline.strftime('%m') month = value.deadline.strftime('%m')
year = value.deadline.strftime('%Y')
month = int(month) month = int(month)
# year = int(year)
# year_now = int(year) 不知道为什么如果转整数会把2021和2022认为相同
quarter = int(quarter) quarter = int(quarter)
# 可能造成性能损失,每次数据库会调出符合“当年”的任务或工作包的全部任务下工作包,并逐个判断
if quarter == 1 and 1 <= month <= 3: if year == year_now:
return str(value) + '&#13;&#10;' print("jakfjklajfklsdjf")
if quarter == 1 and 1 <= month <= 3:
return str(value) + '&#13;&#10;'
elif quarter == 2 and 4 <= month <= 6: elif quarter == 2 and 4 <= month <= 6:
return str(value) + '&#13;&#10;' return str(value) + '&#13;&#10;'
elif quarter == 3 and 7 <= month <= 9: elif quarter == 3 and 7 <= month <= 9:
return str(value) + '&#13;&#10;' return str(value) + '&#13;&#10;'
elif quarter == 4 and 10 <= month <= 12: elif quarter == 4 and 10 <= month <= 12:
return str(value) + '&#13;&#10;' return str(value) + '&#13;&#10;'
else:
return ''
else: else:
return '' return ''

View File

@ -16,6 +16,7 @@ urlpatterns = [
path('group_todolist/<int:year>/<int:month>/', views.GroupTodoList.as_view(), name='group_todolist_month'), path('group_todolist/<int:year>/<int:month>/', views.GroupTodoList.as_view(), name='group_todolist_month'),
path('todo/<int:pk>/', views.TodoEntryView.as_view(), name='todo_detail'), path('todo/<int:pk>/', views.TodoEntryView.as_view(), name='todo_detail'),
path('tasklist/', views.TaskListView.as_view(), name='tasklist'), path('tasklist/', views.TaskListView.as_view(), name='tasklist'),
path('tasklist/<int:year>/', views.TaskListView.as_view(), name='tasklist_year'),
path('about/', views.AboutView.as_view(), name='about'), path('about/', views.AboutView.as_view(), name='about'),
] ]
# #

View File

@ -28,6 +28,7 @@ class IndexView(View):
# TODO 解决系统时间变化,日期不刷新的问题 # TODO 解决系统时间变化,日期不刷新的问题
# https://stackoverflow.com/questions/63072235/django-localdate-doesnt-return-correct-date # https://stackoverflow.com/questions/63072235/django-localdate-doesnt-return-correct-date
# https://stackoverflow.com/questions/13225890/django-default-timezone-now-saves-records-using-old-time # https://stackoverflow.com/questions/13225890/django-default-timezone-now-saves-records-using-old-time
# https://stackoverflow.com/questions/38237777/django-timezone-now-vs-timezone-now
@method_decorator(login_required) @method_decorator(login_required)
def get(self, request, year=timezone.now().year, month=timezone.now().month): def get(self, request, year=timezone.now().year, month=timezone.now().month):
@ -377,8 +378,11 @@ class GroupTodoList(View):
class TaskListView(View): class TaskListView(View):
@method_decorator(login_required) @method_decorator(login_required)
def get(self, request): def get(self, request, year=timezone.now().year): # TODO 把timezone.now().year写在后面要用year替换的地方是否可以解决
tasks = Task.objects.filter(department=request.user.department).order_by('task_id') tasks = Task.objects.filter(department=request.user.department, deadline__year=year).order_by('task_id') \
| Task.objects.filter(department=request.user.department, related_task__deadline__year=year).order_by('task_id')
# 使用‘或’,找出工作包/年度任务的截止日期在今年的年度任务。后面还要做一个筛选,以达到只显示本年度的工作包
context = {'tasks': tasks} context = {'tasks': tasks}
return render(request, 'tasks/tasklist.html', context) return render(request, 'tasks/tasklist.html', context)