Ejemplo n.º 1
0
    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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 def author_view(self, context=None):
     """
     The primary view of the CLFClientXBlock, shown to students
     when viewing courses.
     """
     frag = Fragment()
     clf_info = {}
     if (self.clfId != ''):
         status, clf_info = self.consume_service('getClf',
                                                 {'clfId': self.clfId})
     html_context = dict(
         self=self,
         clf_info=clf_info,
         back_icon=self.runtime.local_resource_url(
             self, 'static/icons/back-016.png'),
     )
     frag.add_content(
         loader.render_template('templates/clfclient-author.html',
                                html_context))
     frag.add_css_url(
         "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
     )
     frag.add_javascript(
         self.resource_string("static/js/src/clfclient-author.js"))
     frag.initialize_js('CLFClientXBlock')
     return frag
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def studio_view(self, _context=None):  # pylint: disable=unused-argument
        '''
        Minimal view with no configuration options giving some help text.
        '''
        self.init_emulation()

        ctx = {
            'done': self.done,
            'feedback': self.feedback,
            'description': self.description,
            'button_name': self.button_name,
            'id': uuid.uuid1(0)
        }

        frag = Fragment()

        frag.add_content(
            loader.render_django_template(
                "static/html/studioview.html",
                context=ctx,
                i18n_service=self.runtime.service(self, "i18n"),
            ))

        frag.add_javascript(resource_string("static/js/src/studioview.js"))
        frag.initialize_js("DoneWithAnswerXBlockEdit")
        return frag
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo 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
Ejemplo n.º 11
0
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Render the calendar tab to a fragment.
        Args:
            request: The Django request.
            course_id: The id of the course.

        Returns:
            Fragment: The fragment representing the calendar tab.
        """
        try:
            context = _create_base_calendar_view_context(request, course_id)
            log.debug(context)
            html = render_to_string('calendar_tab/calendar_tab_fragment.html',
                                    context)
            fragment = Fragment(html)
            fragment.add_css_url(VENDOR_CSS_URL)
            fragment.add_javascript_url(VENDOR_JS_URL)
            fragment.add_javascript_url(VENDOR_PLUGIN_JS_URL)
            fragment.add_javascript_url(JS_URL)
            inline_js = render_to_string(
                'calendar_tab/calendar_tab_js.template', context)
            fragment.add_javascript(inline_js)
            return fragment

        except Exception as e:
            log.exception(e)
            html = render_to_string('calendar_tab/500_fragment.html')
            return Fragment(html)
Ejemplo n.º 12
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
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def studio_view(self, context=None):  # pylint: disable=unused-argument
        """
        Render the OpenAssessment XBlock for editing in Studio.

        Args:
            context: Not actively used for this view.

        Returns:
            (Fragment): An HTML fragment for editing the configuration of this XBlock.
        """
        rendered_template = get_template(self.STUDIO_EDITING_TEMPLATE).render(
            self.editor_context())
        fragment = Fragment(rendered_template)

        # TODO: switch to add_javascript_url once XBlock resources are loaded from the CDN
        js_bytes = pkg_resources.resource_string(
            __name__, "static/js/openassessment-studio.js")
        fragment.add_javascript(js_bytes.decode('utf-8'))

        js_context_dict = {
            "ALLOWED_IMAGE_EXTENSIONS": self.ALLOWED_IMAGE_EXTENSIONS,
            "ALLOWED_FILE_EXTENSIONS": self.ALLOWED_FILE_EXTENSIONS,
            "FILE_EXT_BLACK_LIST": self.FILE_EXT_BLACK_LIST,
        }
        fragment.initialize_js('OpenAssessmentEditor', js_context_dict)
        return fragment
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
    def student_view(self, context=None):
        name = getattr(self, "unmixed_class", self.__class__).__name__

        template_path = f'templates/html/{name.lower()}.html'

        context = context.copy() if context else {}
        context['self'] = self
        context['custom_choices'] = self.custom_choices
        context['hide_header'] = context.get('hide_header',
                                             False) or not self.show_title

        fragment = Fragment(
            loader.render_django_template(template_path,
                                          context,
                                          i18n_service=self.i18n_service))
        # If we use local_resource_url(self, ...) the runtime may insert many identical copies
        # of questionnaire.[css/js] into the DOM. So we use the mentoring block here if possible.
        block_with_resources = self.get_parent()
        from .mentoring import MentoringBlock

        # We use an inline import here to avoid a circular dependency with the .mentoring module.
        if not isinstance(block_with_resources, MentoringBlock):
            block_with_resources = self
        fragment.add_css_url(
            self.runtime.local_resource_url(block_with_resources,
                                            'public/css/questionnaire.css'))
        fragment.add_javascript_url(
            self.runtime.local_resource_url(block_with_resources,
                                            'public/js/questionnaire.js'))
        fragment.add_javascript(self.get_translation_content())
        fragment.initialize_js(name)
        return fragment
Ejemplo n.º 20
0
    def render_to_fragment(self, request, course_id=None, **kwargs):  # lint-amnesty, pylint: disable=arguments-differ
        """
        Renders the user's course bookmarks as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user,
                                        'load',
                                        course_key,
                                        check_if_enrolled=True)

        language = UserPreference.get_value(request.user,
                                            'pref-lang',
                                            default='en')

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'bookmarks_api_url': reverse('bookmarks'),
            'language_preference': language,
        }
        html = render_to_string(
            'course_bookmarks/course-bookmarks-fragment.html', context)
        inline_js = render_to_string(
            'course_bookmarks/course_bookmarks_js.template', context)
        fragment = Fragment(html)
        self.add_fragment_resource_urls(fragment)
        fragment.add_javascript(inline_js)
        return fragment
