[UPDT] ATTENDANCE: Work record optimized rendering using pagination
This commit is contained in:
@@ -4,7 +4,7 @@ attendance/sidebar.py
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from base.context_processors import enable_late_come_early_out_tracking
|
from base.context_processors import enable_late_come_early_out_tracking
|
||||||
@@ -17,40 +17,40 @@ IMG_SRC = "images/ui/attendances.svg"
|
|||||||
SUBMENUS = [
|
SUBMENUS = [
|
||||||
{
|
{
|
||||||
"menu": _("Dashboard"),
|
"menu": _("Dashboard"),
|
||||||
"redirect": reverse("attendance-dashboard"),
|
"redirect": reverse_lazy("attendance-dashboard"),
|
||||||
"accessibility": "attendance.sidebar.dashboard_accessibility",
|
"accessibility": "attendance.sidebar.dashboard_accessibility",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("Attendances"),
|
"menu": _("Attendances"),
|
||||||
"redirect": reverse("attendance-view"),
|
"redirect": reverse_lazy("attendance-view"),
|
||||||
"accessibility": "attendance.sidebar.attendances_accessibility",
|
"accessibility": "attendance.sidebar.attendances_accessibility",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("Attendance Requests"),
|
"menu": _("Attendance Requests"),
|
||||||
"redirect": reverse("request-attendance-view"),
|
"redirect": reverse_lazy("request-attendance-view"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("Hour Account"),
|
"menu": _("Hour Account"),
|
||||||
"redirect": reverse("attendance-overtime-view"),
|
"redirect": reverse_lazy("attendance-overtime-view"),
|
||||||
"accessibility": "attendance.sidebar.hour_account_accessibility",
|
"accessibility": "attendance.sidebar.hour_account_accessibility",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("Work Records"),
|
"menu": _("Work Records"),
|
||||||
"redirect": reverse("work-records"),
|
"redirect": reverse_lazy("work-records"),
|
||||||
"accessibility": "attendance.sidebar.work_record_accessibility",
|
"accessibility": "attendance.sidebar.work_record_accessibility",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("Attendance Activities"),
|
"menu": _("Attendance Activities"),
|
||||||
"redirect": reverse("attendance-activity-view"),
|
"redirect": reverse_lazy("attendance-activity-view"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("Late Come Early Out"),
|
"menu": _("Late Come Early Out"),
|
||||||
"redirect": reverse("late-come-early-out-view"),
|
"redirect": reverse_lazy("late-come-early-out-view"),
|
||||||
"accessibility": "attendance.sidebar.tracking_accessibility",
|
"accessibility": "attendance.sidebar.tracking_accessibility",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"menu": _("My Attendances"),
|
"menu": _("My Attendances"),
|
||||||
"redirect": reverse("view-my-attendance"),
|
"redirect": reverse_lazy("view-my-attendance"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -2458,13 +2458,18 @@ def work_records_change_month(request):
|
|||||||
request, employee_filter_form.qs, "attendance.view_attendance"
|
request, employee_filter_form.qs, "attendance.view_attendance"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
all_employees = employees
|
||||||
|
|
||||||
|
paginator_emp = Paginator(employees, 20)
|
||||||
|
page_emp = paginator_emp.get_page(request.GET.get("page"))
|
||||||
|
|
||||||
month_str = request.GET.get("month", f"{date.today().year}-{date.today().month}")
|
month_str = request.GET.get("month", f"{date.today().year}-{date.today().month}")
|
||||||
try:
|
try:
|
||||||
year, month = map(int, month_str.split("-"))
|
year, month = map(int, month_str.split("-"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
year, month = date.today().year, date.today().month
|
year, month = date.today().year, date.today().month
|
||||||
|
|
||||||
employees = [request.user.employee_get] + list(employees)
|
employees = [request.user.employee_get] + list(page_emp.object_list)
|
||||||
|
|
||||||
month_dates = [
|
month_dates = [
|
||||||
datetime(year, month, day).date()
|
datetime(year, month, day).date()
|
||||||
@@ -2474,20 +2479,22 @@ def work_records_change_month(request):
|
|||||||
]
|
]
|
||||||
|
|
||||||
work_records = WorkRecords.objects.filter(
|
work_records = WorkRecords.objects.filter(
|
||||||
date__in=month_dates, employee_id__in=employees
|
date__in=month_dates, employee_id__in=page_emp.object_list
|
||||||
).select_related("employee_id", "shift_id", "attendance_id")
|
).select_related("employee_id", "shift_id", "attendance_id")
|
||||||
|
|
||||||
work_records_dict = {(wr.employee_id.id, wr.date): wr for wr in work_records}
|
work_records_dict = {(wr.employee_id.id, wr.date): wr for wr in work_records}
|
||||||
|
|
||||||
data = {
|
work_record_table = {
|
||||||
employee: [
|
employee: [
|
||||||
work_records_dict.get((employee.id, current_date))
|
work_records_dict.get((employee.id, current_date))
|
||||||
for current_date in month_dates
|
for current_date in month_dates
|
||||||
]
|
]
|
||||||
for employee in employees
|
for employee in all_employees
|
||||||
}
|
}
|
||||||
|
|
||||||
paginator = Paginator(list(data.items()), get_pagination())
|
paginated_table = list(work_record_table.items())
|
||||||
|
|
||||||
|
paginator = Paginator(paginated_table, 20)
|
||||||
page = paginator.get_page(request.GET.get("page"))
|
page = paginator.get_page(request.GET.get("page"))
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
|
|||||||
Reference in New Issue
Block a user