Skip to content

Commit

Permalink
Merge branch 'master' into bleach#33209
Browse files Browse the repository at this point in the history
  • Loading branch information
irtazaakram authored Jun 12, 2024
2 parents b8008a8 + 5a9c383 commit ceb19b3
Show file tree
Hide file tree
Showing 24 changed files with 339 additions and 551 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-consistent-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- uses: actions/setup-python@v5
if: ${{ env.RELEVANT == 'true' }}
with:
python-version: "3.8"
python-version: '3.11'

- name: "Recompile requirements"
if: ${{ env.RELEVANT == 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compile-python-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.11"

- name: Run make compile-requirements
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade-one-python-dependency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.11"

- name: Update any pinned dependencies
env:
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/api/views/course_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,5 @@ def _stats_dict(self, data): # lint-amnesty, pylint: disable=missing-function-d
max=max(data),
mean=np.around(np.mean(data)),
median=np.around(np.median(data)),
mode=stats.mode(data, axis=None)[0][0],
mode=stats.mode(data, axis=None)[0],
)
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_library_validation(self):
}

@skip("This endpoint shouldn't support num_blocks and has_unpublished_*.")
@patch("openedx.core.djangoapps.content_libraries.views.LibraryApiPagination.page_size", new=2)
@patch("openedx.core.djangoapps.content_libraries.views.LibraryRootView.pagination_class.page_size", new=2)
def test_list_library(self):
"""
Test the /libraries API and its pagination
Expand Down Expand Up @@ -374,7 +374,7 @@ def test_library_blocks_studio_view(self):
assert 'resources' in fragment
assert 'Hello world!' in fragment['content']

@patch("openedx.core.djangoapps.content_libraries.views.LibraryApiPagination.page_size", new=2)
@patch("openedx.core.djangoapps.content_libraries.views.LibraryBlocksView.pagination_class.page_size", new=2)
def test_list_library_blocks(self):
"""
Test the /libraries/{lib_key_str}/blocks API and its pagination
Expand Down
38 changes: 17 additions & 21 deletions openedx/core/djangoapps/content_libraries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@
from organizations.models import Organization
from rest_framework import status
from rest_framework.exceptions import NotFound, PermissionDenied, ValidationError
from rest_framework.pagination import PageNumberPagination
from rest_framework.generics import GenericAPIView
from rest_framework.parsers import MultiPartParser
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ViewSet
from rest_framework.viewsets import GenericViewSet

