Skip to content

Commit 5a0b5c7

Browse files
committed
refactor: Tweak category definition to work with existing mocks
Defining through usage_key instead of scope_ids broke some tests which are partially mocking scope_ids
1 parent d64e833 commit 5a0b5c7

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

openedx/core/djangoapps/content/block_structure/block_structure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ def __init__(self, usage_key):
393393
# Map of transformer name to its block-specific data.
394394
self.transformer_data = TransformerDataMap()
395395

396+
@property
397+
def usage_key(self):
398+
return self.location
399+
396400

397401
class BlockStructureBlockData(BlockStructure):
398402
"""

xmodule/x_module.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,31 @@ def system(self):
311311

312312
@property
313313
def course_id(self):
314-
"""Return the course key for this block."""
314+
"""
315+
Return the key of the block to which this Course belongs.
316+
317+
New code should always used `context_key`, which is the key of the Learning Context to which
318+
this block belongs. "Learning Context" is a generalized notion of Courses which is inclusive
319+
of Content Libraries, et al.
320+
"""
315321
return self.context_key
316322

317323
@property
318324
def category(self):
319-
"""Return the block type/category."""
320-
return self.usage_key.block_type
325+
"""
326+
Return the block type, formerly known as "category".
327+
328+
Preferred forms for new code: `self.usage_key.block_type` or `self.scope_ids.blocks_type`
329+
"""
330+
return self.scope_ids.block_type
321331

322332
@property
323333
def location(self):
324-
"""Return the usage key identifying this block instance."""
334+
"""
335+
Return the usage key identifying this block instance, formerly called the "location".
336+
337+
`self.usage_key` is always preferred in new code.
338+
"""
325339
return self.usage_key
326340

327341
@location.setter
@@ -334,7 +348,11 @@ def location(self, value):
334348

335349
@property
336350
def url_name(self):
337-
"""Return the URL-friendly name for this block."""
351+
"""
352+
Return the URL-friendly name for this block.
353+
354+
Preferred forms for new code: `self.usage_key.block_id`
355+
"""
338356
return self.usage_key.block_id
339357

340358
@property

0 commit comments

Comments
 (0)