Skip to content

Commit 31d1695

Browse files
authored
feat: endpoint to get PDF settings (#193)
* feat: endpoint to get PDF settings * chore: bump version
1 parent 41a861e commit 31d1695

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Change Log
1414
Unreleased
1515
**********
1616

17+
0.15.1 - 2026-03-18
18+
**********************************************
19+
20+
Added
21+
=====
22+
23+
* Implemented JSON-based view to fetch a PDF-block's settings.
24+
1725
0.15.0 - 2026-03-18
1826
**********************************************
1927

xblock_pdf/pdf.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""pdfXBlock main Python class."""
2+
import json
23

34
from django.utils.translation import gettext_noop as _
45
from web_fragments.fragment import Fragment
6+
from webob import Response
57
from xblock.core import XBlock
68
from xblock.fields import Boolean, Scope, String
79
from xblock.utils.resources import ResourceLoader
@@ -58,19 +60,23 @@ class PDFBlock(XBlock):
5860
)
5961
)
6062

61-
def student_view(self, context=None):
62-
"""Primary view of the XBlock, shown to students when viewing courses."""
63-
context = {
63+
@property
64+
def raw_settings(self):
65+
"""Get the raw settings of the XBlock as a dictionary."""
66+
return {
6467
'display_name': self.display_name,
6568
'url': self.url,
6669
'allow_download': self.allow_download,
6770
'disable_all_download': is_all_download_disabled(),
6871
'source_text': self.source_text,
6972
'source_url': self.source_url,
7073
}
74+
75+
def student_view(self, context=None): # pylint: disable=unused-argument
76+
"""Primary view of the XBlock, shown to students when viewing courses."""
7177
html = resource_loader.render_django_template(
7278
'templates/html/pdf_view.html',
73-
context=context,
79+
context=self.raw_settings,
7480
i18n_service=self.runtime.service(self, "i18n"),
7581
)
7682

@@ -119,6 +125,11 @@ def on_download(self, data, suffix=''): # pylint: disable=unused-argument
119125
}
120126
self.runtime.publish(self, event_type, event_data)
121127

128+
@XBlock.handler
129+
def load_pdf(self, *_args, **_kwargs):
130+
"""Get the PDF block's settings in JSON format."""
131+
return Response(json.dumps(self.raw_settings), content_type='application/json', charset='utf8')
132+
122133
@XBlock.json_handler
123134
def save_pdf(self, data, suffix=''): # pylint: disable=unused-argument
124135
"""Save handler."""

xblock_pdf/tests/test_pdf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,11 @@ def test_download_event_fires(mock_publish):
140140
"source_url": "",
141141
}
142142
)
143+
144+
145+
def test_get_settings():
146+
"""Test that fetching the block's settings works."""
147+
block = make_block()
148+
request = mock_handle_request({}, method="GET")
149+
result = json.loads(block.load_pdf(request).body)
150+
assert result["display_name"] == "PDF"

xblocks_contrib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
from .video import VideoBlock
1010
from .word_cloud import WordCloudBlock
1111

12-
__version__ = "0.15.0"
12+
__version__ = "0.15.1"

0 commit comments

Comments
 (0)