feat: finish phase 4 portal review fixes
This commit is contained in:
+19
-2
@@ -1,5 +1,6 @@
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Sum
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse, reverse_lazy
|
||||
@@ -74,6 +75,18 @@ def get_usage_ledger_entries_for_user(user):
|
||||
)
|
||||
|
||||
|
||||
def paginate_records(request, queryset):
|
||||
paginator = Paginator(queryset, RECORDS_PAGE_SIZE)
|
||||
page_obj = paginator.get_page(request.GET.get("page"))
|
||||
return {
|
||||
"paginator": paginator,
|
||||
"page_obj": page_obj,
|
||||
"is_paginated": page_obj.has_other_pages(),
|
||||
"records_total_count": paginator.count,
|
||||
"records_page_size": RECORDS_PAGE_SIZE,
|
||||
}
|
||||
|
||||
|
||||
class DashboardView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "portal/dashboard.html"
|
||||
|
||||
@@ -175,8 +188,10 @@ class RechargeRecordListView(LoginRequiredMixin, TemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
orders = get_recharge_orders_for_user(self.request.user)
|
||||
pagination = paginate_records(self.request, orders)
|
||||
context.update(get_portal_account_summary(self.request.user))
|
||||
context["recharge_orders"] = orders[:RECORDS_PAGE_SIZE]
|
||||
context.update(pagination)
|
||||
context["recharge_orders"] = pagination["page_obj"].object_list
|
||||
return context
|
||||
|
||||
|
||||
@@ -186,6 +201,8 @@ class UsageRecordListView(LoginRequiredMixin, TemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
entries = get_usage_ledger_entries_for_user(self.request.user)
|
||||
pagination = paginate_records(self.request, entries)
|
||||
context.update(get_portal_account_summary(self.request.user))
|
||||
context["usage_entries"] = entries[:RECORDS_PAGE_SIZE]
|
||||
context.update(pagination)
|
||||
context["usage_entries"] = pagination["page_obj"].object_list
|
||||
return context
|
||||
|
||||
Reference in New Issue
Block a user