Commit 94b19d8e by Piotr Mitros

Studio view?

parent 3073110c
"""TO-DO: Write a description of what this XBlock is.""" """This XBlock allows students to edit a concept map. Why students? We
can integrate with the LMS more easily than with Studio, so it's in
many ways an easier environment where to do this."""
import pkg_resources import pkg_resources
...@@ -14,8 +16,6 @@ class ConceptXBlock(XBlock): ...@@ -14,8 +16,6 @@ class ConceptXBlock(XBlock):
This XBlock allows concept tagging in a course. This XBlock allows concept tagging in a course.
""" """
# Fields are defined on the class. You can access them in your code as
# self.<fieldname>.
server = String( server = String(
scope = Scope.settings, scope = Scope.settings,
help = "Concept map server URL" help = "Concept map server URL"
...@@ -28,17 +28,13 @@ class ConceptXBlock(XBlock): ...@@ -28,17 +28,13 @@ class ConceptXBlock(XBlock):
@XBlock.json_handler @XBlock.json_handler
def update_concept_map(self, request, suffix): def update_concept_map(self, request, suffix):
print request
self.concept_map = json.dumps(request) self.concept_map = json.dumps(request)
print "Wrote:", self.concept_map
return {'success':True} return {'success':True}
@XBlock.json_handler @XBlock.json_handler
def relay_handler(self, request, suffix): def relay_handler(self, request, suffix):
#print request, type(request), dict(request)
url = self.server+request['suffix'] url = self.server+request['suffix']
r = requests.get(url, params=request) r = requests.get(url, params=request)
#print url,":", r.text[:80]
return json.loads(r.text) return json.loads(r.text)
def resource_string(self, path): def resource_string(self, path):
...@@ -46,32 +42,30 @@ class ConceptXBlock(XBlock): ...@@ -46,32 +42,30 @@ class ConceptXBlock(XBlock):
data = pkg_resources.resource_string(__name__, path) data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8") return data.decode("utf8")
# TO-DO: change this view to display your data your own way.
def student_view(self, context=None): def student_view(self, context=None):
""" """
The primary view of the ConceptXBlock, shown to students The primary view of the ConceptXBlock, shown to students
when viewing courses. when viewing courses.
""" """
print "HERE", self.concept_map
html = self.resource_string("static/html/concept.html")#.replace("PLACEHOLDER_FOR_CONCEPT_MAP",json.dumps(self.concept_map)) html = self.resource_string("static/html/concept.html")#.replace("PLACEHOLDER_FOR_CONCEPT_MAP",json.dumps(self.concept_map))
#print self.server
#print html.format
cm = self.concept_map cm = self.concept_map
print "Read", cm if not cm:
frag = Fragment(html.replace("PLACEHOLDER_FOR_CONCEPT_MAP",cm).replace("SERVER", self.server)) #)#format(server = self.server, concept_map = cm)) cm = '{"required":[], "taught":[], "exercised":[]}'
frag = Fragment(html.replace("PLACEHOLDER_FOR_CONCEPT_MAP",cm).replace("SERVER", self.server))
frag.add_css_url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css") frag.add_css_url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css")
frag.add_css(self.resource_string("static/css/concept.css")) frag.add_css(self.resource_string("static/css/concept.css"))
frag.add_javascript_url("http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js") frag.add_javascript_url("http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js")
# frag.add_javascript_url("https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js")
frag.add_javascript_url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js") frag.add_javascript_url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js")
frag.add_javascript(self.resource_string("static/js/concept.js")) frag.add_javascript(self.resource_string("static/js/concept.js"))
frag.initialize_js('ConceptXBlock') frag.initialize_js('ConceptXBlock')
print self.xml_text_content()
return frag return frag
def studio_view(self, context=None):
return ""
# TO-DO: change this to create the scenarios you'd like to see in the # TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock. # workbench while developing your XBlock.
@staticmethod @staticmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment