Skip to content

Commit 5dae386

Browse files
committed
fix: pylint and mypy
1 parent 2cb3ab7 commit 5dae386

6 files changed

Lines changed: 34 additions & 16 deletions

File tree

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ def _migrate_container(
867867
container_exists = False
868868
if PublishableEntity.objects.filter(
869869
learning_package_id=context.target_package_id,
870-
key=target_key.container_id,
870+
entity_ref=target_key.container_id,
871871
).exists():
872872
libraries_api.restore_container(container_key=target_key)
873873
container = libraries_api.get_container(target_key)

openedx/core/djangoapps/content/search/documents.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from hashlib import blake2b
88

99
from django.core.exceptions import ObjectDoesNotExist
10+
from django.db.models import F
1011
from django.utils.text import slugify
1112
from opaque_keys.edx.keys import ContainerKey, LearningContextKey, OpaqueKey, UsageKey
1213
from opaque_keys.edx.locator import LibraryCollectionLocator, LibraryContainerLocator
@@ -64,7 +65,8 @@ class Fields:
6465
tags_level2 = "level2"
6566
tags_level3 = "level3"
6667
# Collections (dictionary) that this object belongs to.
67-
# Similarly to tags above, we collect the collection.titles and collection.collection_codes into hierarchical facets.
68+
# Similarly to tags above, we collect the collection.titles and collection.collection_codes
69+
# into hierarchical facets.
6870
collections = "collections"
6971
collections_display_name = "display_name"
7072
collections_key = "key"
@@ -448,10 +450,13 @@ def searchable_doc_collections(object_id: OpaqueKey) -> dict:
448450
try:
449451
if isinstance(object_id, UsageKey):
450452
component = lib_api.get_component_from_usage_key(object_id)
453+
# Temporarily alias collection_code to "key" so downstream consumers
454+
# (search indexer, REST API) keep the same field name. We will update
455+
# downstream consumers later: https://github.com/openedx/openedx-platform/issues/38406
451456
collections = content_api.get_entity_collections(
452457
component.learning_package_id,
453458
component.entity_ref,
454-
).values('key', 'title')
459+
).values(key=F('collection_code'), title=F('title'))
455460
elif isinstance(object_id, LibraryContainerLocator):
456461
container = lib_api.get_container(object_id, include_collections=True)
457462
collections = container.collections

