From c015b78cd6ee096a574dc3c5466b71a9f9291403 Mon Sep 17 00:00:00 2001 From: icovada Date: Sat, 10 Jan 2026 17:14:53 +0000 Subject: [PATCH 1/4] Apply CustomNumberPagination to all API views --- app/WYGIWYH/settings.py | 3 +-- app/apps/api/views/accounts.py | 3 --- app/apps/api/views/transactions.py | 7 ------- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/app/WYGIWYH/settings.py b/app/WYGIWYH/settings.py index fe99dca..83b2988 100644 --- a/app/WYGIWYH/settings.py +++ b/app/WYGIWYH/settings.py @@ -433,8 +433,7 @@ REST_FRAMEWORK = { "apps.api.permissions.NotInDemoMode", "rest_framework.permissions.DjangoModelPermissions", ], - "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", - "PAGE_SIZE": 10, + "DEFAULT_PAGINATION_CLASS": "apps.api.custom.pagination.CustomPageNumberPagination", "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", } diff --git a/app/apps/api/views/accounts.py b/app/apps/api/views/accounts.py index 3a6db3e..4c67226 100644 --- a/app/apps/api/views/accounts.py +++ b/app/apps/api/views/accounts.py @@ -6,7 +6,6 @@ from rest_framework.response import Response from apps.accounts.models import AccountGroup, Account from apps.accounts.services import get_account_balance -from apps.api.custom.pagination import CustomPageNumberPagination from apps.api.serializers import AccountGroupSerializer, AccountSerializer, AccountBalanceSerializer @@ -15,7 +14,6 @@ class AccountGroupViewSet(viewsets.ModelViewSet): queryset = AccountGroup.objects.all() serializer_class = AccountGroupSerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return AccountGroup.objects.all().order_by("id") @@ -33,7 +31,6 @@ class AccountViewSet(viewsets.ModelViewSet): queryset = Account.objects.all() serializer_class = AccountSerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return ( diff --git a/app/apps/api/views/transactions.py b/app/apps/api/views/transactions.py index dc1d6f9..e5fbbdd 100644 --- a/app/apps/api/views/transactions.py +++ b/app/apps/api/views/transactions.py @@ -2,7 +2,6 @@ from copy import deepcopy from rest_framework import viewsets -from apps.api.custom.pagination import CustomPageNumberPagination from apps.api.serializers import ( TransactionSerializer, TransactionCategorySerializer, @@ -25,7 +24,6 @@ from apps.rules.signals import transaction_updated, transaction_created class TransactionViewSet(viewsets.ModelViewSet): queryset = Transaction.objects.all() serializer_class = TransactionSerializer - pagination_class = CustomPageNumberPagination def perform_create(self, serializer): instance = serializer.save() @@ -47,7 +45,6 @@ class TransactionViewSet(viewsets.ModelViewSet): class TransactionCategoryViewSet(viewsets.ModelViewSet): queryset = TransactionCategory.objects.all() serializer_class = TransactionCategorySerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return TransactionCategory.objects.all().order_by("id") @@ -56,7 +53,6 @@ class TransactionCategoryViewSet(viewsets.ModelViewSet): class TransactionTagViewSet(viewsets.ModelViewSet): queryset = TransactionTag.objects.all() serializer_class = TransactionTagSerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return TransactionTag.objects.all().order_by("id") @@ -65,7 +61,6 @@ class TransactionTagViewSet(viewsets.ModelViewSet): class TransactionEntityViewSet(viewsets.ModelViewSet): queryset = TransactionEntity.objects.all() serializer_class = TransactionEntitySerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return TransactionEntity.objects.all().order_by("id") @@ -74,7 +69,6 @@ class TransactionEntityViewSet(viewsets.ModelViewSet): class InstallmentPlanViewSet(viewsets.ModelViewSet): queryset = InstallmentPlan.objects.all() serializer_class = InstallmentPlanSerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return InstallmentPlan.objects.all().order_by("-id") @@ -83,7 +77,6 @@ class InstallmentPlanViewSet(viewsets.ModelViewSet): class RecurringTransactionViewSet(viewsets.ModelViewSet): queryset = RecurringTransaction.objects.all() serializer_class = RecurringTransactionSerializer - pagination_class = CustomPageNumberPagination def get_queryset(self): return RecurringTransaction.objects.all().order_by("-id") From db30bcbeb7ec4a4a13753a79c9476fd951ddd47d Mon Sep 17 00:00:00 2001 From: icovada Date: Thu, 8 Jan 2026 21:36:46 +0000 Subject: [PATCH 2/4] Remove filtering function superseesed by search_fields --- app/apps/api/views/dca.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/apps/api/views/dca.py b/app/apps/api/views/dca.py index 5dd0f06..b5b99ed 100644 --- a/app/apps/api/views/dca.py +++ b/app/apps/api/views/dca.py @@ -59,11 +59,6 @@ class DCAEntryViewSet(viewsets.ModelViewSet): "created_at": ["exact", "gte", "lte", "gt", "lt"], "updated_at": ["exact", "gte", "lte", "gt", "lt"], } - search_fields = ["notes"] - ordering_fields = "__all__" - ordering = ["-date"] - - def get_queryset(self): - # Filter entries by strategies the user has access to - accessible_strategies = DCAStrategy.objects.all() - return DCAEntry.objects.filter(strategy__in=accessible_strategies) + search_fields = ['notes'] + ordering_fields = '__all__' + ordering = ['-date'] From 3b2b6d647318ba2ee6a4dba3517715c747f74f89 Mon Sep 17 00:00:00 2001 From: icovada Date: Thu, 8 Jan 2026 21:48:38 +0000 Subject: [PATCH 3/4] Query all DCA Strategies --- app/apps/api/views/dca.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/apps/api/views/dca.py b/app/apps/api/views/dca.py index b5b99ed..5a6947c 100644 --- a/app/apps/api/views/dca.py +++ b/app/apps/api/views/dca.py @@ -6,7 +6,7 @@ from apps.api.serializers import DCAStrategySerializer, DCAEntrySerializer class DCAStrategyViewSet(viewsets.ModelViewSet): - queryset = DCAStrategy.objects.all() + queryset = DCAStrategy.all_objects.all() serializer_class = DCAStrategySerializer filterset_fields = { "name": ["exact", "icontains"], From 49cac0588e8b9006cfc50f0ca7b4ae9d392302ca Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sat, 10 Jan 2026 17:42:37 -0300 Subject: [PATCH 4/4] add tests and fix missing get_queryset --- app/apps/api/views/dca.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/apps/api/views/dca.py b/app/apps/api/views/dca.py index 5a6947c..9360682 100644 --- a/app/apps/api/views/dca.py +++ b/app/apps/api/views/dca.py @@ -6,7 +6,7 @@ from apps.api.serializers import DCAStrategySerializer, DCAEntrySerializer class DCAStrategyViewSet(viewsets.ModelViewSet): - queryset = DCAStrategy.all_objects.all() + queryset = DCAStrategy.objects.all() serializer_class = DCAStrategySerializer filterset_fields = { "name": ["exact", "icontains"], @@ -22,9 +22,6 @@ class DCAStrategyViewSet(viewsets.ModelViewSet): def get_queryset(self): return DCAStrategy.objects.all() - def get_queryset(self): - return DCAStrategy.objects.all().order_by("id") - @action(detail=True, methods=["get"]) def investment_frequency(self, request, pk=None): strategy = self.get_object() @@ -59,6 +56,11 @@ class DCAEntryViewSet(viewsets.ModelViewSet): "created_at": ["exact", "gte", "lte", "gt", "lt"], "updated_at": ["exact", "gte", "lte", "gt", "lt"], } - search_fields = ['notes'] - ordering_fields = '__all__' - ordering = ['-date'] + search_fields = ["notes"] + ordering_fields = "__all__" + ordering = ["-date"] + + def get_queryset(self): + # Filter entries by strategies the user has access to + accessible_strategies = DCAStrategy.objects.all() + return DCAEntry.objects.filter(strategy__in=accessible_strategies)