Ejemplo n.º 21
0
 def studio_view(self, context=None):
     html = self.resource_string("static/html/livevideo_edit.html")
     frag = Fragment(html.format(self=self))
     frag.add_javascript(
         self.resource_string("static/js/src/livevideo_edit.js"))
     frag.initialize_js('LivevideoEditXBlock')
     return frag
Ejemplo n.º 22
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
Ejemplo 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
Ejemplo n.º 24
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
Ejemplo n.º 25
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
Ejemplo n.º 26
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
Ejemplo n.º 27
0
    def render_to_fragment(self,
                           request,
                           course_id=None,
                           discussion_id=None,
                           thread_id=None,
                           **kwargs):
        """
        Render the discussion board to a fragment.

        Args:
            request: The Django request.
            course_id: The id of the course in question.
            discussion_id: An optional discussion ID to be focused upon.
            thread_id: An optional ID of the thread to be shown.

        Returns:
            Fragment: The fragment representing the discussion board
        """
        course_key = CourseKey.from_string(course_id)
        try:
            base_context = _create_base_discussion_view_context(
                request, course_key)
            # Note:
            #   After the thread is rendered in this fragment, an AJAX
            #   request is made and the thread is completely loaded again
            #   (yes, this is something to fix). Because of this, we pass in
            #   raise_event=False to _load_thread_for_viewing avoid duplicate
            #   tracking events.
            thread = (_load_thread_for_viewing(
                request,
                base_context['course'],
                discussion_id=discussion_id,
                thread_id=thread_id,
                raise_event=False,
            ) if thread_id else None)
            context = _create_discussion_board_context(request,
                                                       base_context,
                                                       thread=thread)
            html = render_to_string(
                'discussion/discussion_board_fragment.html', context)
            inline_js = render_to_string(
                'discussion/discussion_board_js.template', context)

            fragment = Fragment(html)
            self.add_fragment_resource_urls(fragment)
            fragment.add_javascript(inline_js)
            if not settings.REQUIRE_DEBUG:
                fragment.add_javascript_url(
                    staticfiles_storage.url(
                        'discussion/js/discussion_board_factory.js'))
            return fragment
        except cc.utils.CommentClientMaintenanceError:
            log.warning('Forum is in maintenance mode')
            html = render_to_response('discussion/maintenance_fragment.html', {
                'disable_courseware_js': True,
                'uses_pattern_library': True,
            })
            return Fragment(html)
Ejemplo n.º 28
0
    def studio_view(self,context=None):

        html=self.resource_string("static/html/myxblockEdit.html")

        frag = Fragment(str(html).format(problemTitle=self.problemTitle,problemDescription=self.problemDescription,problemCorrectRadioAnswer=self.problemCorrectRadioAnswer,problemCorrectSteps=self.problemCorrectStates,problemDefaultHint=self.problemDefaultHint,problemAnswer1=self.problemAnswer1,problemAnswer2=self.problemAnswer2,problemAnswer3=self.problemAnswer3,problemAnswer4=self.problemAnswer4,problemAnswer5=self.problemAnswer5,problemSubject=self.problemSubject,problemTags=self.problemTags))
        frag.add_javascript(self.resource_string("static/js/src/myxblockEdit.js"))

        frag.initialize_js('MyXBlockEdit')
        return frag
