From 0fc1e44c5be86ad8a8da7cf705419c881eebb49e Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Khan Date: Wed, 7 Aug 2024 14:43:27 +0500 Subject: [PATCH] chore: optimizations --- sample_xblocks/filethumbs/filethumbs.py | 8 +++++--- sample_xblocks/thumbs/thumbs.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sample_xblocks/filethumbs/filethumbs.py b/sample_xblocks/filethumbs/filethumbs.py index 3b1467ce..22ce39aa 100644 --- a/sample_xblocks/filethumbs/filethumbs.py +++ b/sample_xblocks/filethumbs/filethumbs.py @@ -70,7 +70,9 @@ def student_view(self, context=None): # pylint: disable=W0613 """ # Load the HTML fragment from within the package and fill in the template - html_str = importlib.resources.files(__package__).joinpath("static/html/thumbs.html").read_text() + html_str = importlib.resources.files(__package__).joinpath( + "static/html/thumbs.html" + ).read_text(encoding="utf-8") frag = Fragment(str(html_str)) if not self.fs.exists("thumbsvotes.json"): @@ -83,10 +85,10 @@ def student_view(self, context=None): # pylint: disable=W0613 self.downvotes = votes['down'] # Load the CSS and JavaScript fragments from within the package - css_str = importlib.resources.files(__package__).joinpath("static/css/thumbs.css").read_text() + css_str = importlib.resources.files(__package__).joinpath("static/css/thumbs.css").read_text(encoding="utf-8") frag.add_css(str(css_str)) - js_str = importlib.resources.files(__package__).joinpath("static/js/src/thumbs.js").read_text() + js_str = importlib.resources.files(__package__).joinpath("static/js/src/thumbs.js").read_text(encoding="utf-8") frag.add_javascript(str(js_str)) with self.fs.open('uparrow.png', 'wb') as file_output: diff --git a/sample_xblocks/thumbs/thumbs.py b/sample_xblocks/thumbs/thumbs.py index f01e78fa..b1ba1bec 100644 --- a/sample_xblocks/thumbs/thumbs.py +++ b/sample_xblocks/thumbs/thumbs.py @@ -34,14 +34,16 @@ def student_view(self, context=None): # pylint: disable=W0613 """ # Load the HTML fragment from within the package and fill in the template - html_str = importlib.resources.files(__package__).joinpath("static/html/thumbs.html").read_text() + html_str = importlib.resources.files( + __package__ + ).joinpath("static/html/thumbs.html").read_text(encoding="utf-8") frag = Fragment(str(html_str).format(block=self)) # Load the CSS and JavaScript fragments from within the package - css_str = importlib.resources.files(__package__).joinpath("static/css/thumbs.css").read_text() + css_str = importlib.resources.files(__package__).joinpath("static/css/thumbs.css").read_text(encoding="utf-8") frag.add_css(str(css_str)) - js_str = importlib.resources.files(__package__).joinpath("static/js/src/thumbs.js").read_text() + js_str = importlib.resources.files(__package__).joinpath("static/js/src/thumbs.js").read_text(encoding="utf-8") frag.add_javascript(str(js_str)) frag.initialize_js('ThumbsBlock')