2

I can't seem to get the author_view to ever be executed in the Xblock I've created.

Perhaps I'm misunderstanding what the intent of the author_view is, or what I'm expecting it to do. From what I understand it is the view that is displayed in the studio once you've added the Xblock to the Vertical (eg, content displayed inside the Xblock when you can re-order the Xblocks, or click their edit button).

I've done a lot of searching and doc reading and can't find any direct examples of using the author_view. But statments like this:

The view used to preview this XBlock for instructors in Studio. Defaults to student_view if an author_view is not defined.

make me think this is what I'm looking for.

In my case, the Xblock is doing some javascript work when in the Student view so there is no content to display to the student. In the Studio view, I would like it to display the editable parameters and not execute any of the javascript.

The relevant parts of my xblock python file are:

class MyXblock(Xblock):
    def resource_string(self, path):
        data = pkg_resources.resource_string(__name__, path)
        return data.decode("utf8")

    def student_view(self, context=None):
        data = { # some context data }
        # student_view.html contains an empty tag - nothing to display
        html = self.resource_string("static/html/student_view.html")
        frag = Fragment(html.format(self=self))
        frag.add_css(self.resource_string("static/css/style.css"))

        frag.add_javascript(self.resource_string("static/js/src/student.js"))
        frag.initialize_js('MyXblock', data)
        return frag

    def author_view(self, context=None):
        # author_view.html contains html to display current xblock parameter values
        html = self.resource_string("static/html/author_view.html")
        frag = Fragment(html.format(self=self))
        frag.add_css(self.resource_string("static/css/style.css"))
        return frag

    def studio_view(self, context=None):
        html = self.resource_string("static/html/studio_view_edit.html")
        frag = Fragment(html.format(self=self))
        frag.add_css(self.resource_string("static/css/style.css"))
        frag.add_javascript(self.resource_string("static/js/src/studio_edit.js"))
        frag.initialize_js('MyXblock')
        return frag           

I've tried adding log statements into both the student/author views but the only one that ever gets called is the student_view.

I ultimately have a solution to this which involves checking the LMS_ROOT_URL and comparing it to the window.location in the javascript and conditionally executing the javascript or populating the myxblock_xblock html tag... but I really don't like it, especially knowing that this author_view is right here and may just do exactly what I want.

Any insight would be greatly appreciated! Thanks!

RoHS4U
  • 178
  • 1
  • 7

1 Answers1

2

After having the same problems with the author_view of a xblock I found a solution in this google groups thread

You just need to add a variable has_author_view = True to your xblock and the edX Studio will use your author_view. It seems to be a workaround and i have not found any other reference to this varible.