Ejemplo n.º 29
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
Ejemplo n.º 30
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
Ejemplo n.º 31
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
Ejemplo n.º 32
0
    def render_to_fragment(self, request, course_id=None, discussion_id=None, thread_id=None, **kwargs):
        """
        Render the discussion board to a fragment.

        Args:
            request: The Django request.
            course_id: The id of the course in question.
            discussion_id: An optional discussion ID to be focused upon.
            thread_id: An optional ID of the thread to be shown.

        Returns:
            Fragment: The fragment representing the discussion board
        """
        course_key = CourseKey.from_string(course_id)
        try:
            base_context = _create_base_discussion_view_context(request, course_key)
            # Note:
            #   After the thread is rendered in this fragment, an AJAX
            #   request is made and the thread is completely loaded again
            #   (yes, this is something to fix). Because of this, we pass in
            #   raise_event=False to _load_thread_for_viewing avoid duplicate
            #   tracking events.
            thread = (
                _load_thread_for_viewing(
                    request,
                    base_context['course'],
                    discussion_id=discussion_id,
                    thread_id=thread_id,
                    raise_event=False,
                )
                if thread_id
                else None
            )
            context = _create_discussion_board_context(request, base_context, thread=thread)
            html = render_to_string('discussion/discussion_board_fragment.html', context)
            inline_js = render_to_string('discussion/discussion_board_js.template', context)

            fragment = Fragment(html)
            self.add_fragment_resource_urls(fragment)
            fragment.add_javascript(inline_js)
            if not settings.REQUIRE_DEBUG:
                fragment.add_javascript_url(staticfiles_storage.url('discussion/js/discussion_board_factory.js'))
            return fragment
        except cc.utils.CommentClientMaintenanceError:
            log.warning('Forum is in maintenance mode')
            html = render_to_response('discussion/maintenance_fragment.html', {
                'disable_courseware_js': True,
                'uses_pattern_library': True,
            })
            return Fragment(html)
Ejemplo n.º 33
0
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Renders the user's course bookmarks as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)

        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'bookmarks_api_url': reverse('bookmarks'),
            'language_preference': 'en',  # TODO:
        }
        html = render_to_string('course_bookmarks/course-bookmarks-fragment.html', context)
        inline_js = render_to_string('course_bookmarks/course_bookmarks_js.template', context)
        fragment = Fragment(html)
        self.add_fragment_resource_urls(fragment)
        fragment.add_javascript(inline_js)
        return fragment
Ejemplo n.º 34
0
    def render_to_fragment(self, request, course_id=None, discussion_id=None, thread_id=None, **kwargs):
        """
        Render the discussion board to a fragment.

        Args:
            request: The Django request.
            course_id: The id of the course in question.
            discussion_id: An optional discussion ID to be focused upon.
            thread_id: An optional ID of the thread to be shown.

        Returns:
            Fragment: The fragment representing the discussion board
        """
        course_key = CourseKey.from_string(course_id)
        try:
            context = _create_discussion_board_context(
                request,
                course_key,
                discussion_id=discussion_id,
                thread_id=thread_id,
            )
            html = render_to_string('discussion/discussion_board_fragment.html', context)
            inline_js = render_to_string('discussion/discussion_board_js.template', context)

            fragment = Fragment(html)
            self.add_fragment_resource_urls(fragment)
            fragment.add_javascript(inline_js)
            if not settings.REQUIRE_DEBUG:
                fragment.add_javascript_url(staticfiles_storage.url('discussion/js/discussion_board_factory.js'))
            return fragment
        except cc.utils.CommentClientMaintenanceError:
            log.warning('Forum is in maintenance mode')
            html = render_to_string('discussion/maintenance_fragment.html', {
                'disable_courseware_js': True,
                'uses_pattern_library': True,
            })
            fragment = Fragment(html)
            self.add_fragment_resource_urls(fragment)
            return fragment