Skip to content

Commit

Permalink
Add load function to avoid problems when serializing string resources…
Browse files Browse the repository at this point in the history
… form pkg_resources since it returns bytes object.
  • Loading branch information
ericfab179 committed Jul 8, 2020
1 parent 191e38b commit e67991c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions recommender/recommender.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def emit(param1, param2):
""" In workbench, do nothing for event emission """
pass

def load(path):
"""Handy helper for getting resources from our kit."""
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")

def stem_url(url):
"""
Expand Down Expand Up @@ -996,9 +1000,9 @@ def studio_view(self, _context=None): # pylint: disable=unused-argument
self._init_template_lookup()

frag = Fragment(template_lookup.get_template("recommenderstudio.html").render())
frag.add_css(pkg_resources.resource_string(__name__, "static/css/recommenderstudio.css"))
frag.add_css(load("static/css/recommenderstudio.css"))
frag.add_javascript_url("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js")
frag.add_javascript(pkg_resources.resource_string(__name__, "static/js/src/recommenderstudio.js"))
frag.add_javascript(load("static/js/src/recommenderstudio.js"))
frag.initialize_js('RecommenderXBlock')
return frag

Expand Down

0 comments on commit e67991c

Please sign in to comment.