Skip to content

Commit d516736

Browse files
authored
refactor: Convert BuiltIn Video Block's html from mako to django template (openedx#37509)
Closes: openedx/public-engineering#427
1 parent afe5dab commit d516736

File tree

4 files changed

+291
-267
lines changed

4 files changed

+291
-267
lines changed

lms/djangoapps/courseware/tests/helpers.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"""
44

55

6-
import ast
7-
import re
86
import json
97
from collections import OrderedDict
108
from datetime import timedelta
@@ -444,17 +442,27 @@ def get_expiration_banner_text(user, course, language='en'): # lint-amnesty, py
444442
return bannerText
445443

446444

447-
def get_context_dict_from_string(data):
445+
def get_context_from_dict(data):
448446
"""
449-
Retrieve dictionary from string.
447+
Retrieve validated dictionary from template's contextual data.
448+
449+
Args:
450+
data: The context dictionary to validate
451+
452+
Returns:
453+
dict: context dictionary
450454
"""
451-
# Replace tuple and un-necessary info from inside string and get the dictionary.
452-
cleaned_data = data.split('((\'video.html\',')[1].replace("),\n {})", '').strip()
455+
# Make a copy to avoid modifying the original dict
456+
validated_data = data.copy()
457+
453458
# Omit user_id validation
454-
cleaned_data_without_user = re.sub(".*user_id.*\n?", '', cleaned_data)
459+
validated_data.pop('user_id', None)
460+
461+
# Handle metadata field - parse and sort to ensure consistent ordering
462+
if 'metadata' in validated_data and validated_data['metadata'] is not None:
463+
metadata_dict = json.loads(validated_data['metadata'])
464+
validated_data['metadata'] = OrderedDict(
465+
sorted(metadata_dict.items(), key=lambda t: t[0])
466+
)
455467

456-
validated_data = ast.literal_eval(cleaned_data_without_user)
457-
validated_data['metadata'] = OrderedDict(
458-
sorted(json.loads(validated_data['metadata']).items(), key=lambda t: t[0])
459-
)
460468
return validated_data

0 commit comments

Comments
 (0)