from openedx.core.djangoapps.content_libraries import api, permissions
from openedx.core.djangoapps.content_libraries.serializers import (
Expand Down Expand Up @@ -153,13 +153,10 @@ def wrapped_fn(*args, **kwargs):
return wrapped_fn


class LibraryApiPagination(PageNumberPagination):
class LibraryApiPaginationDocs:
"""
Paginates over ContentLibraryMetadata objects.
API docs for query params related to paginating ContentLibraryMetadata objects.
"""
page_size = 50
page_size_query_param = 'page_size'

apidoc_params = [
apidocs.query_parameter(
'pagination',
Expand All @@ -181,14 +178,14 @@ class LibraryApiPagination(PageNumberPagination):

@method_decorator(non_atomic_requests, name="dispatch")
@view_auth_classes()
class LibraryRootView(APIView):
class LibraryRootView(GenericAPIView):
"""
Views to list, search for, and create content libraries.
"""

@apidocs.schema(
parameters=[
*LibraryApiPagination.apidoc_params,
*LibraryApiPaginationDocs.apidoc_params,
apidocs.query_parameter(
'org',
str,
Expand All @@ -211,21 +208,20 @@ def get(self, request):
library_type = serializer.validated_data['type']
text_search = serializer.validated_data['text_search']

paginator = LibraryApiPagination()
queryset = api.get_libraries_for_user(
request.user,
org=org,
library_type=library_type,
text_search=text_search,
)
paginated_qs = paginator.paginate_queryset(queryset, request)
paginated_qs = self.paginate_queryset(queryset)
result = api.get_metadata(paginated_qs)

serializer = ContentLibraryMetadataSerializer(result, many=True)
# Verify `pagination` param to maintain compatibility with older
# non pagination-aware clients
if request.GET.get('pagination', 'false').lower() == 'true':
return paginator.get_paginated_response(serializer.data)
return self.get_paginated_response(serializer.data)
return Response(serializer.data)

def post(self, request):
Expand Down Expand Up @@ -506,13 +502,14 @@ def delete(self, request, lib_key_str): # pylint: disable=unused-argument

@method_decorator(non_atomic_requests, name="dispatch")
@view_auth_classes()
class LibraryBlocksView(APIView):
class LibraryBlocksView(GenericAPIView):
"""
Views to work with XBlocks in a specific content library.
"""

@apidocs.schema(
parameters=[
*LibraryApiPagination.apidoc_params,
*LibraryApiPaginationDocs.apidoc_params,
apidocs.query_parameter(
'text_search',
str,
Expand All @@ -538,13 +535,12 @@ def get(self, request, lib_key_str):
api.require_permission_for_library_key(key, request.user, permissions.CAN_VIEW_THIS_CONTENT_LIBRARY)
components = api.get_library_components(key, text_search=text_search, block_types=block_types)

paginator = LibraryApiPagination()
paginated_xblock_metadata = [
api.LibraryXBlockMetadata.from_component(key, component)
for component in paginator.paginate_queryset(components, request)
for component in self.paginate_queryset(components)
]
serializer = LibraryXBlockMetadataSerializer(paginated_xblock_metadata, many=True)
return paginator.get_paginated_response(serializer.data)
return self.get_paginated_response(serializer.data)

@convert_exceptions
def post(self, request, lib_key_str):
Expand Down Expand Up @@ -742,7 +738,7 @@ def delete(self, request, usage_key_str, file_path):

@method_decorator(non_atomic_requests, name="dispatch")
@view_auth_classes()
class LibraryImportTaskViewSet(ViewSet):
class LibraryImportTaskViewSet(GenericViewSet):
"""
Import blocks from Courseware through modulestore.
"""
Expand All @@ -760,9 +756,9 @@ def list(self, request, lib_key_str):
)
queryset = api.ContentLibrary.objects.get_by_key(library_key).import_tasks
result = ContentLibraryBlockImportTaskSerializer(queryset, many=True).data
paginator = LibraryApiPagination()
return paginator.get_paginated_response(
paginator.paginate_queryset(result, request)

return self.get_paginated_response(
self.paginate_queryset(result)
)

@convert_exceptions
Expand Down
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ click>=8.0,<9.0
# The team that owns this package will manually bump this package rather than having it pulled in automatically.
# This is to allow them to better control its deployment and to do it in a process that works better
# for them.
edx-enterprise==4.19.14
edx-enterprise==4.19.17

# Stay on LTS version, remove once this is added to common constraint
Django<5.0
Expand Down
26 changes: 11 additions & 15 deletions requirements/edx-sandbox/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
Expand All @@ -14,15 +14,13 @@ click==8.1.6
# nltk
codejail-includes==1.0.0
# via -r requirements/edx-sandbox/base.in
contourpy==1.1.1
contourpy==1.2.1
# via matplotlib
cryptography==42.0.7
cryptography==42.0.8
# via -r requirements/edx-sandbox/base.in
cycler==0.12.1
# via matplotlib
fonttools==4.51.0
# via matplotlib
importlib-resources==6.4.0
fonttools==4.53.0
# via matplotlib
joblib==1.4.2
# via nltk
Expand All @@ -37,17 +35,17 @@ markupsafe==2.1.5
# via
# chem
# openedx-calc
matplotlib==3.7.5
matplotlib==3.9.0
# via -r requirements/edx-sandbox/base.in
mpmath==1.3.0
# via sympy
networkx==3.1
networkx==3.3
# via -r requirements/edx-sandbox/base.in
nltk==3.8.1
# via
# -r requirements/edx-sandbox/base.in
# chem
numpy==1.24.4
numpy==1.26.4
# via
# chem
# contourpy
Expand All @@ -56,7 +54,7 @@ numpy==1.24.4
# scipy
openedx-calc==3.1.0
# via -r requirements/edx-sandbox/base.in
packaging==24.0
packaging==24.1
# via matplotlib
pillow==10.3.0
# via matplotlib
Expand All @@ -72,9 +70,9 @@ python-dateutil==2.9.0.post0
# via matplotlib
random2==1.0.2
# via -r requirements/edx-sandbox/base.in
regex==2024.5.10
regex==2024.5.15
# via nltk
scipy==1.10.1
scipy==1.13.1
# via
# -r requirements/edx-sandbox/base.in
# chem
Expand All @@ -83,11 +81,9 @@ six==1.16.0
# via
# codejail-includes
# python-dateutil
sympy==1.12
sympy==1.12.1
# via
# -r requirements/edx-sandbox/base.in
# openedx-calc
tqdm==4.66.4
# via nltk
zipp==3.18.1
# via importlib-resources
7 changes: 2 additions & 5 deletions requirements/edx/assets.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
Expand All @@ -12,10 +12,7 @@ libsass==0.10.0
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/assets.in
nodeenv==1.8.0
nodeenv==1.9.1
# via -r requirements/edx/assets.in
six==1.16.0
# via libsass

# The following packages are considered to be unsafe in a requirements file:
# setuptools
Loading

0 comments on commit ceb19b3

Please sign in to comment.