Skip to content

Commit

Permalink
refactor: import only static content in specific method
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanttV committed Sep 2, 2024
1 parent 5c79cb9 commit 6bd325e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Unreleased
Fixed
=====

* Move contentstore backend imports into the specific methods
* Move ``StaticContent`` import into the specific method
to avoid runtime errors due to circular imports.

0.5.1 - 2024-05-27
Expand Down
3 changes: 0 additions & 3 deletions imagesgallery/edxapp_wrapper/contentstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@ def update_course_run_asset(*args, **kwargs):
backend = import_module(backend_function)

return backend.update_course_run_asset(*args, **kwargs)


StaticContent = get_static_content()
14 changes: 2 additions & 12 deletions imagesgallery/imagesgallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from xblock.reference.user_service import XBlockUser
from xblock.utils.resources import ResourceLoader

from imagesgallery.edxapp_wrapper.contentstore import get_static_content, contentstore, update_course_run_asset
from imagesgallery.edxapp_wrapper.site_configuration import configuration_helpers

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -218,9 +219,6 @@ def studio_view(self, context=None) -> Fragment:
@XBlock.handler
def file_upload(self, request, suffix=''): # pylint: disable=unused-argument
"""Handler for file upload to the course assets."""
# Avoid circular import
from imagesgallery.edxapp_wrapper.contentstore import update_course_run_asset # pylint: disable=import-outside-toplevel

uploaded_content = []
for _, file in request.params.items():
try:
Expand Down Expand Up @@ -289,9 +287,7 @@ def remove_files(self, data, suffix=''): # pylint: disable=unused-argument

def get_asset_json_from_content(self, content):
"""Serialize the content object to a JSON serializable object. """
# Avoid circular import
from imagesgallery.edxapp_wrapper.contentstore import StaticContent # pylint: disable=import-outside-toplevel

StaticContent = get_static_content() # This is done here to avoid circular import
asset_url = StaticContent.serialize_asset_key_with_slash(content.location)
thumbnail_url = StaticContent.serialize_asset_key_with_slash(content.thumbnail_location)
return {
Expand Down Expand Up @@ -342,17 +338,11 @@ def get_all_course_assets_id(self) -> list[str]:
Returns:
list[str]: List of all course assets id.
"""
# Avoid circular import
from imagesgallery.edxapp_wrapper.contentstore import contentstore # pylint: disable=import-outside-toplevel

course_assets, _ = contentstore().get_all_content_for_course(self.course_id)
return [asset["_id"] for asset in course_assets]

def _get_assets_for_page(self, course_key, options):
"""Return course content for given course and options."""
# Avoid circular import
from imagesgallery.edxapp_wrapper.contentstore import contentstore # pylint: disable=import-outside-toplevel

current_page = options["current_page"]
page_size = options["page_size"]
sort = options["sort"]
Expand Down

0 comments on commit 6bd325e

Please sign in to comment.