From 40e9413100fae9804442aac709d04c069ca86e65 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 25 Oct 2024 07:32:35 -0500 Subject: [PATCH 1/4] chore: let openedx-learning handle content library asset logic --- .../core/djangoapps/content_libraries/api.py | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index fdfe2ff0efaf..c2a0bcd99640 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -57,6 +57,7 @@ import hashlib import logging import mimetypes +import sys import attr import requests @@ -1176,26 +1177,11 @@ def add_library_block_static_asset_file(usage_key, file_path, file_content, user component = get_component_from_usage_key(usage_key) - media_type_str, _encoding = mimetypes.guess_type(file_path) - # We use "application/octet-stream" as a generic fallback media type, per - # RFC 2046: https://datatracker.ietf.org/doc/html/rfc2046 - # TODO: This probably makes sense to push down to openedx-learning? - media_type_str = media_type_str or "application/octet-stream" - - now = datetime.now(tz=timezone.utc) - with transaction.atomic(): - media_type = authoring_api.get_or_create_media_type(media_type_str) - content = authoring_api.get_or_create_file_content( - component.publishable_entity.learning_package.id, - media_type.id, - data=file_content, - created=now, - ) component_version = authoring_api.create_next_component_version( component.pk, - content_to_replace={file_path: content.id}, - created=now, + content_to_replace={file_path: file_content}, + created=datetime.now(tz=timezone.utc), created_by=user.id if user else None, ) transaction.on_commit( @@ -1220,7 +1206,7 @@ def add_library_block_static_asset_file(usage_key, file_path, file_content, user return LibraryXBlockStaticFile( path=file_path, url=site_root_url + local_path, - size=content.size, + size=sys.getsizeof(file_content), ) From f6d379899afcebba7a3179356272cb60cc765a39 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 25 Oct 2024 11:01:51 -0500 Subject: [PATCH 2/4] fix: use len instead of sys.gesizeof method to return the size --- openedx/core/djangoapps/content_libraries/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index c2a0bcd99640..6c7189a1ac79 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -57,7 +57,7 @@ import hashlib import logging import mimetypes -import sys + import attr import requests @@ -1206,7 +1206,7 @@ def add_library_block_static_asset_file(usage_key, file_path, file_content, user return LibraryXBlockStaticFile( path=file_path, url=site_root_url + local_path, - size=sys.getsizeof(file_content), + size=len(file_content), ) From 70957b6c6b2400d45838bc6ac06faed17db0496e Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 31 Oct 2024 15:52:44 -0500 Subject: [PATCH 3/4] chore: bump openedx-learning to v0.16.2 --- requirements/constraints.txt | 2 +- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/doc.txt | 2 +- requirements/edx/testing.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 1fe478a4b9ae..7001f3217401 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -146,7 +146,7 @@ optimizely-sdk<5.0 # Date: 2023-09-18 # pinning this version to avoid updates while the library is being developed # Issue for unpinning: https://github.com/openedx/edx-platform/issues/35269 -openedx-learning==0.16.1 +openedx-learning==0.16.2 # Date: 2023-11-29 # Open AI version 1.0.0 dropped support for openai.ChatCompletion which is currently in use in enterprise. diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index f1a7db4c80ed..ae0d698a95d1 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -825,7 +825,7 @@ openedx-filters==1.11.0 # -r requirements/edx/kernel.in # lti-consumer-xblock # ora2 -openedx-learning==0.16.1 +openedx-learning==0.16.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/kernel.in diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index eec25125f84b..b92ab3445973 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -1376,7 +1376,7 @@ openedx-filters==1.11.0 # -r requirements/edx/testing.txt # lti-consumer-xblock # ora2 -openedx-learning==0.16.1 +openedx-learning==0.16.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/doc.txt diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index 62f435c49719..6222c182d42c 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -986,7 +986,7 @@ openedx-filters==1.11.0 # -r requirements/edx/base.txt # lti-consumer-xblock # ora2 -openedx-learning==0.16.1 +openedx-learning==0.16.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/base.txt diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 58f778af500e..cc7e6d4ee534 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -1037,7 +1037,7 @@ openedx-filters==1.11.0 # -r requirements/edx/base.txt # lti-consumer-xblock # ora2 -openedx-learning==0.16.1 +openedx-learning==0.16.2 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/base.txt From ded7fd32d8056a6db21d082c15cad95e3cae7022 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 1 Nov 2024 07:39:01 -0500 Subject: [PATCH 4/4] chore: bump openedx-learning to v0.16.3 --- requirements/constraints.txt | 2 +- requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/doc.txt | 2 +- requirements/edx/testing.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 7001f3217401..fd08f9063bba 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -146,7 +146,7 @@ optimizely-sdk<5.0 # Date: 2023-09-18 # pinning this version to avoid updates while the library is being developed # Issue for unpinning: https://github.com/openedx/edx-platform/issues/35269 -openedx-learning==0.16.2 +openedx-learning==0.16.3 # Date: 2023-11-29 # Open AI version 1.0.0 dropped support for openai.ChatCompletion which is currently in use in enterprise. diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index ae0d698a95d1..4d42c4ae73d0 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -825,7 +825,7 @@ openedx-filters==1.11.0 # -r requirements/edx/kernel.in # lti-consumer-xblock # ora2 -openedx-learning==0.16.2 +openedx-learning==0.16.3 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/kernel.in diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index b92ab3445973..b583538f3d84 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -1376,7 +1376,7 @@ openedx-filters==1.11.0 # -r requirements/edx/testing.txt # lti-consumer-xblock # ora2 -openedx-learning==0.16.2 +openedx-learning==0.16.3 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/doc.txt diff --git a/requirements/edx/doc.txt b/requirements/edx/doc.txt index 6222c182d42c..25198e64241e 100644 --- a/requirements/edx/doc.txt +++ b/requirements/edx/doc.txt @@ -986,7 +986,7 @@ openedx-filters==1.11.0 # -r requirements/edx/base.txt # lti-consumer-xblock # ora2 -openedx-learning==0.16.2 +openedx-learning==0.16.3 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/base.txt diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index cc7e6d4ee534..18d4d558ebec 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -1037,7 +1037,7 @@ openedx-filters==1.11.0 # -r requirements/edx/base.txt # lti-consumer-xblock # ora2 -openedx-learning==0.16.2 +openedx-learning==0.16.3 # via # -c requirements/edx/../constraints.txt # -r requirements/edx/base.txt