fix: apply linting rules and refactor code
This commit is contained in:
committed by
Muhammad Faraz Maqsood
parent
466aaad85d
commit
ca45009a31
@@ -8,9 +8,9 @@ from user_tasks.conf import settings as user_tasks_settings
|
||||
from user_tasks.models import UserTaskArtifact, UserTaskStatus
|
||||
|
||||
from cms.djangoapps.contentstore.tasks import CourseLinkCheckTask, LinkState, _get_urls
|
||||
from cms.djangoapps.contentstore.utils import create_course_info_usage_key
|
||||
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import get_xblock
|
||||
from cms.djangoapps.contentstore.xblock_storage_handlers.xblock_helpers import usage_key_with_run
|
||||
from lms.djangoapps.courseware.courses import get_course_info_usage_key
|
||||
from openedx.core.lib.xblock_utils import get_course_update_items
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -83,8 +83,8 @@ def _latest_task_status(request, course_key_string, view_func=None):
|
||||
def generate_broken_links_descriptor(json_content, request_user, course_key):
|
||||
"""
|
||||
Returns a Data Transfer Object for frontend given a list of broken links.
|
||||
Includes ALL link types: broken, locked, external-forbidden, and previous run links.
|
||||
Now also includes course updates, handouts, and custom pages.
|
||||
Includes all link types: broken, locked, external-forbidden, and previous run links,
|
||||
as well as links found in course updates, handouts, and custom pages.
|
||||
|
||||
** Example json_content structure **
|
||||
Note: link_state is locked if the link is a studio link and returns 403
|
||||
@@ -449,7 +449,7 @@ def _generate_enhanced_content_structure(course, content_links, content_type):
|
||||
def _generate_course_updates_content(course, updates_links):
|
||||
"""Generate course updates content with categorized links."""
|
||||
store = modulestore()
|
||||
usage_key = get_course_info_usage_key(course, "updates")
|
||||
usage_key = create_course_info_usage_key(course, "updates")
|
||||
updates_block = store.get_item(usage_key)
|
||||
course_updates = []
|
||||
|
||||
@@ -492,7 +492,7 @@ def _generate_course_updates_content(course, updates_links):
|
||||
def _generate_handouts_content(course, handouts_links):
|
||||
"""Generate handouts content with categorized links."""
|
||||
store = modulestore()
|
||||
usage_key = get_course_info_usage_key(course, "handouts")
|
||||
usage_key = create_course_info_usage_key(course, "handouts")
|
||||
handouts_block = store.get_item(usage_key)
|
||||
course_handouts = []
|
||||
|
||||
|
||||
@@ -63,12 +63,12 @@ from cms.djangoapps.contentstore.utils import (
|
||||
)
|
||||
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import get_block_info
|
||||
from cms.djangoapps.models.settings.course_metadata import CourseMetadata
|
||||
from cms.djangoapps.contentstore.utils import create_course_info_usage_key
|
||||
from common.djangoapps.course_action_state.models import CourseRerunState
|
||||
from common.djangoapps.static_replace import replace_static_urls
|
||||
from common.djangoapps.student.auth import has_course_author_access
|
||||
from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole, LibraryUserRole
|
||||
from common.djangoapps.util.monitoring import monitor_import_failure
|
||||
from lms.djangoapps.courseware.courses import get_course_info_usage_key
|
||||
from openedx.core.djangoapps.content.learning_sequences.api import key_supports_outlines
|
||||
from openedx.core.djangoapps.content_libraries import api as v2contentlib_api
|
||||
from openedx.core.djangoapps.content_tagging.api import make_copied_tags_editable
|
||||
@@ -1307,7 +1307,7 @@ def _scan_course_updates_for_links(course):
|
||||
course_updates = []
|
||||
try:
|
||||
store = modulestore()
|
||||
usage_key = get_course_info_usage_key(course, "updates")
|
||||
usage_key = create_course_info_usage_key(course, "updates")
|
||||
updates_block = store.get_item(usage_key)
|
||||
|
||||
if updates_block and hasattr(updates_block, "data"):
|
||||
@@ -1345,7 +1345,7 @@ def _scan_course_handouts_for_links(course):
|
||||
course_handouts = []
|
||||
try:
|
||||
store = modulestore()
|
||||
usage_key = get_course_info_usage_key(course, "handouts")
|
||||
usage_key = create_course_info_usage_key(course, "handouts")
|
||||
handouts_block = store.get_item(usage_key)
|
||||
|
||||
if handouts_block and hasattr(handouts_block, "data") and handouts_block.data:
|
||||
@@ -1377,7 +1377,6 @@ def _scan_custom_pages_for_links(course):
|
||||
if isinstance(tab, StaticTab):
|
||||
try:
|
||||
# Get the static tab content
|
||||
# tab_locator = course_key.make_usage_key("static_tab", tab.url_slug)
|
||||
static_tab_loc = course_key.make_usage_key(
|
||||
"static_tab", tab.url_slug
|
||||
)
|
||||
|
||||
@@ -665,9 +665,9 @@ def use_legacy_logged_out_home():
|
||||
# .. toggle_implementation: CourseWaffleFlag
|
||||
# .. toggle_default: False
|
||||
# .. toggle_description: When enabled, allows the Course Optimizer to detect and update links pointing to previous course runs.
|
||||
# This feature enables instructors to automatically fix internal course links that still point to old course runs
|
||||
# This feature enables instructors to fix internal course links that still point to old course runs
|
||||
# after creating a course rerun.
|
||||
# .. toggle_use_cases: temporary, open_edx
|
||||
# .. toggle_use_cases: temporary
|
||||
# .. toggle_creation_date: 2025-07-21
|
||||
# .. toggle_target_removal_date: None
|
||||
ENABLE_COURSE_OPTIMIZER_CHECK_PREV_RUN_LINKS = CourseWaffleFlag(
|
||||
|
||||
@@ -705,6 +705,13 @@ def get_sequence_usage_keys(course):
|
||||
for subsection in section.get_children()]
|
||||
|
||||
|
||||
def create_course_info_usage_key(course, section_key):
|
||||
"""
|
||||
Returns the usage key for the specified section's course info block.
|
||||
"""
|
||||
return course.id.make_usage_key('course_info', section_key)
|
||||
|
||||
|
||||
def reverse_url(handler_name, key_name=None, key_value=None, kwargs=None):
|
||||
"""
|
||||
Creates the URL for the given handler.
|
||||
|
||||
Reference in New Issue
Block a user