33
33
LearningCoreXBlockRuntime ,
34
34
)
35
35
from .data import CheckPerm , LatestVersion
36
- from .utils import get_secure_token_for_xblock_handler , get_xblock_id_for_anonymous_user
36
+ from .rest_api .url_converters import VersionConverter
37
+ from .utils import (
38
+ get_secure_token_for_xblock_handler ,
39
+ get_xblock_id_for_anonymous_user ,
40
+ get_auto_latest_version ,
41
+ )
37
42
38
43
from .runtime .learning_core_runtime import LearningCoreXBlockRuntime
39
44
@@ -208,13 +213,26 @@ def get_component_from_usage_key(usage_key: UsageKeyV2) -> Component:
208
213
)
209
214
210
215
211
- def get_block_draft_olx (usage_key : UsageKeyV2 ) -> str :
216
+ def get_block_olx (
217
+ usage_key : UsageKeyV2 ,
218
+ * ,
219
+ version : int | LatestVersion = LatestVersion .AUTO
220
+ ) -> str :
212
221
"""
213
- Get the OLX source of the draft version of the given Learning-Core-backed XBlock.
222
+ Get the OLX source of the of the given Learning-Core-backed XBlock and a version .
214
223
"""
215
- # Inefficient but simple approach. Optimize later if needed.
216
224
component = get_component_from_usage_key (usage_key )
217
- component_version = component .versioning .draft
225
+ version = get_auto_latest_version (version )
226
+
227
+ if version == LatestVersion .DRAFT :
228
+ component_version = component .versioning .draft
229
+ elif version == LatestVersion .PUBLISHED :
230
+ component_version = component .versioning .published
231
+ else :
232
+ assert isinstance (version , int )
233
+ component_version = component .versioning .version_num (version )
234
+ if component_version is None :
235
+ raise NoSuchUsage (usage_key )
218
236
219
237
# TODO: we should probably make a method on ComponentVersion that returns
220
238
# a content based on the name. Accessing by componentversioncontent__key is
@@ -224,6 +242,11 @@ def get_block_draft_olx(usage_key: UsageKeyV2) -> str:
224
242
return content .text
225
243
226
244
245
+ def get_block_draft_olx (usage_key : UsageKeyV2 ) -> str :
246
+ """ DEPRECATED. Use get_block_olx(). Can be removed post-Teak. """
247
+ return get_block_olx (usage_key , version = LatestVersion .DRAFT )
248
+
249
+
227
250
def render_block_view (block , view_name , user ): # pylint: disable=unused-argument
228
251
"""
229
252
Get the HTML, JS, and CSS needed to render the given XBlock view.
0 commit comments