Esempio n. 1
0
    def student_view(self, context=None):
        """
        The primary view of the GeoGebraXBlock, shown to students
        when viewing courses.
        """

	logger.info("geogebra student_view ggb_url={a}".format(a=self.ggb_url))


	"""
	Ensure that the ggb_url attribute is defined in this xblock
	"""

	ggburl = ""

	try:
                ggburl = self.ggb_url
	except NameError:
                ggburl = ""

	data = {
                "ggb_url" : ggburl
               }

        html = self.resource_string("static/html/geogebra.html")
        frag = Fragment(html.format(self=self))
        frag.add_css(self.resource_string("static/css/geogebra.css"))
        frag.add_javascript_url("https://cdn.geogebra.org/apps/deployggb.js")
        frag.add_javascript(self.resource_string("static/js/src/geogebra.js"))
        frag.initialize_js('GeoGebraXBlock',data)
        return frag
Esempio n. 2
0
    def student_view(self, context=None):
        """
        The primary view of the EduToolsXBlock, shown to students
        when viewing courses.
        """
        notification_class = 'hidden'
        icon_class = ''
        msg = ''
        if self.submited and self.score:
            notification_class = 'success'
            icon_class = 'fa-check'
            msg = _('Correct ({grade}/{weight} point)').format(
                grade=self.score, weight=self.weight)
        elif self.submited:
            notification_class = 'error'
            icon_class = 'fa-close'
            msg = _('Incorrect ({grade}/{weight} point)').format(
                grade=self.score, weight=self.weight)

        html = self.resource_string("static/html/edutools.html")
        frag = Fragment(
            html.format(self=self,
                        notification_class=notification_class,
                        icon_class=icon_class,
                        msg=msg))
        frag.add_css(self.resource_string("static/css/edutools.css"))
        frag.add_javascript(self.resource_string("static/js/src/edutools.js"))
        frag.initialize_js('EduToolsXBlock')
        return frag
Esempio n. 3
0
    def student_view(self, context=None):  # pylint: disable=W0613
        """
        Create a fragment used to display the XBlock to a student.
        `context` is a dictionary used to configure the display (unused)

        Returns a `Fragment` object specifying the HTML, CSS, and JavaScript
        to display.
        """

        # Load the HTML fragment from within the package and fill in the template
        html_str = pkg_resources.resource_string(
            __name__, "static/html/thumbs.html").decode('utf-8')
        frag = Fragment(str(html_str).format(block=self))

        # Load the CSS and JavaScript fragments from within the package
        css_str = pkg_resources.resource_string(
            __name__, "static/css/thumbs.css").decode('utf-8')
        frag.add_css(str(css_str))

        js_str = pkg_resources.resource_string(
            __name__, "static/js/src/thumbs.js").decode('utf-8')
        frag.add_javascript(str(js_str))

        frag.initialize_js('ThumbsBlock')
        return frag
Esempio n. 4
0
    def student_view(self, _context):
        """
            The view students see
                :param _context:
                :return:
        """
        if not self.is_staff:
            return Fragment(
                "Erro: esta página só está disponível para instrutores")

        data = {
            'xblock_id': self._get_xblock_loc(),
            'is_course_cohorted': is_course_cohorted(self.course_id),
            'cohorts': self.get_cohorts(),
            'cohort': self.cohort
        }
        html = loader.render_django_template('templates/stats_display.html',
                                             data)
        frag = Fragment(html)

        frag.add_css(resource_string("static/css/quiz_stats.css"))

        frag.add_css(resource_string("static/highcharts/css/highcharts.css"))
        frag.add_javascript(resource_string("static/highcharts/highcharts.js"))
        frag.add_javascript(
            resource_string(
                "static/highcharts/modules/histogram-bellcurve.js"))

        frag.add_javascript(resource_string("static/js/stats_script.js"))
        frag.initialize_js('QuizStatsXBlock', data)

        return frag
Esempio n. 5
0
    def student_view(self, context=None):
        """
        The primary view, shown to students
        when viewing courses.
        """
        user_service = self.runtime.service(self, 'user')
        xb_user = user_service.get_current_user()
        CURRENT = xb_user.opt_attrs.get('edx-platform.username')

        html = self.resource_string("static/html/gossxblock.html")
        frag = Fragment(html.format(self=self))

        res0 = textwrap.dedent("""
            <p id='goss_hidden'><span id="gosscurrent">{}</span></p>
        """).format(CURRENT)
        frag.add_content(SafeText(res0))

        HTMLURL = 'https://node-server.online/r/assets/x92.html'
        if sys.version_info.major >= 3:
            response = urlopen(HTMLURL)
            encoding = response.info().get_content_charset('utf-8')
            html_data = response.read().decode(encoding)
        else:
            html_data = urlopen(HTMLURL).read()

        res = textwrap.dedent(html_data)
        frag.add_content(SafeText(res))

        frag.add_css(self.resource_string("static/css/gossxblock.css"))
        frag.add_javascript(
            self.resource_string("static/js/src/goss92xblock.js"))
        frag.initialize_js('Goss92XBlock')
        return frag
    def student_view(self, context=None):
        """
        Create a fragment used to display the XBlock to a student.
        `context` is a dictionary used to configure the display (unused).

        Returns a `Fragment` object specifying the HTML, CSS, and JavaScript
        to display.
        """

        self.href = "https://vimeo.com/46100581"
        self.maxwidth = 800
        self.maxheight = 600

        provider, embed_code = self.get_embed_code_for_url(self.href)

        # Load the HTML fragment from within the package and fill in the template
        html_str = pkg_resources.resource_string(
            __name__, "static/html/simplevideo.html")
        frag = Fragment(str(html_str).format(self=self, embed_code=embed_code))
        # Load CSS
        css_str = pkg_resources.resource_string(__name__,
                                                "static/css/simplevideo.css")
        frag.add_css(str(css_str))
        # Load JS
        if provider == 'vimeo.com':
            # Load the Froogaloop library from vimeo CDN.
            frag.add_javascript_url("//f.vimeocdn.com/js/froogaloop2.min.js")
            js_str = pkg_resources.resource_string(
                __name__, "static/js/src/simplevideo.js")
            frag.add_javascript(str(js_str))
            frag.initialize_js('SimpleVideoBlock')
        return frag
Esempio n. 7
0
    def student_view(self, _context):
        # pylint: disable=no-member
        """
        The primary view of the StaffGradedAssignmentXBlock, shown to students
        when viewing courses.
        """
        data = self.get_student_view_base_data()

        if self.is_course_staff():
            data['is_course_staff'] = True
            data['is_course_cohorted'] = is_course_cohorted(self.course_id)
            data['cohorts'] = [
                group.name
                for group in get_course_cohorts(course_id=self.course_id)
            ]
            data['cohort'] = self.cohort
            data['submissions'] = self.get_sorted_submissions()

        html = loader.render_django_template(
            'templates/nand2tetris_student.html', data)
        frag = Fragment(html)

        if self.is_course_staff():
            frag.add_css(resource_string("static/css/theme.blue.min.css"))
            frag.add_javascript(
                resource_string(
                    "static/js/jquery.tablesorter.combined.min.js"))

        frag.add_javascript(
            resource_string("static/js/nand2tetris_student.js"))
        frag.initialize_js('Nand2TetrisXBlock', data)

        frag.add_css(resource_string("static/css/nand2tetris.css"))
        return frag
