Skip to content
Closed
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
12 changes: 12 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,21 @@

# alternative swagger generator for CMS API
'drf_spectacular',

'openedx_events',

# Learning Core Apps, used by v2 content libraries (content_libraries app)
"openedx_learning.core.components.apps.ComponentsConfig",
"openedx_learning.core.contents.apps.ContentsConfig",
"openedx_learning.core.publishing.apps.PublishingConfig",
]

OPENEDX_LEARNING = {
# Custom file storage, though this is better done through Django's
# STORAGES setting in Django >= 4.2
"STORAGE": None,
}


################# EDX MARKETING SITE ##################################

Expand Down
14 changes: 13 additions & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
# and throws spurious errors. Therefore, we disable invalid-name checking.
# pylint: disable=invalid-name


import importlib.util
import sys
import os
Expand Down Expand Up @@ -3312,9 +3311,22 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring

# Notifications
'openedx.core.djangoapps.notifications',


'openedx_events',

# Learning Core Apps, used by v2 content libraries (content_libraries app)
"openedx_learning.core.components.apps.ComponentsConfig",
"openedx_learning.core.contents.apps.ContentsConfig",
"openedx_learning.core.publishing.apps.PublishingConfig",
]

OPENEDX_LEARNING = {
# Custom file storage, though this is better done through Django's
# STORAGES setting in Django >= 4.2
"STORAGE": None,
}

######################### CSRF #########################################

# Forwards-compatibility with Django 1.7
Expand Down
6 changes: 5 additions & 1 deletion openedx/core/djangoapps/content_libraries/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Admin site for content libraries
"""
from django.contrib import admin
from .models import ContentLibrary, ContentLibraryPermission
from .models import ContentLibrary, ContentLibraryLearningPackage, ContentLibraryPermission


class ContentLibraryPermissionInline(admin.TabularInline):
Expand Down Expand Up @@ -40,3 +40,7 @@ def get_readonly_fields(self, request, obj=None):
return ["library_key", "org", "slug", "bundle_uuid"]
else:
return ["library_key", ]

@admin.register(ContentLibraryLearningPackage)
class ContentLibraryLearningPackageAdmin(admin.ModelAdmin):
pass
110 changes: 108 additions & 2 deletions openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,51 @@ def delete_library(library_key):
log.exception("Failed to delete blockstore bundle %s when deleting library. Delete it manually.", bundle_uuid)
raise


def get_library_blocks(library_key, text_search=None, block_types=None):
return get_library_blocks_learning_core(
#return get_library_blocks_blockstore(
library_key,
text_search=text_search,
block_types=block_types,
)


from openedx_learning.core.publishing.models import Draft, LearningPackage
from .models import ContentLibraryLearningPackage

def get_library_blocks_learning_core(library_key, text_search=None, block_types=None):
"""
We are absolutely ignoring the optional args in the first pass.
"""
lib = ContentLibrary.objects.get_by_key(library_key)
learning_package = ContentLibraryLearningPackage.objects.get(pk=lib.pk).learning_package
drafts = Draft.objects \
.select_related(
'version',
'version__componentversion',
'entity',
'entity__component',
).filter(
entity__learning_package=learning_package,
version__isnull=False,
).all()
return [
LibraryXBlockMetadata(
usage_key=LibraryUsageLocatorV2(
library_key,
draft.entity.component.type,
draft.entity.component.local_key,
),
def_key=None,
display_name=draft.version.title,
has_unpublished_changes=False,
)
for draft in drafts
]



def get_library_blocks_blockstore(library_key, text_search=None, block_types=None):
"""
Get the list of top-level XBlocks in the specified library.

Expand Down Expand Up @@ -717,6 +760,33 @@ def _lookup_usage_key(usage_key):


def get_library_block(usage_key):
return get_library_block_learning_core(usage_key)


def get_library_block_learning_core(usage_key):
library_key = usage_key.lib_key
lib = ContentLibrary.objects.get_by_key(library_key)
learning_package = ContentLibraryLearningPackage.objects.get(pk=lib.pk).learning_package
entity = PublishableEntity.objects.select_related('published', 'draft').get(
learning_package=learning_package,
component__type=usage_key.block_type,
component__local_key=usage_key.block_id,
)
draft_version = entity.draft.version
if hasattr(entity, 'published'):
published_version = entity.published.version
else:
published_version = None

return LibraryXBlockMetadata(
usage_key=usage_key,
def_key=None,
display_name=draft_version.title,
has_unpublished_changes=(draft_version != published_version),
)


def get_library_block_blockstore(usage_key):
"""
Get metadata (LibraryXBlockMetadata) about one specific XBlock in a library

Expand All @@ -733,7 +803,13 @@ def get_library_block(usage_key):
)


def get_library_block_olx(usage_key):
from openedx_learning.core.components.api import get_component_version_content
from openedx_learning.core.components.models import Component, ComponentVersion, ComponentVersionRawContent
from openedx_learning.core.contents.models import RawContent, TextContent
from openedx_learning.core.publishing.models import Draft, LearningPackage, PublishableEntity
from django.db.models import Q

def get_library_block_olx(usage_key: LibraryUsageLocatorV2):
"""
Get the OLX source of the given XBlock.
"""
Expand All @@ -747,6 +823,36 @@ def get_library_block_olx(usage_key):
return xml_str


#xml_str = get_component_version_content(
# str(usage_key.lib_key),
# # xblock.v1:problem@3e8c88ea8ec545b4b3c7066c89527d5e_cvo3nwt344t7ytqts
# f"xblock.v1:{usage_key.definition_key}",
# 1,
# "definition.xml",
#)
# cv_rc = ComponentVersionRawContent.objects.select_related(
# "raw_content",
# "raw_content__text_content"
# "component_version",
# "component_version__component",
# "component_version__component__learning_package",
# )
# Inefficient but simple approach first
learning_package = LearningPackage.objects.get(key=str(usage_key.lib_key))
component = Component.objects.get(
learning_package=learning_package,
namespace='xblock.v1',
type=usage_key.block_type,
local_key=usage_key.block_id,
)
component_version = component.versioning.draft
text_content = component_version.raw_contents.get(key="definition.xml").text_content

print("I really executed! Not a hallucination!")

return text_content.text


def set_library_block_olx(usage_key, new_olx_str):
"""
Replace the OLX source of the given XBlock.
Expand Down
Loading