From e67991c8ae1492ea475ac6ea07cd721f742d07c1 Mon Sep 17 00:00:00 2001 From: Eric Herrera Date: Tue, 7 Jul 2020 23:53:26 -0500 Subject: [PATCH] Add load function to avoid problems when serializing string resources form pkg_resources since it returns bytes object. --- recommender/recommender.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/recommender/recommender.py b/recommender/recommender.py index 15cf914..9cafff9 100644 --- a/recommender/recommender.py +++ b/recommender/recommender.py @@ -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): """ @@ -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