Skip to content

Commit

Permalink
feat: pull site configurations for storage each time is required
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekenhei committed Dec 10, 2024
1 parent 67004c6 commit 553a0f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions edx_sga/sga.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@

log = logging.getLogger(__name__)

default_storage = get_default_storage()


def reify(meth):
"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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())

Expand Down
4 changes: 2 additions & 2 deletions edx_sga/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

log = logging.getLogger(__name__)

default_storage = get_default_storage()


def _get_student_submissions(block_id, course_id, locator):
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions edx_sga/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 553a0f0

Please sign in to comment.