From 553a0f03ee10ae96e743432ee34c810920faafe4 Mon Sep 17 00:00:00 2001 From: Esteban Giraldo Date: Tue, 10 Dec 2024 14:48:32 -0500 Subject: [PATCH] feat: pull site configurations for storage each time is required --- edx_sga/sga.py | 9 +++++---- edx_sga/tasks.py | 4 ++-- edx_sga/utils.py | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/edx_sga/sga.py b/edx_sga/sga.py index abf710fc..307ec7b3 100644 --- a/edx_sga/sga.py +++ b/edx_sga/sga.py @@ -54,8 +54,6 @@ log = logging.getLogger(__name__) -default_storage = get_default_storage() - def reify(meth): """ @@ -285,6 +283,7 @@ def upload_assignment(self, request, suffix=""): path, user.username, ) + default_storage = get_default_storage() if default_storage.exists(path): # save latest submission default_storage.delete(path) @@ -330,6 +329,7 @@ def staff_upload_annotated(self, request, suffix=""): state["annotated_mimetype"] = mimetypes.guess_type(upload.file.name)[0] state["annotated_timestamp"] = utcnow().strftime(DateTime.DATETIME_FORMAT) path = self.file_storage_path(sha1, filename) + default_storage = get_default_storage() if not default_storage.exists(path): default_storage.save(path, File(upload.file)) module.state = json.dumps(state) @@ -614,6 +614,7 @@ def clear_student_state(self, *args, **kwargs): used, the block's "clear_student_state" function is called if it exists. """ student_id = kwargs["user_id"] + default_storage = get_default_storage() for submission in submissions_api.get_submissions( self.get_student_item_dict(student_id) ): @@ -979,7 +980,7 @@ def is_zip_file_available(self, user): zip_file_path = get_zip_file_path( user.username, self.block_course_id, self.block_id, self.location ) - return default_storage.exists(zip_file_path) + return get_default_storage().exists(zip_file_path) def count_archive_files(self, user): """ @@ -989,7 +990,7 @@ def count_archive_files(self, user): zip_file_path = get_zip_file_path( user.username, self.block_course_id, self.block_id, self.location ) - with default_storage.open(zip_file_path, "rb") as zip_file: + with get_default_storage().open(zip_file_path, "rb") as zip_file: with closing(ZipFile(zip_file)) as archive: return len(archive.infolist()) diff --git a/edx_sga/tasks.py b/edx_sga/tasks.py index d304822d..2592e8e6 100644 --- a/edx_sga/tasks.py +++ b/edx_sga/tasks.py @@ -16,8 +16,6 @@ log = logging.getLogger(__name__) -default_storage = get_default_storage() - def _get_student_submissions(block_id, course_id, locator): """ @@ -66,6 +64,7 @@ def _compress_student_submissions(zip_file_path, block_id, course_id, locator): zip_file_path, ) # Build the zip file in memory using temporary file. + default_storage = get_default_storage() with tempfile.TemporaryFile() as tmp: with zipfile.ZipFile(tmp, "w", compression=zipfile.ZIP_DEFLATED) as zip_pointer: for student_username, submission_file_path in student_submissions: @@ -100,6 +99,7 @@ def zip_student_submissions(course_id, block_id, locator_unicode, username): locator = BlockUsageLocator.from_string(locator_unicode) zip_file_path = get_zip_file_path(username, course_id, block_id, locator) log.info("Creating zip file for course: %s at path: %s", locator, zip_file_path) + default_storage = get_default_storage() if default_storage.exists(zip_file_path): log.info("Deleting already-existing zip file at path: %s", zip_file_path) default_storage.delete(zip_file_path) diff --git a/edx_sga/utils.py b/edx_sga/utils.py index 8fc11901..51c05c39 100644 --- a/edx_sga/utils.py +++ b/edx_sga/utils.py @@ -8,6 +8,7 @@ from functools import partial import pytz +from django.conf import settings from django.core.files.storage import default_storage as django_default_storage, get_storage_class from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from edx_sga.constants import BLOCK_SIZE