Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rely on DefaultPagination from edx_rest_framework_extensions #290

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def test_list(self, role_context_dict):
# Send a list request for all Assignments for the requesting user.
response = self.client.get(ASSIGNMENTS_LIST_ENDPOINT)

# Only Assignments that match the following qualifications are returned:
# Only Assignments that match the following qualifications are returned in paginated response:
# 1. Assignment is for the requesting user.
# 2. Assignment is in the requested AssignementConfiguration.
expected_assignments_for_requester = [
Expand Down
18 changes: 9 additions & 9 deletions enterprise_access/apps/api/v1/views/utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""
Utilities for REST API View and Viewset classes.
"""
from rest_framework.pagination import PageNumberPagination
from django.conf import settings
from edx_rest_framework_extensions.paginators import DefaultPagination


class PaginationWithPageCount(PageNumberPagination):
class PaginationWithPageCount(DefaultPagination):
Copy link
Member Author

@adamstankiewicz adamstankiewicz Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By migrating from PageNumberPagination (DRF standard) -> DefaultPagination (Open edX standard), list APIs throughout enterprise-access will have additional properties such as num_pages and current_page without extra effort.

However, it does mean we have to override DefaultPagination's page_size to keep the original page_size for PaginationWithPageCount in place (i.e., relies on the REST_FRAMEWORK.PAGE_SIZE Django settings).

"""
A PageNumber paginator that adds the total number of pages to the paginated response.
A PageNumber paginator that adds the total number of pages
and the current page to the paginated response.
"""

page_size_query_param = 'page_size'
# The configured `PAGE_SIZE` in Django settings must be used as the default page size as opposed
# to relying on the default `page_size` specified via `DefaultPagination` in order to maintain
# backwards compatibility with existing API clients.
page_size = settings.REST_FRAMEWORK.get('PAGE_SIZE')
max_page_size = 500

def get_paginated_response(self, data):
""" Adds a ``num_pages`` field into the paginated response. """
response = super().get_paginated_response(data)
response.data['num_pages'] = self.page.paginator.num_pages
return response
2 changes: 1 addition & 1 deletion enterprise_access/apps/content_assignments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AssignmentConfigurationAdmin(DjangoQLSearchMixin, SimpleHistoryAdmin):
Admin configuration for AssignmentConfigurations.
"""
list_display = (
'enterprise_customer_uuid',
'uuid',
Copy link
Member Author

@adamstankiewicz adamstankiewicz Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opting to treat uuid as the clickable cell to go into the detail page in Django Admin from the list page of assignments. It felt a bit odd clicking on an enterprise customer UUID to go into a specific content assignment.

'enterprise_customer_uuid',
'active',
'modified',
)
Expand Down
Loading