Skip to content

Commit aa2cf24

Browse files
committed
chore: update the extracted HTML XBlock to fix the test failures
1 parent c45915c commit aa2cf24

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

xblocks_contrib/common/xml_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,19 @@ def own_metadata(block: XBlock) -> dict[str, Any]:
131131
Return a JSON-friendly dictionary that contains only non-inherited field
132132
keys, mapped to their serialized values
133133
"""
134-
return block.get_explicitly_set_fields_by_scope(Scope.settings)
134+
result = {}
135+
for field in block.fields.values(): # lint-amnesty, pylint: disable=no-member
136+
if field.scope == Scope.settings and field.is_set_on(block):
137+
try:
138+
result[field.name] = field.read_json(block)
139+
except TypeError as exception:
140+
exception_message = "{message}, Block-location:{location}, Field-name:{field_name}".format(
141+
message=str(exception),
142+
location=str(block.location),
143+
field_name=field.name
144+
)
145+
raise TypeError(exception_message) # lint-amnesty, pylint: disable=raise-missing-from
146+
return result
135147

136148

137149
class LegacyXmlMixin:

xblocks_contrib/html/html.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ class HtmlBlock(LegacyXmlMixin, XBlock): # pylint: disable=abstract-method
159159
default=_("Text"),
160160
)
161161
data = String(help=_("Html contents to display for this block"), default="", scope=Scope.content)
162+
upstream_data = String(
163+
help=_("Upstream html contents to store upstream data field"),
164+
default=None,
165+
hidden=True,
166+
enforce_type=True,
167+
scope=Scope.content,
168+
)
162169
source_code = String(
163170
help=_("Source code for LaTeX documents. This feature is not well-supported."), scope=Scope.settings
164171
)
@@ -179,6 +186,7 @@ class HtmlBlock(LegacyXmlMixin, XBlock): # pylint: disable=abstract-method
179186
uses_xmodule_styles_setup = True
180187
template_dir_name = "html"
181188
show_in_read_only_mode = True
189+
icon_class = "other"
182190

183191
@property
184192
def category(self):
@@ -252,17 +260,26 @@ def get_html(self):
252260
user_id = current_user.opt_attrs.get(ATTR_KEY_DEPRECATED_ANONYMOUS_USER_ID)
253261
if user_id:
254262
data = data.replace("%%USER_ID%%", user_id)
263+
if current_user.emails:
264+
email = current_user.emails[0]
265+
data = data.replace("%%USER_EMAIL%%", email)
255266

256267
# The course ID replacement is always safe to run.
257268
data = data.replace("%%COURSE_ID%%", str(self.scope_ids.usage_id.context_key))
258269
return data
259270

260271
def studio_view(self, context=None): # pylint: disable=unused-argument
261272
"""Return a fragment that contains the html for the studio view."""
262-
frag = Fragment(self.get_html())
263-
frag.add_javascript("""function HtmlBlock(runtime, element){}""")
264-
frag.initialize_js("HtmlBlock")
265-
return frag
273+
# Only the ReactJS editor is supported for this block.
274+
# See https://github.com/openedx/frontend-app-authoring/tree/master/src/editors/containers/TextEditor
275+
raise NotImplementedError
276+
277+
@classmethod
278+
def get_customizable_fields(cls) -> dict[str, str | None]:
279+
return {
280+
"display_name": "upstream_display_name",
281+
"data": "upstream_data",
282+
}
266283

267284
# VS[compat] TODO (cpennington): Delete this method once all fall 2012 course
268285
# are being edited in the cms

0 commit comments

Comments
 (0)