Esempio n. 8
0
    def student_view(self, context):
        """
        XBlock student view of this component.

        Makes a request to `lti_launch_handler` either
        in an iframe or in a new window depending on the
        configuration of the instance of this XBlock

        Arguments:
            context (dict): XBlock context

        Returns:
            xblock.fragment.Fragment: XBlock HTML fragment
        """
        fragment = Fragment()
        loader = ResourceLoader(__name__)
        context.update(self._get_context_for_template())
        fragment.add_content(
            loader.render_mako_template('/templates/html/student.html',
                                        context))
        fragment.add_css(loader.load_unicode('static/css/student.css'))
        fragment.add_javascript(
            loader.load_unicode('static/js/xblock_lti_consumer.js'))
        fragment.initialize_js('LtiConsumerXBlock')
        return fragment
    def student_view(self, context=None):
        """
        The primary view of the GraphQL CMS XBlock, shown to students
        when viewing courses.
        """

        entry = {
            'title': '',
            'sections': [],
            'contentBlocks': [],
            'assets': [],
            'faqs': [],
            'tips': []
        }
        if self.entrySlug is not '':
            entry = self.load_selected_entry()
            

        frag = Fragment()
        html = self.render_template("static/html/graphqlcmsxblock.html", {
            'self':  self, 
            'cmsHost': self.cmsApi.replace('/api', ''),
            'title': entry['title'],
            'sections': entry['sections'],
            'contentBlocks': entry['contentBlocks'],
            'assets': entry['assets'],
            'faqs': entry['faqs'],
            'tips': entry['tips']
        })
        frag.add_content(html)
        frag.add_css(self.resource_string("static/css/graphqlcmsxblock.css"))
        frag.add_javascript(self.resource_string("static/js/src/graphqlcmsxblock.js"))
        frag.initialize_js('GraphQlCmsXBlock')
        return frag
Esempio n. 10
0
    def student_view(self, context=None):
        """
        The primary view of the CodeSnippetXBlock, shown to students
        when viewing courses.
        """
        frag = Fragment()
        frag.content = loader.render_django_template(
            'templates/code_snippet.html', self._get_context())
        frag.add_css(self.resource_string("static/css/code_snippet.css"))
        frag.add_css_url(
            "//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/styles/agate.min.css"
        )

        logger.info("{}".format(self._get_context()))

        # Add i18n js
        statici18n_js_url = self._get_statici18n_js_url()
        if statici18n_js_url:
            frag.add_javascript_url(
                self.runtime.local_resource_url(self, statici18n_js_url))

        frag.add_javascript(
            self.resource_string("static/js/src/code_snippet.js"))
        frag.add_javascript_url(
            "//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.3.2/highlight.min.js"
        )
        frag.initialize_js('CodeSnippetXBlock', self._get_context())
        return frag
Esempio n. 11
0
    def render_to_fragment(self, request: HttpRequest, course: CourseBlock,
                           **kwargs) -> Fragment:
        """
        Returns a fragment view for the LTI launch.
        Args:
            request (HttpRequest): request object
            course (CourseBlock): A course object
        Returns:
            A Fragment that embeds LTI in a course page.
        """
        lti_embed_html = self._get_lti_embed_code(course, request)

        fragment = Fragment(
            HTML("""
                <iframe
                    id='lti-tab-embed'
                    srcdoc='{srcdoc}'
                 >
                </iframe>
                """).format(srcdoc=lti_embed_html))
        fragment.add_css("""
            #lti-tab-embed {
                width: 100%;
                min-height: 800px;
                border: none;
            }
            """)
        return fragment
Esempio n. 12
0
 def studio_view(self, context):
     """
     Render a form for editing this XBlock
     """
     init_values = {
         'format': self.format,
         'category': self.category,
         'catalog': self.catalog,
         'language': self.language,
         'resource': self.resource,
     }
     context.update({
         'svg_sprite':
         self.resource_string('public/images/sprite.svg'),
     })
     self.update_studio_context(context)
     fragment = Fragment()
     fragment.content = loader.render_django_template(
         'static/html/studio_edit.html', context)
     fragment.add_css(self.resource_string("static/css/edflex.css"))
     fragment.add_css(self.resource_string("static/css/select2.css"))
     fragment.add_javascript(
         loader.load_unicode('static/js/src/parse_duration.js'))
     fragment.add_javascript(
         loader.load_unicode('static/js/src/studio_edit.js'))
     fragment.initialize_js('StudioEditableEdflexXBlock',
                            json_args={
                                'url_select2':
                                self.runtime.local_resource_url(
                                    self, 'public/js/select2.min'),
                                'init_values':
                                init_values
                            })
     return fragment
Esempio n. 13
0
    def student_view(self, context=None):
        """
        The primary view of the EdflexXBlock, shown to students
        when viewing courses.
        """
        if context is None:
            context = {}

        context.update({
            'svg_sprite':
            self.resource_string('public/images/sprite.svg'),
        })

        self.update_student_context(context)
        fragment = Fragment()
        fragment.content = loader.render_django_template(
            'static/html/edflex.html', context)
        fragment.add_css(self.resource_string("static/css/edflex.css"))

        if self.resource.get('type', '') == 'video':
            fragment.add_javascript_url('https://www.youtube.com/iframe_api')

        fragment.add_javascript(
            loader.load_unicode('static/js/src/parse_duration.js'))
        fragment.add_javascript(
            self.resource_string("static/js/src/edflex.js"))
        fragment.initialize_js('EdflexXBlock')
        return fragment
Esempio n. 14
0
    def student_view(self, context=None):
        """
        The student view
        """
        fragment = Fragment()

        blooms = json.loads(loader.load_unicode("static/blooms_catalog.json"))
        content = {
            'self': self,
        }

        fragment.add_content(
            loader.render_django_template('templates/learning_objs-lms.html',
                                          content))
        fragment.add_css(loader.load_unicode('static/css/lms-styling.css'))
        fragment.add_css(
            loader.load_unicode('static/css/LO_listing_styling.css'))

        #fragment.add_content(render_django_template('templates/HLCustomText.html', content))

        # add the custom initialization code for the LMS view and initialize it
        fragment.add_javascript(
            loader.load_unicode('static/js/js-str-format.js'))
        fragment.add_javascript(loader.load_unicode('static/js/LO_catalog.js'))
        fragment.add_javascript(
            loader.load_unicode('static/js/hl_learning_objs-lms.js'))

        fragment.initialize_js('LO_catalog')
        fragment.initialize_js(
            'HL_LO_XBlock', {
                'blooms_catalog': json.dumps(blooms),
                'objs': json.dumps(self.learning_objs or []),
            })

        return fragment
Esempio n. 15
0
    def student_view(self, context=None):
        """
        The primary view of the Goss2XBlock, shown to students
        when viewing courses.
        """
        user_service = self.runtime.service(self, 'user')
        xb_user = user_service.get_current_user()
        CURRENT = xb_user.opt_attrs.get('edx-platform.username')

        XURL = 'https://fork.kodaktor.ru/testxblock2'
        response = urllib.urlopen(XURL)
        data = json.loads(response.read())
        CHECK = data['message']

        html = self.resource_string("static/html/goss4xblock.html")
        frag = Fragment(html.format(self=self))

        res = textwrap.dedent("""
            <h2>X4a: Server app challenge</h2>
            <p>Your server app URL should return this: <span id="gosscurrent">{}</span>!</h2>
            <p>The address {} returned {}</h2>
            <div>Enter URL: <input id='gossinput' /><br/>
            <button id='gosssend'>send to server</button>
            </div> 
        """).format(CURRENT, XURL, CHECK)
        frag.add_content(SafeText(res))

        frag.add_css(self.resource_string("static/css/goss4xblock.css"))
        frag.add_javascript(
            self.resource_string("static/js/src/goss4xblock.js"))
        frag.initialize_js('Goss4XBlock')
        return frag
Esempio n. 16
0
    def student_view(self, context=None):
        # pylint: disable=no-member
        """
        The primary view of the StaffGradedAssignmentXBlock, shown to students
        when viewing courses.
        """
        spinner_url = self.runtime.local_resource_url(
            self, 'public/img/spinner.gif')
        context = {
            'upload_grades_file_form': UploadGradesFileForm(auto_id=True),
            'spinner_url': spinner_url,
            "student_state": json.dumps(self.student_state()),
            "id": self.location.block_id.replace('.', '_'),
            "max_file_size": self.student_upload_max_size(),
            "support_email": settings.TECH_SUPPORT_EMAIL
        }
        if self.show_staff_grading_interface():
            context['is_course_staff'] = True
            self.update_staff_debug_context(context)

        fragment = Fragment()
        fragment.add_content(
            render_django_template(
                'templates/staff_graded_assignment/show.html', context))
        fragment.add_css(_resource("static/css/edx_sga.css"))
        fragment.add_javascript(_resource("static/js/src/edx_sga.js"))
        fragment.add_javascript(
            _resource("static/js/src/jquery.tablesorter.min.js"))
        fragment.initialize_js('StaffGradedAssignmentXBlock')
        return fragment
Esempio n. 17
0
    def _staff_view(self, context):
        """
        Render the staff view for a split test module.
        """
        fragment = Fragment()
        active_contents = []
        inactive_contents = []

        for child_location in self.children:  # pylint: disable=no-member
            child_descriptor = self.get_child_descriptor_by_location(
                child_location)
            child = self.system.get_module(child_descriptor)
            rendered_child = child.render(STUDENT_VIEW, context)
            fragment.add_fragment_resources(rendered_child)
            group_name, updated_group_id = self.get_data_for_vertical(child)

            if updated_group_id is None:  # inactive group
                group_name = child.display_name
                updated_group_id = [
                    g_id for g_id, loc in self.group_id_to_child.items()
                    if loc == child_location
                ][0]
                inactive_contents.append({
                    'group_name':
                    _(u'{group_name} (inactive)').format(
                        group_name=group_name),
                    'id':
                    text_type(child.location),
                    'content':
                    rendered_child.content,
                    'group_id':
                    updated_group_id,
                })
                continue

            active_contents.append({
                'group_name': group_name,
                'id': text_type(child.location),
                'content': rendered_child.content,
                'group_id': updated_group_id,
            })

        # Sort active and inactive contents by group name.
        sorted_active_contents = sorted(active_contents,
                                        key=itemgetter('group_name'))
        sorted_inactive_contents = sorted(inactive_contents,
                                          key=itemgetter('group_name'))

        # Use the new template
        fragment.add_content(
            self.system.render_template(
                'split_test_staff_view.html', {
                    'items': sorted_active_contents + sorted_inactive_contents,
                }))
        fragment.add_css('.split-test-child { display: none; }')
        fragment.add_javascript_url(
            self.runtime.local_resource_url(self,
                                            'public/js/split_test_staff.js'))
        fragment.initialize_js('ABTestSelector')
        return fragment
Esempio n. 18
0
    def student_view(self, context=None):
        # pylint: disable=no-member
        """
        The primary view of the StaffGradedAssignmentXBlock, shown to students
        when viewing courses.
        """
        context = {
            "student_state": json.dumps(self.student_state()),
            "id": self.location.name.replace('.', '_'),
            "max_file_size": self.student_upload_max_size(),
            "support_email": settings.TECH_SUPPORT_EMAIL
        }
        if self.show_staff_grading_interface():
            context['is_course_staff'] = True
            self.update_staff_debug_context(context)

        fragment = Fragment()
        fragment.add_content(
            render_template('templates/staff_graded_assignment/show.html',
                            context))
        fragment.add_css(_resource("static/css/edx_sga.css"))
        fragment.add_javascript(_resource("static/js/src/edx_sga.js"))
        fragment.add_javascript(
            _resource("static/js/src/jquery.tablesorter.min.js"))
        fragment.initialize_js('StaffGradedAssignmentXBlock')
        return fragment
Esempio n. 19
0
 def student_view(self, context=None):
     """
     The primary view of the LivevideostreamingXBlock, shown to students
     when viewing courses.
     """
     # user_service = self.runtime.service(self, 'user')
     # xb_user = user_service.get_current_user()
     # username = xb_user.opt_attrs.get('edx-platform.username')
     # email=xb_user.emails
     # print('===========================================user_id:')
     # print(xb_user.opt_attrs.get('edx-platform.user_id'))
     # print('===========================================is_staff')
     # print(xb_user.opt_attrs.get('edx-platform.user_is_staff'))
     # print('===========================================email')
     # print(xb_user.opt_attrs.get('edx-platform.email'))
     # email = '*****@*****.**'
     # username = '******'
     # self.student_live_url = 'https://live.vhall.com/room/embedclient/435712157?email=test%40vhall.com&name=visitor&k=%E9%9A%8F%E6%9C%BA%E5%AD%97%E7%AC%A6%E4%B8%B2&state=%E9%9A%8F%E6%9C%BA%E5%AD%97%E7%AC%A6%E4%B8%B2'
     # self.teacher_live_url = 'https://e.vhall.com/webinar/new-host/435712157'
     html = self.resource_string("static/html/livevideo_view.html")
     frag = Fragment(html.format(self=self))
     frag.add_css(self.resource_string("static/css/livevideo.css"))
     frag.add_javascript(
         self.resource_string("static/js/src/livevideo_view.js"))
     frag.initialize_js('LivevideostreamingXBlock')
     return frag
Esempio n. 20
0
    def switch_exp(self, data, suffix=""):
        html = self.resource_string("static/html/experiment.html")
        frag = Fragment(html.format(self=self))
        frag.add_css(self.resource_string("static/css/dcxblock.css"))
        frag.add_javascript(self.resource_string("static/js/src/dcxblock.js"))
        frag.initialize_js('DcXBlock')

        return frag
Esempio n. 21
0
 def create_fragment(self, content=None):
     """
     Create a fragment.
     """
     fragment = Fragment(content)
     fragment.add_css('body {background-color:red;}')
     fragment.add_javascript('alert("Hi!");')
     return fragment
Esempio n. 22
0
 def render_to_fragment(self, request, **kwargs):
     """
     Returns a simple fragment
     """
     fragment = Fragment(TEST_HTML)
     fragment.add_javascript(TEST_JS)
     fragment.add_css(TEST_CSS)
     return fragment
Esempio n. 23
0
 def create_fragment(self, content=None):
     """
     Create a fragment.
     """
     fragment = Fragment(content)
     fragment.add_css('body {background-color:red;}')
     fragment.add_javascript('alert("Hi!");')
     return fragment
Esempio n. 24
0
    def student_view(self, context=None):
        """
        The primary view of the StaffGradedXBlock, shown to students
        when viewing courses.
        """
        frag = Fragment()
        frag.add_css(self.resource_string("static/css/staff_graded.css"))
        loader = ResourceLoader(__name__)
        _ = self.runtime.service(self, "i18n").ugettext

        # Add i18n js
        statici18n_js_url = self._get_statici18n_js_url()
        if statici18n_js_url:
            frag.add_javascript_url(self.runtime.local_resource_url(self, statici18n_js_url))

        frag.add_javascript(self.resource_string("static/js/src/staff_graded.js"))
        frag.initialize_js('StaffGradedXBlock')

        context['id'] = self.location.html_id()
        context['instructions'] = markdown.markdown(self.instructions)
        context['display_name'] = self.display_name
        context['is_staff'] = self.runtime.user_is_staff

        course_id = self.location.course_key
        context['available_cohorts'] = [cohort.name for cohort in get_course_cohorts(course_id=course_id)]
        context['available_tracks'] = [
            (mode.slug, mode.name) for mode in
            modes_for_course(course_id, only_selectable=False)
            ]

        if context['is_staff']:
            from crum import get_current_request
            from django.middleware.csrf import get_token
            context['import_url'] = self.runtime.handler_url(self, "csv_import_handler")
            context['export_url'] = self.runtime.handler_url(self, "csv_export_handler")
            context['poll_url'] = self.runtime.handler_url(self, "get_results_handler")
            context['csrf_token'] = get_token(get_current_request())
            frag.add_javascript(loader.load_unicode('static/js/src/staff_graded.js'))
            frag.initialize_js('StaffGradedProblem',
                               json_args={k: context[k]
                                          for k
                                          in ('csrf_token', 'import_url', 'export_url', 'poll_url', 'id')})

        try:
            score = get_score(self.location, self.runtime.user_id) or {}
            context['grades_available'] = True
        except NoSuchServiceError:
            context['grades_available'] = False
        else:
            if score:
                grade = score['score']
                context['score_string'] = _('{score} / {total} points').format(score=grade, total=self.weight)
            else:
                context['score_string'] = _('{total} points possible').format(total=self.weight)
        frag.add_content(loader.render_django_template('static/html/staff_graded.html', context))
        return frag
Esempio n. 25
0
 def studio_view(self, context=None):
     # Note that we could make this xblock editable so that we wouldn't need to
     # create a manual studio view.
     context = self.get_context_studio()
     template = self.render_template("static/html/studio.html", context)
     frag = Fragment(template)
     frag.add_css(self.resource_string("static/css/scormxblock.css"))
     frag.add_javascript(self.resource_string("static/js/src/studio.js"))
     frag.initialize_js("ScormStudioXBlock")
     return frag
Esempio n. 26
0
 def author_view(self, context=None):
     context.update({
         'svg_sprite':
         self.resource_string('public/images/sprite.svg'),
     })
     html = loader.render_django_template("static/html/author_view.html",
                                          context)
     fragment = Fragment(html)
     fragment.add_css(self.resource_string("static/css/edflex.css"))
     return fragment
Esempio n. 27
0
    def student_view(self, context=None):
        #Adiciona qual arquivo HTML será usado
        html = self.resource_string("static/html/myxblock.html")
        frag = Fragment(str(html).format(block=self))
        frag.add_css(self.resource_string("static/css/myxblock.css"))
        frag.add_javascript(self.resource_string("static/js/src/myxblock.js"))

        #Também precisa inicializar
        frag.initialize_js('MyXBlock')
        return frag
Esempio n. 28
0
    def _create_fragment(self,
                         template,
                         context_dict,
                         initialize_js_func,
                         additional_css=None,
                         additional_js=None):
        """
        Creates a fragment for display.

        """
        fragment = Fragment(template.render(context_dict))

        if additional_css is None:
            additional_css = []
        if additional_js is None:
            additional_js = []

        i18n_service = self.runtime.service(self, 'i18n')
        if hasattr(i18n_service,
                   'get_language_bidi') and i18n_service.get_language_bidi():
            css_url = "static/css/openassessment-rtl.css"
        else:
            css_url = "static/css/openassessment-ltr.css"

        if settings.DEBUG:
            for css in additional_css:
                fragment.add_css_url(self.runtime.local_resource_url(
                    self, css))
            fragment.add_css_url(self.runtime.local_resource_url(
                self, css_url))

            for js in additional_js:  # pylint: disable=invalid-name
                self.add_javascript_files(fragment, js)
            self.add_javascript_files(fragment, "static/js/src/oa_shared.js")
            self.add_javascript_files(fragment, "static/js/src/oa_server.js")
            self.add_javascript_files(fragment, "static/js/src/lms")
        else:
            # TODO: load CSS and JavaScript as URLs once they can be served by the CDN
            for css in additional_css:
                fragment.add_css(load(css))
            fragment.add_css(load(css_url))

            # minified additional_js should be already included in 'make javascript'
            fragment.add_javascript(
                load("static/js/openassessment-lms.min.js"))
        js_context_dict = {
            "ALLOWED_IMAGE_MIME_TYPES": self.ALLOWED_IMAGE_MIME_TYPES,
            "ALLOWED_FILE_MIME_TYPES": self.ALLOWED_FILE_MIME_TYPES,
            "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST,
            "FILE_TYPE_WHITE_LIST": self.white_listed_file_types,
            "MAXIMUM_FILE_UPLOAD_COUNT": self.MAX_FILES_COUNT,
            "TEAM_ASSIGNMENT": self.is_team_assignment()
        }
        fragment.initialize_js(initialize_js_func, js_context_dict)
        return fragment
 def student_view(self, context=None):
     """
     The primary view of the {{cookiecutter.class_name}}, shown to students
     when viewing courses.
     """
     html = self.resource_string("static/html/{{cookiecutter.short_name|lower}}.html")
     frag = Fragment(html.format(self=self))
     frag.add_css(self.resource_string("static/css/{{cookiecutter.short_name|lower}}.css"))
     frag.add_javascript(self.resource_string("static/js/src/{{cookiecutter.short_name|lower}}.js"))
     frag.initialize_js('{{cookiecutter.class_name}}')
     return frag
Esempio n. 30
0
 def student_view(self, context=None):
     """
     The primary view of the NikitaXBlock, shown to students
     when viewing courses.
     """
     html = self.resource_string("static/html/nickxblock.html")
     frag = Fragment(html.format(self=self))
     frag.add_css(self.resource_string("static/css/nickxblock.css"))
     frag.add_javascript(self.resource_string("static/js/src/nickxblock.js"))
     frag.initialize_js('NikitaXBlock')
     return frag
Esempio n. 31
0
 def studio_view(self, context=None):
     context_html = self.get_context_studio()
     template = loader.render_django_template(
         'static/html/studio.html',
         context=context_html,
         i18n_service=self.runtime.service(self, 'i18n'))
     frag = Fragment(template)
     frag.add_css(self.resource_string("static/css/scormxblock.css"))
     frag.add_javascript(self.resource_string("static/js/src/studio.js"))
     frag.initialize_js('ScormStudioXBlock')
     return frag
    def _staff_view(self, context):
        """
        Render the staff view for a split test module.
        """
        fragment = Fragment()
        active_contents = []
        inactive_contents = []

        for child_location in self.children:  # pylint: disable=no-member
            child_descriptor = self.get_child_descriptor_by_location(child_location)
            child = self.system.get_module(child_descriptor)
            rendered_child = child.render(STUDENT_VIEW, context)
            fragment.add_fragment_resources(rendered_child)
            group_name, updated_group_id = self.get_data_for_vertical(child)

            if updated_group_id is None:  # inactive group
                group_name = child.display_name
                updated_group_id = [g_id for g_id, loc in self.group_id_to_child.items() if loc == child_location][0]
                inactive_contents.append({
                    'group_name': _(u'{group_name} (inactive)').format(group_name=group_name),
                    'id': text_type(child.location),
                    'content': rendered_child.content,
                    'group_id': updated_group_id,
                })
                continue

            active_contents.append({
                'group_name': group_name,
                'id': text_type(child.location),
                'content': rendered_child.content,
                'group_id': updated_group_id,
            })

        # Sort active and inactive contents by group name.
        sorted_active_contents = sorted(active_contents, key=itemgetter('group_name'))
        sorted_inactive_contents = sorted(inactive_contents, key=itemgetter('group_name'))

        # Use the new template
        fragment.add_content(self.system.render_template('split_test_staff_view.html', {
            'items': sorted_active_contents + sorted_inactive_contents,
        }))
        fragment.add_css('.split-test-child { display: none; }')
        fragment.add_javascript_url(self.runtime.local_resource_url(self, 'public/js/split_test_staff.js'))
        fragment.initialize_js('ABTestSelector')
        return fragment