From 6f8f4ccb1b40b3a14a1b344e94b7b2f8a03fd59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81s=20Gonza=CC=81lez?= Date: Wed, 26 Jan 2022 19:17:09 -0300 Subject: [PATCH 1/4] Remove unicode function --- pdf/pdf.py | 76 +++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/pdf/pdf.py b/pdf/pdf.py index d208f4a..9786c70 100644 --- a/pdf/pdf.py +++ b/pdf/pdf.py @@ -4,70 +4,76 @@ from django.template import Context, Template from xblock.core import XBlock -from xblock.fields import Scope, Integer, String, Boolean +from xblock.fields import Scope, String, Boolean from xblock.fragment import Fragment -class pdfXBlock(XBlock): - ''' +class pdfXBlock(XBlock): + """ Icon of the XBlock. Values : [other (default), video, problem] - ''' + """ icon_class = "other" - ''' + """ Fields - ''' + """ display_name = String(display_name="Display Name", - default="PDF", - scope=Scope.settings, - help="This name appears in the horizontal navigation at the top of the page.") + default="PDF", + scope=Scope.settings, + help="This name appears in the horizontal navigation at the top of the page.") url = String(display_name="PDF URL", - default="http://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf", - scope=Scope.content, - help="The URL for your PDF.") - + default="http://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf", + scope=Scope.content, + help="The URL for your PDF.") + allow_download = Boolean(display_name="PDF Download Allowed", - default=True, - scope=Scope.content, - help="Display a download button for this PDF.") - + default=True, + scope=Scope.content, + help="Display a download button for this PDF.") + source_text = String(display_name="Source document button text", - default="", - scope=Scope.content, - help="Add a download link for the source file of your PDF. Use it for example to provide the PowerPoint file used to create this PDF.") - + default="", + scope=Scope.content, + help="Add a download link for the source file of your PDF. Use it for example to provide the " + "PowerPoint file used to create this PDF.") + source_url = String(display_name="Source document URL", - default="", - scope=Scope.content, - help="Add a download link for the source file of your PDF. Use it for example to provide the PowerPoint file used to create this PDF.") + default="", + scope=Scope.content, + help="Add a download link for the source file of your PDF. Use it for example to provide the " + "PowerPoint file used to create this PDF.") - ''' + """ Util functions - ''' + """ + def load_resource(self, resource_path): """ Gets the content of a resource """ resource_content = pkg_resources.resource_string(__name__, resource_path) - return unicode(resource_content) + return resource_content - def render_template(self, template_path, context={}): + def render_template(self, template_path, context=None): """ Evaluate a template by resource path, applying the provided context """ + if context is None: + context = {} template_str = self.load_resource(template_path) return Template(template_str).render(Context(context)) - ''' + """ Main functions - ''' + """ + def student_view(self, context=None): """ The primary view of the XBlock, shown to students when viewing courses. """ - + context = { 'display_name': self.display_name, 'url': self.url, @@ -76,7 +82,7 @@ def student_view(self, context=None): 'source_url': self.source_url } html = self.render_template('static/html/pdf_view.html', context) - + frag = Fragment(html) frag.add_css(self.load_resource("static/css/pdf.css")) frag.add_javascript(self.load_resource("static/js/pdf_view.js")) @@ -96,7 +102,7 @@ def studio_view(self, context=None): 'source_url': self.source_url } html = self.render_template('static/html/pdf_edit.html', context) - + frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/pdf_edit.js")) frag.initialize_js('pdfXBlockInitEdit') @@ -109,10 +115,10 @@ def save_pdf(self, data, suffix=''): """ self.display_name = data['display_name'] self.url = data['url'] - self.allow_download = True if data['allow_download'] == "True" else False # Str to Bool translation + self.allow_download = True if data['allow_download'] == "True" else False # Str to Bool translation self.source_text = data['source_text'] self.source_url = data['source_url'] - + return { 'result': 'success', } From 740164e65ef7b51c586782bdd70de94a594517dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81s=20Gonza=CC=81lez?= Date: Thu, 27 Jan 2022 00:08:08 -0300 Subject: [PATCH 2/4] Remove unicode function --- pdf/pdf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf/pdf.py b/pdf/pdf.py index 9786c70..9b8ea18 100644 --- a/pdf/pdf.py +++ b/pdf/pdf.py @@ -53,7 +53,7 @@ def load_resource(self, resource_path): Gets the content of a resource """ resource_content = pkg_resources.resource_string(__name__, resource_path) - return resource_content + return str(resource_content) def render_template(self, template_path, context=None): """ From e094d229a6ad78a5831706f6e31bfb75911cbae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81s=20Gonza=CC=81lez?= Date: Thu, 27 Jan 2022 13:04:11 -0300 Subject: [PATCH 3/4] Fix return type of load_resource --- pdf/pdf.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pdf/pdf.py b/pdf/pdf.py index 9b8ea18..d95d08d 100644 --- a/pdf/pdf.py +++ b/pdf/pdf.py @@ -47,12 +47,11 @@ class pdfXBlock(XBlock): """ Util functions """ - def load_resource(self, resource_path): """ Gets the content of a resource """ - resource_content = pkg_resources.resource_string(__name__, resource_path) + resource_content = pkg_resources.resource_string(__name__, resource_path).decode('utf-8') return str(resource_content) def render_template(self, template_path, context=None): From 0ca90d1e7aa5c95be4bd60cc884b492a9a2e3627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81s=20Gonza=CC=81lez?= Date: Wed, 26 Jan 2022 19:17:09 -0300 Subject: [PATCH 4/4] Remove unicode function --- pdf/pdf.py | 77 +++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/pdf/pdf.py b/pdf/pdf.py index d208f4a..d95d08d 100644 --- a/pdf/pdf.py +++ b/pdf/pdf.py @@ -4,70 +4,75 @@ from django.template import Context, Template from xblock.core import XBlock -from xblock.fields import Scope, Integer, String, Boolean +from xblock.fields import Scope, String, Boolean from xblock.fragment import Fragment -class pdfXBlock(XBlock): - ''' +class pdfXBlock(XBlock): + """ Icon of the XBlock. Values : [other (default), video, problem] - ''' + """ icon_class = "other" - ''' + """ Fields - ''' + """ display_name = String(display_name="Display Name", - default="PDF", - scope=Scope.settings, - help="This name appears in the horizontal navigation at the top of the page.") + default="PDF", + scope=Scope.settings, + help="This name appears in the horizontal navigation at the top of the page.") url = String(display_name="PDF URL", - default="http://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf", - scope=Scope.content, - help="The URL for your PDF.") - + default="http://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf", + scope=Scope.content, + help="The URL for your PDF.") + allow_download = Boolean(display_name="PDF Download Allowed", - default=True, - scope=Scope.content, - help="Display a download button for this PDF.") - + default=True, + scope=Scope.content, + help="Display a download button for this PDF.") + source_text = String(display_name="Source document button text", - default="", - scope=Scope.content, - help="Add a download link for the source file of your PDF. Use it for example to provide the PowerPoint file used to create this PDF.") - + default="", + scope=Scope.content, + help="Add a download link for the source file of your PDF. Use it for example to provide the " + "PowerPoint file used to create this PDF.") + source_url = String(display_name="Source document URL", - default="", - scope=Scope.content, - help="Add a download link for the source file of your PDF. Use it for example to provide the PowerPoint file used to create this PDF.") + default="", + scope=Scope.content, + help="Add a download link for the source file of your PDF. Use it for example to provide the " + "PowerPoint file used to create this PDF.") - ''' + """ Util functions - ''' + """ def load_resource(self, resource_path): """ Gets the content of a resource """ - resource_content = pkg_resources.resource_string(__name__, resource_path) - return unicode(resource_content) + resource_content = pkg_resources.resource_string(__name__, resource_path).decode('utf-8') + return str(resource_content) - def render_template(self, template_path, context={}): + def render_template(self, template_path, context=None): """ Evaluate a template by resource path, applying the provided context """ + if context is None: + context = {} template_str = self.load_resource(template_path) return Template(template_str).render(Context(context)) - ''' + """ Main functions - ''' + """ + def student_view(self, context=None): """ The primary view of the XBlock, shown to students when viewing courses. """ - + context = { 'display_name': self.display_name, 'url': self.url, @@ -76,7 +81,7 @@ def student_view(self, context=None): 'source_url': self.source_url } html = self.render_template('static/html/pdf_view.html', context) - + frag = Fragment(html) frag.add_css(self.load_resource("static/css/pdf.css")) frag.add_javascript(self.load_resource("static/js/pdf_view.js")) @@ -96,7 +101,7 @@ def studio_view(self, context=None): 'source_url': self.source_url } html = self.render_template('static/html/pdf_edit.html', context) - + frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/pdf_edit.js")) frag.initialize_js('pdfXBlockInitEdit') @@ -109,10 +114,10 @@ def save_pdf(self, data, suffix=''): """ self.display_name = data['display_name'] self.url = data['url'] - self.allow_download = True if data['allow_download'] == "True" else False # Str to Bool translation + self.allow_download = True if data['allow_download'] == "True" else False # Str to Bool translation self.source_text = data['source_text'] self.source_url = data['source_url'] - + return { 'result': 'success', }