Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PADV-1558 Pull Storage definition from site configuration each time there would be a file process #10

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading