Skip to content
Merged
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
17 changes: 14 additions & 3 deletions nau_openedx_extensions/edxapp_wrapper/course_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Course block backend abstraction """

import json
import logging

from opaque_keys.edx.keys import CourseKey
Expand All @@ -9,14 +10,24 @@

def get_other_course_settings(course_id):
"""Get Other Course Settings."""
from cms.djangoapps.models.settings.course_metadata import CourseMetadata # pylint: disable=import-error
from xmodule.modulestore.django import modulestore # pylint: disable=import-error
try:
course = modulestore().get_course(course_id)
other_course_settings = CourseMetadata.fetch_all(course).get('other_course_settings', {})
other_course_settings = course.other_course_settings or {}
except Exception as e: # pylint: disable=broad-except
other_course_settings = {}
log.error(f'Error fetching other_course_settings for {e}')
log.error('Error fetching other_course_settings: %s', e)

# Normalize shape for callers.
# Some callers expect `{"value": {...}}`, while modulestore returns `{...}`.
if isinstance(other_course_settings, str):
try:
other_course_settings = json.loads(other_course_settings)
except Exception: # pylint: disable=broad-except
other_course_settings = {}

if isinstance(other_course_settings, dict) and "value" not in other_course_settings:
return {"value": other_course_settings}

return other_course_settings

Expand Down