Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ Change Log
Unreleased
**********

0.13.2 - 2026-03-12
**********************************************

Added
=====

* Implemented JSON-based view to fetch a PDF-block's settings.


0.13.1 - 2026-03-09
**********************************************

Expand Down
19 changes: 15 additions & 4 deletions xblock_pdf/pdf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""pdfXBlock main Python class."""
import json

from django.utils.translation import gettext_noop as _
from web_fragments.fragment import Fragment
from webob import Response
from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String
from xblock.utils.resources import ResourceLoader
Expand Down Expand Up @@ -58,19 +60,23 @@ class PDFBlock(XBlock):
)
)

def student_view(self, context=None):
"""Primary view of the XBlock, shown to students when viewing courses."""
context = {
@property

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of using the property decorator unless absolutely necessary, as it hides a function call. Just a nit though; address at your discretion.

def raw_settings(self):
"""Get the raw settings of the XBlock as a dictionary."""
return {
'display_name': self.display_name,
'url': self.url,
'allow_download': self.allow_download,
'disable_all_download': is_all_download_disabled(),
'source_text': self.source_text,
'source_url': self.source_url,
}

def student_view(self, context=None): # pylint: disable=unused-argument
"""Primary view of the XBlock, shown to students when viewing courses."""
html = resource_loader.render_django_template(
'templates/html/pdf_view.html',
context=context,
context=self.raw_settings,
i18n_service=self.runtime.service(self, "i18n"),
)

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

@XBlock.handler
def load_pdf(self, *_args, **_kwargs):
"""Get the PDF block's settings in JSON format."""
return Response(json.dumps(self.raw_settings), content_type='application/json', charset='utf8')

@XBlock.json_handler
def save_pdf(self, data, suffix=''): # pylint: disable=unused-argument
"""Save handler."""
Expand Down
8 changes: 8 additions & 0 deletions xblock_pdf/tests/test_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,11 @@ def test_download_event_fires(mock_publish):
"source_url": "",
}
)


def test_get_settings():
"""Test that fetching the block's settings works."""
block = make_block()
request = mock_handle_request({}, method="GET")
result = json.loads(block.load_pdf(request).body)
assert result["display_name"] == "PDF"
2 changes: 1 addition & 1 deletion xblocks_contrib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
from .video import VideoBlock
from .word_cloud import WordCloudBlock

__version__ = "0.13.1"
__version__ = "0.13.2"
Loading