openedx/core/djangoapps/content_libraries/api/blocks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from django.core.exceptions import ObjectDoesNotExist, ValidationError
1616
from django.core.validators import validate_unicode_slug
1717
from django.db import transaction
18-
from django.db.models import QuerySet
18+
from django.db.models import F, QuerySet
1919
from django.urls import reverse
2020
from django.utils.text import slugify
2121
from django.utils.translation import gettext as _
@@ -176,10 +176,13 @@ def get_library_block(usage_key: LibraryUsageLocatorV2, include_collections=Fals
176176
raise ContentLibraryBlockNotFound(usage_key)
177177

178178
if include_collections:
179+
# Temporarily alias collection_code to "key" so downstream consumers
180+
# (search indexer, REST API) keep the same field name. We will update
181+
# downstream consumers later: https://github.com/openedx/openedx-platform/issues/38406
179182
associated_collections = content_api.get_entity_collections(
180183
component.learning_package_id,
181184
component.entity_ref,
182-
).values('key', 'title')
185+
).values(key=F('collection_code'), title=F('title'))
183186
else:
184187
associated_collections = None
185188
xblock_metadata = LibraryXBlockMetadata.from_component(

openedx/core/djangoapps/content_libraries/api/containers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from uuid import uuid4
1111

1212
from django.db import transaction
13+
from django.db.models import F
1314
from django.utils.text import slugify
1415
from opaque_keys.edx.locator import LibraryContainerLocator, LibraryLocatorV2, LibraryUsageLocatorV2
1516
from openedx_content import api as content_api
@@ -73,10 +74,13 @@ def get_container(
7374
"""
7475
container = get_container_from_key(container_key)
7576
if include_collections:
77+
# Temporarily alias collection_code to "key" so downstream consumers
78+
# (search indexer, REST API) keep the same field name. We will update
79+
# downstream consumers later: https://github.com/openedx/openedx-platform/issues/38406
7680
associated_collections = content_api.get_entity_collections(
7781
container.publishable_entity.learning_package_id,
7882
container_key.container_id,
79-
).values("key", "title")
83+
).values(key=F("collection_code"), title=F("title"))
8084
else:
8185
associated_collections = None
8286
container_meta = ContainerMetadata.from_container(

openedx/core/djangoapps/content_libraries/tasks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def send_events_after_publish(publish_log_pk: int, library_key_str: str) -> None
142142
pass
143143
else:
144144
log.warning(
145-
f"PublishableEntity {record.entity.pk} / {record.entity.entity_ref} was modified during publish operation "
146-
"but is of unknown type."
145+
f"PublishableEntity {record.entity.pk} / {record.entity.entity_ref} "
146+
"was modified during publish operation but is of unknown type."
147147
)
148148

149149
for container_key in affected_containers:
@@ -246,8 +246,8 @@ def send_events_after_revert(draft_change_log_id: int, library_key_str: str) ->
246246
updated_container_keys.add(container_key)
247247
else:
248248
log.warning(
249-
f"PublishableEntity {record.entity.pk} / {record.entity.entity_ref} was modified during publish operation "
250-
"but is of unknown type."
249+
f"PublishableEntity {record.entity.pk} / {record.entity.entity_ref} "
250+
"was modified during publish operation but is of unknown type."
251251
)
252252
# If any collections contain this entity, their item count may need to be updated, e.g. if this was a
253253
# newly created component in the collection and is now deleted, or this was deleted and is now re-added.
@@ -256,7 +256,7 @@ def send_events_after_revert(draft_change_log_id: int, library_key_str: str) ->
256256
):
257257
collection_key = api.library_collection_locator(
258258
library_key=library_key,
259-
collection_key=parent_collection.key,
259+
collection_key=parent_collection.collection_code,
260260
)
261261
affected_collection_keys.add(collection_key)
262262

@@ -541,7 +541,7 @@ def backup_library(self, user_id: int, library_key_str: str) -> None:
541541
file_path = os.path.join(root_dir, filename)
542542
user = User.objects.get(id=user_id)
543543
origin_server = getattr(settings, 'CMS_BASE', None)
544-
create_lib_zip_file(lp_key=str(library_key), path=file_path, user=user, origin_server=origin_server)
544+
create_lib_zip_file(package_ref=str(library_key), path=file_path, user=user, origin_server=origin_server)
545545
set_custom_attribute("exporting_completed", str(library_key))
546546

547547
with open(file_path, 'rb') as zipfile:

openedx/core/djangoapps/content_libraries/tests/test_api.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ def test_set_library_component_collections(self) -> None:
325325
)
326326

327327
assert self.lib2.learning_package_id is not None
328-
assert len(content_api.get_collection(self.lib2.learning_package_id, self.col2.collection_code).entities.all()) == 1
329-
assert len(content_api.get_collection(self.lib2.learning_package_id, self.col3.collection_code).entities.all()) == 1
328+
col2 = content_api.get_collection(self.lib2.learning_package_id, self.col2.collection_code)
329+
col3 = content_api.get_collection(self.lib2.learning_package_id, self.col3.collection_code)
330+
assert len(col2.entities.all()) == 1
331+
assert len(col3.entities.all()) == 1
330332

331333
self.assertDictContainsEntries(
332334
event_receiver.call_args_list[0].kwargs,
@@ -345,11 +347,15 @@ def test_set_library_component_collections(self) -> None:
345347
assert all(event["signal"] == LIBRARY_COLLECTION_UPDATED for event in collection_update_events)
346348
assert {event["library_collection"] for event in collection_update_events} == {
347349
LibraryCollectionData(
348-
collection_key=api.library_collection_locator(self.lib2.library_key, collection_key=self.col2.collection_code),
350+
collection_key=api.library_collection_locator(
351+
self.lib2.library_key, collection_key=self.col2.collection_code,
352+
),
349353
background=True,
350354
),
351355
LibraryCollectionData(
352-
collection_key=api.library_collection_locator(self.lib2.library_key, collection_key=self.col3.collection_code),
356+
collection_key=api.library_collection_locator(
357+
self.lib2.library_key, collection_key=self.col3.collection_code,
358+
),
353359
background=True,
354360
)
355361
}

0 commit comments

Comments
 (0)