Files
edx-platform/openedx/core/apidocs.py
Kyle McCormick ec9ac34886 Paginate course card API for Programs Learner Portal
* Pull business logic of ProgramCourseEnrollmentOverviewView
  out of view class and into utils.py.
* Add UserProgramCourseEnrollmentsView, which is a paginated
  version of ProgramCourseEnrollmentOverviewView with a
  URL that is parameterized on the user (to enable masquerading
  in MST-109).
* Add get_certificates_for_user_by_course_keys to certs API
  to make enrollments overviews REST API use fewer SQL queries.
* Document new course cards API with edx-api-doc-tools.

In a follow-up ticket, the Programs Learner Portal will switch
to the new paginatd API in order to speed up its page load.

MST-126
2020-05-04 09:26:23 -04:00

55 lines
1.9 KiB
Python

"""
Open API support.
"""
from edx_api_doc_tools import make_api_info
from rest_framework import serializers
api_info = make_api_info(
title="Open edX API",
version="v1",
description="APIs for access to Open edX information",
#terms_of_service="https://www.google.com/policies/terms/", # TODO: Do we have these?
email="oscm@edx.org",
#license=openapi.License(name="BSD License"), # TODO: What does this mean?
)
def cursor_paginate_serializer(inner_serializer_class):
"""
Create a cursor-paginated version of a serializer.
This is hacky workaround for an edx-api-doc-tools issue described here:
https://github.com/edx/api-doc-tools/issues/32
It assumes we are using cursor-style pagination and assumes a specific
schema for the pages. It should be removed once we address the underlying issue.
Arguments:
inner_serializer_class (type): A subclass of ``Serializer``.
Returns: type
A subclass of ``Serializer`` to model the schema of a page of a cursor-paginated
endpoint.
"""
class PageOfInnerSerializer(serializers.Serializer):
"""
A serializer for a page of a cursor-paginated list of ``inner_serializer_class``.
"""
# pylint: disable=abstract-method
previous = serializers.URLField(
required=False,
help_text="Link to the previous page or results, or null if this is the first.",
)
next = serializers.URLField(
required=False,
help_text="Link to the next page of results, or null if this is the last.",
)
results = serializers.ListField(
child=inner_serializer_class(),
help_text="The list of result objects on this page.",
)
PageOfInnerSerializer.__name__ = 'PageOf{}'.format(inner_serializer_class.__name__)
return PageOfInnerSerializer