|
1 | 1 | """pdfXBlock main Python class.""" |
| 2 | +import json |
2 | 3 |
|
3 | 4 | from django.utils.translation import gettext_noop as _ |
4 | 5 | from web_fragments.fragment import Fragment |
| 6 | +from webob import Response |
5 | 7 | from xblock.core import XBlock |
6 | 8 | from xblock.fields import Boolean, Scope, String |
7 | 9 | from xblock.utils.resources import ResourceLoader |
@@ -58,19 +60,23 @@ class PDFBlock(XBlock): |
58 | 60 | ) |
59 | 61 | ) |
60 | 62 |
|
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 { |
64 | 67 | 'display_name': self.display_name, |
65 | 68 | 'url': self.url, |
66 | 69 | 'allow_download': self.allow_download, |
67 | 70 | 'disable_all_download': is_all_download_disabled(), |
68 | 71 | 'source_text': self.source_text, |
69 | 72 | 'source_url': self.source_url, |
70 | 73 | } |
| 74 | + |
| 75 | + def student_view(self, context=None): # pylint: disable=unused-argument |
| 76 | + """Primary view of the XBlock, shown to students when viewing courses.""" |
71 | 77 | html = resource_loader.render_django_template( |
72 | 78 | 'templates/html/pdf_view.html', |
73 | | - context=context, |
| 79 | + context=self.raw_settings, |
74 | 80 | i18n_service=self.runtime.service(self, "i18n"), |
75 | 81 | ) |
76 | 82 |
|
@@ -119,6 +125,11 @@ def on_download(self, data, suffix=''): # pylint: disable=unused-argument |
119 | 125 | } |
120 | 126 | self.runtime.publish(self, event_type, event_data) |
121 | 127 |
|
| 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 | + |
122 | 133 | @XBlock.json_handler |
123 | 134 | def save_pdf(self, data, suffix=''): # pylint: disable=unused-argument |
124 | 135 | """Save handler.""" |
|
0 commit comments