Skip to content

Commit 2ae4557

Browse files
authored
feat: readd fragment as passthrough to webfragement.fragment (#739)
a previous deprecation of this pass-through causes wide-spread consequences.
1 parent 4b8775c commit 2ae4557

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

CHANGELOG.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Change history for XBlock
55
Unreleased
66
----------
77

8+
4.0.0 - 2024-04-18
9+
------------------
10+
11+
* xblock.fragment has returned as a pass-though component to web_fragments.fragment
12+
813

914
3.0.0 - 2024-03-18
1015
------------------
@@ -15,7 +20,7 @@ will be unaffected by this change. Some improvements have also been made to the
1520

1621
Specific changes:
1722

18-
* **Removed:**
23+
* **Removed:**
1924

2025
* ``xblock.XBlockMixin`` (still available as ``xblock.core.XBlockMixin``)
2126
* ``xblock.core.SharedBlockBase`` (replaced with ``xblock.core.Blocklike``)
@@ -53,7 +58,7 @@ Specific changes:
5358

5459
* Various docstrings have been improved, some of which are published in the docs.
5560
* XBlockAside will now be represented in the API docs, right below XBlock on the "XBlock API" page.
56-
* XBlockMixin has been removed from the docs.
61+
* XBlockMixin has been removed from the docs.
5762
It was only ever documented under the "Fields API" page (which didn't make any sense),
5863
and it was barely even documented there. We considered adding it back to the "XBlock API" page,
5964
but as noted in the class's new docstring, we do not want to encourage any new use of XBlockMixin.

xblock/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
XBlock Courseware Components
33
"""
44

5-
__version__ = '3.1.0'
5+
__version__ = '4.0.0'

xblock/fragment.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Makes the Fragment class available through the old namespace location.
3+
"""
4+
import warnings
5+
6+
import web_fragments.fragment
7+
8+
9+
class Fragment(web_fragments.fragment.Fragment):
10+
"""
11+
A wrapper around web_fragments.fragment.Fragment that provides
12+
backwards compatibility for the old location.
13+
Deprecated.
14+
"""
15+
def __init__(self, *args, **kwargs):
16+
warnings.warn(
17+
'xblock.fragment is deprecated. Please use web_fragments.fragment instead',
18+
DeprecationWarning,
19+
stacklevel=2
20+
)
21+
super().__init__(*args, **kwargs)
22+
23+
# Provide older names for renamed methods
24+
add_frag_resources = web_fragments.fragment.Fragment.add_fragment_resources
25+
add_frags_resources = web_fragments.fragment.Fragment.add_resources

xblock/test/test_fragment.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Unit tests for the Fragment class.
3+
Note: this class has been deprecated in favor of web_fragments.fragment.Fragment
4+
"""
5+
from unittest import TestCase
6+
7+
from xblock.fragment import Fragment
8+
9+
10+
class TestFragment(TestCase):
11+
"""
12+
Unit tests for fragments.
13+
"""
14+
def test_fragment(self):
15+
"""
16+
Test the delegated Fragment class.
17+
"""
18+
TEST_HTML = '<p>Hello, world!</p>' # pylint: disable=invalid-name
19+
fragment = Fragment()
20+
fragment.add_content(TEST_HTML)
21+
self.assertEqual(fragment.body_html(), TEST_HTML)

0 commit comments

Comments
 (0)