Fakultas Ilmu Komputer UI

Commit 5d6adb75 authored by Nabila Febri Viola's avatar Nabila Febri Viola
Browse files

[GREEN] Change acara donor filters to match the new acara donor model and refactor datetime range

parent a6eca14a
...@@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _ ...@@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
class AcaraDonorFilter(admin.SimpleListFilter): class AcaraDonorFilter(admin.SimpleListFilter):
title = _('waktu donor') title = _('waktu donor')
parameter_name = 'waktu_donor' parameter_name = 'waktu_mulai'
def lookups(self, request, model_admin): def lookups(self, request, model_admin):
return ( return (
...@@ -24,33 +24,34 @@ class AcaraDonorFilter(admin.SimpleListFilter): ...@@ -24,33 +24,34 @@ class AcaraDonorFilter(admin.SimpleListFilter):
def __last_day_of_month(self, any_day): def __last_day_of_month(self, any_day):
next_month = any_day.replace(day=28) + datetime.timedelta(days=4) next_month = any_day.replace(day=28) + datetime.timedelta(days=4)
return next_month - datetime.timedelta(days=next_month.day) + datetime.timedelta(days=1) return next_month - datetime.timedelta(days=next_month.day) \
+ datetime.timedelta(days=1)
def queryset(self, request, queryset): def queryset(self, request, queryset):
today = localtime(now()).replace(hour=0, minute=0, second=0, microsecond=0) today = localtime(now()).replace(
tomorrow = today + datetime.timedelta(days=1) hour=0, minute=0, second=0, microsecond=0)
next_seven_days = today + datetime.timedelta(days=8) next_seven_days = today + datetime.timedelta(days=8)
this_month = today.replace(day=1) this_month = today.replace(day=1)
end_of_this_month = self.__last_day_of_month(today) end_of_this_month = self.__last_day_of_month(today)
start_of_next_month = today.replace(year=today.year, month=today.month + 1, day=1) start_of_next_month = today.replace(year=today.year,
month=today.month + 1, day=1)
end_of_next_month = self.__last_day_of_month(start_of_next_month) end_of_next_month = self.__last_day_of_month(start_of_next_month)
this_year = today.replace(month=1, day=1)
next_year = today.replace(year=today.year + 1, month=1, day=1)
if self.value() == 'today': if self.value() == 'today':
return queryset.filter(waktu_donor__range=[today, tomorrow]) return queryset.filter(waktu_mulai__date=today)
if self.value() == 'next_seven_days': if self.value() == 'next_seven_days':
return queryset.filter(waktu_donor__range=[today, next_seven_days]) return queryset.filter(waktu_mulai__range=[today, next_seven_days])
if self.value() == 'this_month': if self.value() == 'this_month':
return queryset.filter(waktu_donor__range=[this_month, end_of_this_month]) return queryset.filter(
waktu_mulai__range=[this_month, end_of_this_month])
if self.value() == 'next_month': if self.value() == 'next_month':
return queryset.filter(waktu_donor__range=[start_of_next_month, end_of_next_month]) return queryset.filter(waktu_mulai__range=[start_of_next_month,
end_of_next_month])
if self.value() == 'this_year': if self.value() == 'this_year':
return queryset.filter(waktu_donor__range=[this_year, next_year]) return queryset.filter(waktu_mulai__year=today.year)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment