Skip to content

Commit

Permalink
chore: optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Aug 7, 2024
1 parent 39ff513 commit 0fc1e44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions sample_xblocks/filethumbs/filethumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions sample_xblocks/thumbs/thumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 0fc1e44

Please sign in to comment.