-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
if self.has_non_paginated_response(request): | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[inform] By returning None
here, DRF never calls self.get_paginated_response()
, so we wouldn't be able to conditionally modify self.get_paginated_response()
to behave different with the presence of a ?no_page=1
query parameter.
It feels preferable to rely on this logic living in the paginator than the viewset itself even though it means we have to return a top-level list, e.g.:
[
{
"uuid": "db2372f3-c25c-4c38-8de0-60d4d105e0e3",
"assignment_configuration": "942410d4-ef20-4e4a-9a5f-fa2da07cbb39",
"learner_email": "[[email protected]](mailto:[email protected])",
"lms_user_id": null,
"content_key": "edX+DemoX",
"content_quantity": -19900,
"state": "allocated",
"transaction_uuid": null,
"last_notification_at": null
},
{
"uuid": "f9c7c4c8-11a7-45f7-ae3e-d81029ec5541",
"assignment_configuration": "942410d4-ef20-4e4a-9a5f-fa2da07cbb39",
"learner_email": "[[email protected]](mailto:[email protected])",
"lms_user_id": null,
"content_key": "HarvardX+CS50x",
"content_quantity": -500000,
"state": "allocated",
"transaction_uuid": null,
"last_notification_at": null
}
]
FWIW, the top-level list for non-paginated responses does seem to be the current convention for several (most?) non-paginated list APIs in Enterprise (e.g., enterprise_course_enrollments
) and the broader Open edX platform.
@@ -13,8 +13,8 @@ class AssignmentConfigurationAdmin(DjangoQLSearchMixin, SimpleHistoryAdmin): | |||
Admin configuration for AssignmentConfigurations. | |||
""" | |||
list_display = ( | |||
'enterprise_customer_uuid', | |||
'uuid', |
There was a problem hiding this comment.
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.
|
||
|
||
class PaginationWithPageCount(PageNumberPagination): | ||
class PaginationWithPageCount(DefaultPagination): |
There was a problem hiding this comment.
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).
fe59949
to
530944d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Not gonna block, but I too am leaning on beggs' side of the fence with regards to wanting pagination even if we just set a large page size. Why can't we just make unreasonably large requests take >1 request to fetch the full list, and 99% of the time the normal experience is 1 request?
no_page_query_param = request.query_params.get(self.no_page_query_param) | ||
formatted_no_page_query_param = no_page_query_param.lower() if no_page_query_param else no_page_query_param | ||
return formatted_no_page_query_param |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code-golf nit: you could default the get()
to return an empty string, or use or ''
to do something like e.g.
param_value = request.query_params.get(self.no_page_query_param) or ''
return param_value.lower()
or if we believe no_page
will never be set explicitly as null in the query params, simply
return request.query_params.get(self.no_page_query_param, '').lower()
@pwnage101 @iloveagent57 I've decided to remove the The rationale to no longer include support for Given the uncertainty around which API endpoint(s) will be used to support the learner-facing UX of content assignments (a different assignments list API? extending |
Rather than relying on
from rest_framework.pagination import PageNumberPagination
for the basePaginationWithPageCount
that exists in enterprise-access today and is consumed by viewsets including browse & request, subsidy access policy, and assignments, this PR proposed we rely onfrom edx_rest_framework_extensions.paginators import DefaultPagination
instead, so we don't need to manually set thenum_pages
andcurrent_page
properties ourselves. Additionally, it gives us acurrentPage
property which is useful for working with theDataTable
in consuming MFE(s).Secondly, this PR proposes the introduction of an optional
?no_page
query parameter for any viewset that utilizes a newOptionalPaginationWithPageCount
pagination such that callers can disable pagination for any given request should the use case deem it necessary. The only viewset that utilizes the newOptionalPaginationWithPageCount
is assignments.For example, currently, listing all assignments for a learner on the Dashboard page would only return 10 assignments (unless the frontend naively overrides
?page_size=500
) and force the frontend to traverse the pagination which is not performant for users. In such cases, the?no_page
query parameter could be used to return all assignments as a single list instead of segmented by page.