1 """Embed reference widget from MKWS, the MasterKey Widget Set"""
6 from xblock.core import XBlock
7 from xblock.fields import Integer, Scope, String, Any, Boolean, Dict
8 from xblock.fragment import Fragment
10 class MKWSRef(XBlock):
11 """Embed reference widget from MKWS, the MasterKey Widget Set"""
19 display_name = String(
20 default="MKWS Reference Widget",
24 def resource_string(self, path):
25 """Helper for accessing resources."""
26 data = pkg_resources.resource_string(__name__, path)
27 return data.decode("utf8")
29 def student_view(self, context=None):
30 """The primary view of the MKWS XBlock, shown to students when viewing courses."""
31 html = self.resource_string("static/html/student.html")
32 frag = Fragment(html.format(query=self.query, team=random.randint(0, 100000)))
33 # student.js uses require.js as it cannot guarantee mkws-complete.js has loaded
34 # in studio without it. We'll need to add it if we're in the LMS:
35 frag.add_javascript_url("/static/js/vendor/require.js");
36 frag.add_javascript(self.resource_string("static/js/src/student.js"))
37 frag.initialize_js('MKWSRef')
40 def author_view(self, context=None):
41 """View of the MKWS XBlock shown when authoring courses."""
42 html = self.resource_string("static/html/student.html")
43 frag = Fragment(html.format(query=self.query, team=random.randint(0, 100000)))
44 frag.add_javascript(self.resource_string("static/js/src/student.js"))
45 frag.initialize_js('MKWSRef')
48 def studio_view(self, context=None):
49 """Studio configuration view."""
50 html = self.resource_string("static/html/settings.html")
51 frag = Fragment(html.format(query=self.query))
52 frag.add_javascript(self.resource_string("static/js/src/settings.js"))
53 frag.initialize_js('MKWSRefSettings')
57 def update_settings(self, data, suffix=''):
58 """Studio configuration callback."""
59 self.query = data['query']
60 return {"result": "success"}
63 def workbench_scenarios():
64 """A canned scenario for display in the workbench."""