Пример #1
0
    def studio_view(self, context):
        """
        Render a form for editing this XBlock
        """
        fragment = Fragment()
        static_content = ResourceLoader(
            'common.djangoapps.pipeline_mako').load_unicode(
                'templates/static_content.html')
        render_react = MakoTemplate(static_content,
                                    default_filters=[]).get_def('renderReact')
        react_content = render_react.render(
            component="LibrarySourcedBlockPicker",
            id="library-sourced-block-picker",
            props={
                'selectedXblocks': self.source_block_ids,
            })
        fragment.content = loader.render_django_template(
            'templates/library-sourced-block-studio-view.html', {
                'react_content': react_content,
                'save_url': handler_url(self, 'submit_studio_edits'),
            })

        fragment.add_javascript_url(
            self.runtime.local_resource_url(
                self, 'public/js/library_source_block.js'))
        fragment.initialize_js('LibrarySourceBlockStudioView')

        return fragment
Пример #2
0
    def test_trailing_charecters(self):
        self.assertFalse(handler_url(self.block, 'handler').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler').endswith('/'))

        self.assertFalse(handler_url(self.block, 'handler', 'suffix').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler', 'suffix').endswith('/'))

        self.assertFalse(handler_url(self.block, 'handler', 'suffix', 'query').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler', 'suffix', 'query').endswith('/'))

        self.assertFalse(handler_url(self.block, 'handler', query='query').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler', query='query').endswith('/'))
Пример #3
0
    def test_trailing_characters(self):
        self.assertFalse(handler_url(self.block, 'handler').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler').endswith('/'))

        self.assertFalse(handler_url(self.block, 'handler', 'suffix').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler', 'suffix').endswith('/'))

        self.assertFalse(handler_url(self.block, 'handler', 'suffix', 'query').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler', 'suffix', 'query').endswith('/'))

        self.assertFalse(handler_url(self.block, 'handler', query='query').endswith('?'))
        self.assertFalse(handler_url(self.block, 'handler', query='query').endswith('/'))
Пример #4
0
    def test_block_views(self):
        # Create a blockstore content library
        library = self._create_library(slug="testlib1_preview",
                                       title="Test Library 1",
                                       description="Testing XBlocks")
        # Add content to the library
        html_block_id = self._add_block_to_library(
            library["id"], "html", "html_student_preview")["id"]
        self._set_library_block_olx(html_block_id,
                                    '<html>Student Preview Test</html>')

        # Create a modulestore course
        course = CourseFactory.create(modulestore=self.store,
                                      user_id=self.user.id)
        CourseInstructorRole(course.id).add_users(self.user)
        # Add a "Source from Library" block to the course
        source_block = ItemFactory.create(category="library_sourced",
                                          parent=course,
                                          parent_location=course.location,
                                          user_id=self.user.id,
                                          modulestore=self.store)

        # Check if author_view for empty block renders using the editor template
        html = source_block.render(AUTHOR_VIEW).content
        loader = ResourceLoader('xmodule.library_sourced_block')
        expected_html = loader.render_django_template(
            'templates/library-sourced-block-author-view.html',
            {'save_url': handler_url(source_block, 'submit_studio_edits')})
        self.assertEqual(expected_html, html)

        submit_studio_edits_url = '/xblock/{0}/handler/submit_studio_edits'.format(
            source_block.scope_ids.usage_id)
        post_data = {
            "values": {
                "source_block_id": html_block_id
            },
            "defaults": ["display_name"]
        }
        # Import the html block from the library to the course
        self.client.post(submit_studio_edits_url,
                         data=post_data,
                         format='json')

        # Check if author_view for a configured block renders the children correctly
        # Use self.get_block_view for rendering these as mako templates are mocked to return repr of the template
        # instead of the rendered html
        res = self.get_block_view(source_block, AUTHOR_VIEW)
        self.assertNotIn('library-sourced-block-author-view.html', res)
        self.assertIn('studio_render_children_view.html', res)
        self.assertIn('Student Preview Test', res)

        # Check if student_view renders the children correctly
        res = self.get_block_view(source_block, STUDENT_VIEW)
        self.assertIn('Student Preview Test', res)
Пример #5
0
    def author_view(self, context):
        """
        Renders the Studio preview view.
        """
        fragment = Fragment()
        root_xblock = context.get('root_xblock')
        is_root = root_xblock and root_xblock.location == self.location  # pylint: disable=no-member
        # If block ID is not defined, ask user for the component ID in the author_view itself.
        # We don't display the editor if is_root as that page should represent the student_view without any ambiguity
        if not self.source_block_id and not is_root:
            fragment.add_content(
                loader.render_django_template('templates/library-sourced-block-author-view.html', {
                    'save_url': handler_url(self, 'submit_studio_edits')
                })
            )
            fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/library_source_block.js'))
            fragment.initialize_js('LibrarySourceBlockAuthorView')
            return fragment

        context = {} if not context else copy(context)  # Isolate context - without this there are weird bugs in Studio
        # EditableChildrenMixin.render_children will render HTML that allows instructors to make edits to the children
        context['can_move'] = False
        self.render_children(context, fragment, can_reorder=False, can_add=False)
        return fragment
Пример #6
0
 def _parsed_path(self, handler_name='handler', suffix=''):
     """Return the parsed path from a handler_url with the supplied handler_name and suffix"""
     return urlparse(handler_url(self.block, handler_name,
                                 suffix=suffix)).path
Пример #7
0
 def _parsed_query(self, query_string):
     """Return the parsed query string from a handler_url generated with the supplied query_string"""
     return urlparse(handler_url(self.block, 'handler',
                                 query=query_string)).query
Пример #8
0
 def _parsed_path(self, handler_name='handler', suffix=''):
     """Return the parsed path from a handler_url with the supplied handler_name and suffix"""
     return urlparse(handler_url(self.block, handler_name, suffix=suffix)).path
Пример #9
0
 def _parsed_query(self, query_string):
     """Return the parsed query string from a handler_url generated with the supplied query_string"""
     return urlparse(handler_url(self.block, 'handler', query=query_string)).query