mirror of https://github.com/raiots/TasksManager
fix: the unfiltered by year in tasklist view
This commit is contained in:
parent
92971237f5
commit
69af43c01c
|
@ -8,10 +8,17 @@ register = template.Library()
|
|||
|
||||
@register.filter(name='quarter_cate')
|
||||
def quarter_cate(value, quarter):
|
||||
year_now = datetime.now().strftime('%Y')
|
||||
month = value.deadline.strftime('%m')
|
||||
year = value.deadline.strftime('%Y')
|
||||
month = int(month)
|
||||
# year = int(year)
|
||||
# year_now = int(year) 不知道为什么,如果转整数会把2021和2022认为相同
|
||||
quarter = int(quarter)
|
||||
# 可能造成性能损失,每次数据库会调出符合“当年”的任务或工作包的全部任务下工作包,并逐个判断
|
||||
|
||||
if year == year_now:
|
||||
print("jakfjklajfklsdjf")
|
||||
if quarter == 1 and 1 <= month <= 3:
|
||||
return str(value) + ' '
|
||||
|
||||
|
@ -26,6 +33,8 @@ def quarter_cate(value, quarter):
|
|||
|
||||
else:
|
||||
return ''
|
||||
else:
|
||||
return ''
|
||||
|
||||
@register.filter(name='last_month')
|
||||
def last_month(value):
|
||||
|
|
|
@ -16,6 +16,7 @@ urlpatterns = [
|
|||
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('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'),
|
||||
]
|
||||
#
|
||||
|
|
|
@ -28,6 +28,7 @@ class IndexView(View):
|
|||
# TODO 解决系统时间变化,日期不刷新的问题
|
||||
# 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/38237777/django-timezone-now-vs-timezone-now
|
||||
|
||||
@method_decorator(login_required)
|
||||
def get(self, request, year=timezone.now().year, month=timezone.now().month):
|
||||
|
@ -377,8 +378,11 @@ class GroupTodoList(View):
|
|||
|
||||
class TaskListView(View):
|
||||
@method_decorator(login_required)
|
||||
def get(self, request):
|
||||
tasks = Task.objects.filter(department=request.user.department).order_by('task_id')
|
||||
def get(self, request, year=timezone.now().year): # TODO 把timezone.now().year写在后面要用year替换的地方是否可以解决
|
||||
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}
|
||||
return render(request, 'tasks/tasklist.html', context)
|
||||
|
||||
|
|
Loading…
Reference in New Issue