Example #1
0
    def test_js_escaped_string_escapes_unsafe_html(self):
        """
        Test js_escaped_string escapes &, <, and >, as well as returns a unicode type
        """
        malicious_js_string = "</script><script>alert('hello, ');</script>"

        expected_escaped_string_for_js = unicode(
            r"\u003C/script\u003E\u003Cscript\u003Ealert(\u0027hello, \u0027)\u003B\u003C/script\u003E"
        )
        escaped_string_for_js = js_escaped_string(malicious_js_string)
        self.assertEquals(expected_escaped_string_for_js, escaped_string_for_js)
 def test_js_escaped_string_with_none(self):
     """
     Test js_escaped_string returns empty string for None
     """
     escaped_string_for_js = js_escaped_string(None)
     assert u'' == escaped_string_for_js
Example #3
0
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)

        def requirejs():
            return render_requirejs(context._locals(__M_locals))

        request = context.get('request', UNDEFINED)
        EDX_ROOT_URL = context.get('EDX_ROOT_URL', UNDEFINED)
        static = _mako_get_namespace(context, 'static')
        LANGUAGE_CODE = context.get('LANGUAGE_CODE', UNDEFINED)

        def bodyclass():
            return render_bodyclass(context._locals(__M_locals))

        def title():
            return render_title(context._locals(__M_locals))

        context_library = context.get('context_library', UNDEFINED)

        def jsextra():
            return render_jsextra(context._locals(__M_locals))

        def content():
            return render_content(context._locals(__M_locals))

        getattr = context.get('getattr', UNDEFINED)
        uses_bootstrap = context.get('uses_bootstrap', UNDEFINED)

        def view_notes():
            return render_view_notes(context._locals(__M_locals))

        user = context.get('user', UNDEFINED)
        hasattr = context.get('hasattr', UNDEFINED)
        context_course = context.get('context_course', UNDEFINED)
        settings = context.get('settings', UNDEFINED)
        list = context.get('list', UNDEFINED)

        def page_bundle():
            return render_page_bundle(context._locals(__M_locals))

        def page_alert():
            return render_page_alert(context._locals(__M_locals))

        def header_extras():
            return render_header_extras(context._locals(__M_locals))

        def modal_placeholder():
            return render_modal_placeholder(context._locals(__M_locals))

        self = context.get('self', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(u'\n\n')
        __M_writer(u'\n')
        __M_writer(u'\n\n')
        __M_writer(
            u'\n<!doctype html>\n<!--[if lte IE 9]><html class="ie9 lte9" lang="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(LANGUAGE_CODE)))
        __M_writer(u'"><![endif]-->\n<!--[if !IE]><<!--><html lang="')
        __M_writer(filters.html_escape(filters.decode.utf8(LANGUAGE_CODE)))
        __M_writer(u'"><!--<![endif]-->\n  <head dir="')
        __M_writer(filters.html_escape(filters.decode.utf8(static.dir_rtl())))
        __M_writer(
            u'">\n    <meta charset="utf-8">\n    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n    <meta name="openedx-release-line" content="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(RELEASE_LINE)))
        __M_writer(u'" />\n    <title>\n        ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'title'):
            context['self'].title(**pageargs)

        __M_writer(u' |\n')
        if context_course:
            __M_writer(u'        ')
            ctx_loc = context_course.location

            __M_locals_builtin_stored = __M_locals_builtin()
            __M_locals.update(
                __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                                  for __M_key in ['ctx_loc']
                                  if __M_key in __M_locals_builtin_stored]))
            __M_writer(u'\n        ')
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(
                        context_course.display_name_with_default)))
            __M_writer(u' |\n')
        elif context_library:
            __M_writer(u'        ')
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(
                        context_library.display_name_with_default)))
            __M_writer(u' |\n')
        __M_writer(u'        ')
        __M_writer(
            filters.html_escape(filters.decode.utf8(settings.STUDIO_NAME)))
        __M_writer(u'\n    </title>\n\n    ')

        jsi18n_path = "js/i18n/{language}/djangojs.js".format(
            language=LANGUAGE_CODE)

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['jsi18n_path']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n\n')
        if getattr(settings, 'CAPTURE_CONSOLE_LOG', False):
            __M_writer(
                u'        <script type="text/javascript">\n            var oldOnError = window.onerror;\n            window.localStorage.setItem(\'console_log_capture\', JSON.stringify([]));\n\n            window.onerror = function (message, url, lineno, colno, error) {\n                if (oldOnError) {\n                    oldOnError.apply(this, arguments);\n                }\n\n                var messages = JSON.parse(window.localStorage.getItem(\'console_log_capture\'));\n                messages.push([message, url, lineno, colno, (error || {}).stack]);\n                window.localStorage.setItem(\'console_log_capture\', JSON.stringify(messages));\n            }\n        </script>\n'
            )
        __M_writer(u'\n    <script type="text/javascript" src="')
        __M_writer(
            filters.html_escape(filters.decode.utf8(static.url(jsi18n_path))))
        __M_writer(
            u'"></script>\n    <meta name="viewport" content="width=device-width,initial-scale=1">\n    <meta name="path_prefix" content="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(EDX_ROOT_URL)))
        __M_writer(u'">\n\n    ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(static.css(group=u'style-vendor'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n    ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(
                        static.css(group=u'style-vendor-tinymce-content'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n    ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(
                        static.css(group=u'style-vendor-tinymce-skin'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n\n')
        if uses_bootstrap:
            __M_writer(u'      <link rel="stylesheet" href="')
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(static.url(self.attr.main_css))))
            __M_writer(u'" type="text/css" media="all" />\n')
        else:
            __M_writer(u'      ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(
                            static.css(group=(self.attr.main_css)))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        __M_writer(u'\n    ')
        runtime._include_file(context, u'widgets/segment-io.html',
                              _template_uri)
        __M_writer(u'\n\n    ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'header_extras'):
            context['self'].header_extras(**pageargs)

        __M_writer(u'\n  </head>\n\n  <body class="')
        __M_writer(filters.html_escape(filters.decode.utf8(static.dir_rtl())))
        __M_writer(u' ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'bodyclass'):
            context['self'].bodyclass(**pageargs)

        __M_writer(u' lang_')
        __M_writer(filters.html_escape(filters.decode.utf8(LANGUAGE_CODE)))
        __M_writer(u'">\n    ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'view_notes'):
            context['self'].view_notes(**pageargs)

        __M_writer(u'\n\n    <a class="nav-skip" href="#main">')
        __M_writer(
            filters.html_escape(filters.decode.utf8(
                _("Skip to main content"))))
        __M_writer(u'</a>\n\n    ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(static.js(group=u'base_vendor'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n\n    ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(static.webpack(entry=u'commons'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(
            u'\n\n    <script type="text/javascript">\n      window.baseUrl = "'
        )
        __M_writer(js_escaped_string(settings.STATIC_URL))
        __M_writer(
            u'";\n      require.config({\n          baseUrl: window.baseUrl\n      });\n    </script>\n\n    <script type="text/javascript" src="'
        )
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(static.url("cms/js/require-config.js"))))
        __M_writer(
            u'"></script>\n\n    <!-- view -->\n    <div class="wrapper wrapper-view" dir="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(static.dir_rtl())))
        __M_writer(u'">\n      ')
        online_help_token = self.online_help_token() if hasattr(
            self, 'online_help_token') else None

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['online_help_token']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n      ')
        runtime._include_file(context,
                              u'widgets/header.html',
                              _template_uri,
                              online_help_token=online_help_token)
        __M_writer(u'\n\n      ')

        banner_messages = list(PageLevelMessages.user_messages(request))

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['banner_messages']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n\n')
        if banner_messages:
            __M_writer(
                u'        <div class="page-banner">\n          <div class="user-messages">\n'
            )
            for message in banner_messages:
                __M_writer(u'              <div class="alert ')
                __M_writer(
                    filters.html_escape(filters.decode.utf8(
                        message.css_class)))
                __M_writer(
                    u'" role="alert">\n                <span class="icon icon-alert fa '
                )
                __M_writer(
                    filters.html_escape(filters.decode.utf8(
                        message.icon_class)))
                __M_writer(u'" aria-hidden="true"></span>\n                ')
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(HTML(message.message_html))))
                __M_writer(u'\n              </div>\n')
            __M_writer(u'          </div>\n        </div>\n')
        __M_writer(u'\n      <div id="page-alert">\n      ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'page_alert'):
            context['self'].page_alert(**pageargs)

        __M_writer(
            u'\n      </div>\n\n      <main id="main" aria-label="Content" tabindex="-1">\n        <div id="content">\n        '
        )
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'content'):
            context['self'].content(**pageargs)

        __M_writer(u'\n        </div>\n      </main>\n\n')
        if user.is_authenticated:
            __M_writer(u'        ')
            runtime._include_file(context,
                                  u'widgets/sock.html',
                                  _template_uri,
                                  online_help_token=online_help_token)
            __M_writer(u'\n')
        __M_writer(u'      ')
        runtime._include_file(context, u'widgets/footer.html', _template_uri)
        __M_writer(
            u'\n\n      <div id="page-notification"></div>\n    </div>\n\n    <div id="page-prompt"></div>\n\n    '
        )
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'modal_placeholder'):
            context['self'].modal_placeholder(**pageargs)

        __M_writer(u'\n\n    ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'jsextra'):
            context['self'].jsextra(**pageargs)

        __M_writer(u'\n\n')
        if context_course:
            __M_writer(u'      ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(
                            static.webpack(
                                entry=u'js/factories/context_course'))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(
                u'\n      <script type="text/javascript">\n        window.course = new ContextCourse({\n          id: "'
            )
            __M_writer(js_escaped_string(context_course.id))
            __M_writer(u'",\n          name: "')
            __M_writer(
                js_escaped_string(context_course.display_name_with_default))
            __M_writer(u'",\n          url_name: "')
            __M_writer(js_escaped_string(context_course.location.block_id))
            __M_writer(u'",\n          org: "')
            __M_writer(js_escaped_string(context_course.location.org))
            __M_writer(u'",\n          num: "')
            __M_writer(js_escaped_string(context_course.location.course))
            __M_writer(u'",\n          display_course_number: "')
            __M_writer(js_escaped_string(context_course.display_coursenumber))
            __M_writer(u'",\n          revision: "')
            __M_writer(js_escaped_string(context_course.location.branch))
            __M_writer(u'",\n          self_paced: ')
            __M_writer(dump_js_escaped_json(context_course.self_paced))
            __M_writer(u'\n        });\n      </script>\n')
        if user.is_authenticated:
            __M_writer(u'      ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(static.webpack(entry=u'js/sock'))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        __M_writer(u'    ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'page_bundle'):
            context['self'].page_bundle(**pageargs)

        __M_writer(u'\n    ')
        runtime._include_file(context, u'widgets/segment-io-footer.html',
                              _template_uri)
        __M_writer(
            u'\n    <div class="modal-cover"></div>\n  </body>\n</html>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #4
0
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        disable_window_wrap = context.get('disable_window_wrap', UNDEFINED)
        disable_courseware_js = context.get('disable_courseware_js', UNDEFINED)
        EDX_ROOT_URL = context.get('EDX_ROOT_URL', UNDEFINED)
        static = _mako_get_namespace(context, 'static')
        unicode = context.get('unicode', UNDEFINED)
        LANGUAGE_CODE = context.get('LANGUAGE_CODE', UNDEFINED)
        disable_footer = context.get('disable_footer', UNDEFINED)

        def bodyclass():
            return render_bodyclass(context._locals(__M_locals))

        def js_overrides():
            return render_js_overrides(context._locals(__M_locals))

        self = context.get('self', UNDEFINED)
        getattr = context.get('getattr', UNDEFINED)

        def js_extra():
            return render_js_extra(context._locals(__M_locals))

        def marketing_hero():
            return render_marketing_hero(context._locals(__M_locals))

        uses_bootstrap = context.get('uses_bootstrap', UNDEFINED)

        def footer_extra():
            return render_footer_extra(context._locals(__M_locals))

        def headextra():
            return render_headextra(context._locals(__M_locals))

        uses_pattern_library = context.get('uses_pattern_library', UNDEFINED)
        hasattr = context.get('hasattr', UNDEFINED)

        def head_extra():
            return render_head_extra(context._locals(__M_locals))

        def bodyextra():
            return render_bodyextra(context._locals(__M_locals))

        disable_header = context.get('disable_header', UNDEFINED)

        def title():
            return render_title(context._locals(__M_locals))

        is_from_mobile_app = context.get('is_from_mobile_app', UNDEFINED)
        allow_iframing = context.get('allow_iframing', UNDEFINED)
        settings = context.get('settings', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(u'\n')
        __M_writer(u'\n\n\n')
        __M_writer(u'\n')
        online_help_token = self.online_help_token() if hasattr(
            self, 'online_help_token') else None

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['online_help_token']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n')
        __M_writer(
            u'\n<!DOCTYPE html>\n<!--[if lte IE 9]><html class="ie ie9 lte9" lang="'
        )
        __M_writer(filters.decode.utf8(LANGUAGE_CODE))
        __M_writer(u'"><![endif]-->\n<!--[if !IE]><!--><html lang="')
        __M_writer(filters.decode.utf8(LANGUAGE_CODE))
        __M_writer(u'"><!--<![endif]-->\n<head dir="')
        __M_writer(filters.decode.utf8(static.dir_rtl()))
        __M_writer(
            u'">\n    <meta charset="UTF-8">\n    <meta http-equiv="X-UA-Compatible" content="IE=edge">\n    <meta name="viewport" content="width=device-width, initial-scale=1">\n\n'
        )
        __M_writer(u'\n')
        __M_writer(u'\n  ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'title'):
            context['self'].title(**pageargs)

        __M_writer(u'\n\n')
        if not allow_iframing:
            __M_writer(
                u'      <script type="text/javascript">\n        /* immediately break out of an iframe if coming from the marketing website */\n        (function(window) {\n          if (window.location !== window.top.location) {\n            window.top.location = window.location;\n          }\n        })(this);\n      </script>\n'
            )
        __M_writer(u'\n  ')

        jsi18n_path = "js/i18n/{language}/djangojs.js".format(
            language=LANGUAGE_CODE)
        ie11_fix_path = "js/ie11_find_array.js"

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['jsi18n_path', 'ie11_fix_path']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n\n')
        if getattr(settings, 'CAPTURE_CONSOLE_LOG', False):
            __M_writer(
                u'    <script type="text/javascript">\n      var oldOnError = window.onerror;\n      window.localStorage.setItem(\'console_log_capture\', JSON.stringify([]));\n\n      window.onerror = function (message, url, lineno, colno, error) {\n        if (oldOnError) {\n          oldOnError.apply(this, arguments);\n        }\n\n        var messages = JSON.parse(window.localStorage.getItem(\'console_log_capture\'));\n        messages.push([message, url, lineno, colno, (error || {}).stack]);\n        window.localStorage.setItem(\'console_log_capture\', JSON.stringify(messages));\n      }\n    </script>\n'
            )
        __M_writer(u'  <script type="text/javascript" src="')
        __M_writer(filters.decode.utf8(static.url(jsi18n_path)))
        __M_writer(u'"></script>\n  <script type="text/javascript" src="')
        __M_writer(filters.decode.utf8(static.url(ie11_fix_path)))
        __M_writer(
            u'"></script>\n\n  <link rel="icon" type="image/x-icon" href="')
        __M_writer(
            filters.decode.utf8(
                static.url(
                    static.get_value('favicon_path', settings.FAVICON_PATH))))
        __M_writer(u'" />\n\n  ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(filters.decode.utf8(static.css(group=u'style-vendor')))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n')
        if '/' in self.attr.main_css:
            if get_language_bidi():
                __M_writer(u'      ')

                rtl_css_file = self.attr.main_css.replace('.css', '-rtl.css')

                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(
                    __M_dict_builtin([
                        (__M_key, __M_locals_builtin_stored[__M_key])
                        for __M_key in ['rtl_css_file']
                        if __M_key in __M_locals_builtin_stored
                    ]))
                __M_writer(u'\n      <link rel="stylesheet" href="')
                __M_writer(
                    filters.decode.utf8(unicode(static.url(rtl_css_file))))
                __M_writer(u'" type="text/css" media="all" />\n')
            else:
                __M_writer(u'      <link rel="stylesheet" href="')
                __M_writer(filters.decode.utf8(static.url(self.attr.main_css)))
                __M_writer(u'" type="text/css" media="all" />\n')
        else:
            __M_writer(u'    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.decode.utf8(
                        static.css(group=(self.attr.main_css))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        __M_writer(u'\n')
        if disable_courseware_js or uses_pattern_library:
            __M_writer(u'    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(filters.decode.utf8(
                    static.js(group=u'base_vendor')))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.decode.utf8(static.js(group=u'base_application')))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        else:
            __M_writer(u'    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(filters.decode.utf8(
                    static.js(group=u'main_vendor')))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(filters.decode.utf8(
                    static.js(group=u'application')))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        __M_writer(u'\n  ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(filters.decode.utf8(static.webpack(entry=u'commons')))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n\n')
        if uses_bootstrap:
            __M_writer(u'    <script type="text/javascript" src="')
            __M_writer(
                filters.decode.utf8(
                    static.url('common/js/vendor/bootstrap.bundle.js')))
            __M_writer(u'"></script>\n')
        __M_writer(u'\n  <script>\n    window.baseUrl = "')
        __M_writer(js_escaped_string(settings.STATIC_URL))
        __M_writer(
            u'";\n    (function (require) {\n      require.config({\n          baseUrl: window.baseUrl\n      });\n    }).call(this, require || RequireJS.require);\n  </script>\n  <script type="text/javascript" src="'
        )
        __M_writer(filters.decode.utf8(static.url("lms/js/require-config.js")))
        __M_writer(u'"></script>\n  ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'js_overrides'):
            context['self'].js_overrides(**pageargs)

        __M_writer(u'\n\n  ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'headextra'):
            context['self'].headextra(**pageargs)

        __M_writer(u'\n  ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'head_extra'):
            context['self'].head_extra(**pageargs)

        __M_writer(u'\n\n  ')
        runtime._include_file(context, u'/courseware/experiments.html',
                              _template_uri)
        __M_writer(u'\n  ')
        runtime._include_file(context, u'user_metadata.html', _template_uri)
        __M_writer(u'\n  ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.decode.utf8(
                    static.optional_include_mako(is_theming_enabled=u'True',
                                                 file=u'head-extra.html')))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n\n  ')
        runtime._include_file(context, u'widgets/optimizely.html',
                              _template_uri)
        __M_writer(u'\n  ')
        runtime._include_file(context, u'widgets/segment-io.html',
                              _template_uri)
        __M_writer(u'\n\n  <meta name="path_prefix" content="')
        __M_writer(filters.decode.utf8(EDX_ROOT_URL))
        __M_writer(u'">\n  \n  ')
        google_site_verification_id = configuration_helpers.get_value(
            'GOOGLE_SITE_VERIFICATION_ID',
            settings.GOOGLE_SITE_VERIFICATION_ID)

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['google_site_verification_id']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n')
        if google_site_verification_id:
            __M_writer(u'    <meta name="google-site-verification" content="')
            __M_writer(filters.decode.utf8(google_site_verification_id))
            __M_writer(u'" />\n')
        __M_writer(u'\n  <meta name="openedx-release-line" content="')
        __M_writer(filters.decode.utf8(RELEASE_LINE))
        __M_writer(u'" />\n\n')
        ga_acct = static.get_value("GOOGLE_ANALYTICS_ACCOUNT",
                                   settings.GOOGLE_ANALYTICS_ACCOUNT)

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['ga_acct']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n')
        if ga_acct:
            __M_writer(
                u'    <script type="text/javascript">\n    var _gaq = _gaq || [];\n    _gaq.push([\'_setAccount\', \''
            )
            __M_writer(js_escaped_string(ga_acct))
            __M_writer(
                u"']);\n    _gaq.push(['_trackPageview']);\n\n    (function() {\n      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n    })();\n    </script>\n"
            )
        __M_writer(u'\n')
        branch_key = static.get_value("BRANCH_IO_KEY", settings.BRANCH_IO_KEY)

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['branch_key']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n')
        if branch_key and not is_from_mobile_app:
            __M_writer(
                u'    <script type="text/javascript">\n        (function(b,r,a,n,c,h,_,s,d,k){if(!b[n]||!b[n]._q){for(;s<_.length;)c(h,_[s++]);d=r.createElement(a);d.async=1;d.src="https://cdn.branch.io/branch-latest.min.js";k=r.getElementsByTagName(a)[0];k.parentNode.insertBefore(d,k);b[n]=h}})(window,document,"script","branch",function(b,r){b[r]=function(){b._q.push([r,arguments])}},{_q:[],_v:1},"addListener applyCode banner closeBanner creditHistory credits data deepview deepviewCta first getCode init link logout redeem referrals removeListener sendSMS setBranchViewData setIdentity track validateCode".split(" "), 0);\n        branch.init(\''
            )
            __M_writer(js_escaped_string(branch_key))
            __M_writer(u"');\n    </script>\n")
        __M_writer(u'\n</head>\n\n<body class="')
        __M_writer(filters.decode.utf8(static.dir_rtl()))
        __M_writer(u' ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'bodyclass'):
            context['self'].bodyclass(**pageargs)

        __M_writer(u' lang_')
        __M_writer(filters.decode.utf8(LANGUAGE_CODE))
        __M_writer(u'">\n\n')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.decode.utf8(
                    static.optional_include_mako(is_theming_enabled=u'True',
                                                 file=u'body-initial.html')))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n<div id="page-prompt"></div>\n')
        if not disable_window_wrap:
            __M_writer(u'  <div class="window-wrap" dir="')
            __M_writer(filters.decode.utf8(static.dir_rtl()))
            __M_writer(u'">\n')
        __M_writer(
            u'    <a class="nav-skip sr-only sr-only-focusable" href="#main">')
        __M_writer(filters.decode.utf8(_("Skip to main content")))
        __M_writer(u'</a>\n\n')
        if not disable_header:
            __M_writer(u'        ')
            runtime._include_file(context,
                                  (static.get_template_path('header.html')),
                                  _template_uri,
                                  online_help_token=online_help_token)
            __M_writer(u'\n        ')
            runtime._include_file(context, u'/preview_menu.html',
                                  _template_uri)
            __M_writer(u'\n')
        __M_writer(u'\n    ')
        runtime._include_file(context, u'/page_banner.html', _template_uri)
        __M_writer(u'\n\n    <div class="marketing-hero">')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'marketing_hero'):
            context['self'].marketing_hero(**pageargs)

        __M_writer(
            u'</div>\n\n    <div class="content-wrapper main-container" id="content" dir="'
        )
        __M_writer(filters.decode.utf8(static.dir_rtl()))
        __M_writer(u'">\n      ')
        __M_writer(filters.decode.utf8(self.body()))
        __M_writer(u'\n      ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'bodyextra'):
            context['self'].bodyextra(**pageargs)

        __M_writer(u'\n    </div>\n\n')
        if not disable_footer:
            __M_writer(u'        ')
            runtime._include_file(context,
                                  (static.get_template_path('footer.html')),
                                  _template_uri)
            __M_writer(u'\n')
        __M_writer(u'\n')
        if not disable_window_wrap:
            __M_writer(u'  </div>\n')
        __M_writer(u'\n  ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'footer_extra'):
            context['self'].footer_extra(**pageargs)

        __M_writer(u'\n  ')
        if 'parent' not in context._data or not hasattr(
                context._data['parent'], 'js_extra'):
            context['self'].js_extra(**pageargs)

        __M_writer(u'\n\n  ')
        runtime._include_file(context, u'widgets/segment-io-footer.html',
                              _template_uri)
        __M_writer(u'\n  <script type="text/javascript" src="')
        __M_writer(filters.decode.utf8(static.url('js/vendor/noreferrer.js')))
        __M_writer(
            u'" charset="utf-8"></script>\n  <script type="text/javascript" src="'
        )
        __M_writer(filters.decode.utf8(static.url('js/utils/navigation.js')))
        __M_writer(
            u'" charset="utf-8"></script>\n  <script type="text/javascript" src="'
        )
        __M_writer(filters.decode.utf8(static.url('js/header/header.js')))
        __M_writer(u'"></script>\n  ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.decode.utf8(
                    static.optional_include_mako(is_theming_enabled=u'True',
                                                 file=u'body-extra.html')))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n</body>\n</html>\n\n')
        __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
 def test_js_escaped_string_with_none(self):
     """
     Test js_escaped_string returns empty string for None
     """
     escaped_string_for_js = js_escaped_string(None)
     self.assertEquals(u"", escaped_string_for_js)
Example #6
0
def render_js_extra(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        redirect_message = context.get('redirect_message', UNDEFINED)

        def js_extra():
            return render_js_extra(context)

        static = _mako_get_namespace(context, 'static')
        settings = context.get('settings', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n  <script src="')
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(static.url('js/commerce/credit.js'))))
        __M_writer(u'"></script>\n  ')

        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(static.js(group=u'dashboard'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(
            u'\n  <script type="text/javascript">\n    $(document).ready(function() {\n      edx.dashboard.legacy.init({\n        dashboard: "'
        )
        __M_writer(js_escaped_string(reverse('dashboard')))
        __M_writer(u'",\n        signInUser: "******",\n        changeEmailSettings: "')
        __M_writer(js_escaped_string(reverse('change_email_settings')))
        __M_writer(u'"\n      });\n    });\n  </script>\n  ')

        def ccall(caller):
            def body():
                marketing_link = context.get('marketing_link', UNDEFINED)
                __M_writer = context.writer()
                __M_writer(
                    u'\n    UnenrollmentFactory({\n      urls: {\n        dashboard: "'
                )
                __M_writer(js_escaped_string(reverse('dashboard')))
                __M_writer(u'",\n        signInUser: "******",\n        changeEmailSettings: "')
                __M_writer(js_escaped_string(reverse('change_email_settings')))
                __M_writer(u'",\n        browseCourses: "')
                __M_writer(js_escaped_string(marketing_link('COURSES')))
                __M_writer(u'"\n      },\n      isEdx: false\n    });\n  ')
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(
                        static.webpack(entry=u'UnenrollmentFactory'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n  ')

        def ccall(caller):
            def body():
                marketing_link = context.get('marketing_link', UNDEFINED)
                __M_writer = context.writer()
                __M_writer(u'\n')
                __M_writer(
                    u'    $(document).ready(function() {\n      EntitlementUnenrollmentFactory({\n        dashboardPath: "'
                )
                __M_writer(js_escaped_string(reverse('dashboard')))
                __M_writer(u'",\n        signInPath: "')
                __M_writer(js_escaped_string(reverse('signin_user')))
                __M_writer(u'",\n        browseCourses: "')
                __M_writer(js_escaped_string(marketing_link('COURSES')))
                __M_writer(u'",\n        isEdx: false\n      });\n    });\n  ')
                return ''

            return [body]

        context.caller_stack.nextcaller = runtime.Namespace(
            'caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(
                        static.webpack(
                            entry=u'EntitlementUnenrollmentFactory'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n')
        if settings.FEATURES.get('ENABLE_DASHBOARD_SEARCH'):
            __M_writer(u'    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    __M_writer(u'\n        DashboardSearchFactory();\n    ')
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(
                            static.require_module(
                                class_name=u'DashboardSearchFactory',
                                module_name=
                                u'course_search/js/dashboard_search_factory')))
                )
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        if redirect_message:
            __M_writer(u'    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    __M_writer(
                        u"\n        var banner = new MessageBannerView({urgency: 'low', type: 'warning'});\n        $('#content').prepend(banner.$el);\n        banner.showMessage("
                    )
                    __M_writer(dump_js_escaped_json(redirect_message))
                    __M_writer(u')\n    ')
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(
                            static.require_module(
                                class_name=u'MessageBannerView',
                                module_name=u'js/views/message_banner'))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #7
0
 def body():
     password_reset_support_link = context.get(
         'password_reset_support_link', UNDEFINED)
     extended_profile_fields = context.get(
         'extended_profile_fields', UNDEFINED)
     enterprise_name = context.get('enterprise_name', UNDEFINED)
     user_preferences_api_url = context.get(
         'user_preferences_api_url', UNDEFINED)
     fields = context.get('fields', UNDEFINED)
     enterprise_readonly_account_fields = context.get(
         'enterprise_readonly_account_fields', UNDEFINED)
     sync_learner_profile_data = context.get(
         'sync_learner_profile_data', UNDEFINED)
     edx_support_url = context.get('edx_support_url', UNDEFINED)
     bool = context.get('bool', UNDEFINED)
     user_accounts_api_url = context.get('user_accounts_api_url',
                                         UNDEFINED)
     enable_account_deletion = context.get(
         'enable_account_deletion', UNDEFINED)
     order_history = context.get('order_history', UNDEFINED)
     __M_writer = context.writer()
     __M_writer(u'\n    var fieldsData = ')
     __M_writer(dump_js_escaped_json(fields))
     __M_writer(u',\n        ordersHistoryData = ')
     __M_writer(dump_js_escaped_json(order_history))
     __M_writer(u',\n        authData = ')
     __M_writer(dump_js_escaped_json(auth))
     __M_writer(u",\n        platformName = '")
     __M_writer(js_escaped_string(static.get_platform_name()))
     __M_writer(u"',\n        contactEmail = '")
     __M_writer(
         js_escaped_string(static.get_contact_email_address()))
     __M_writer(u"',\n        allowEmailChange = ")
     __M_writer(
         dump_js_escaped_json(
             bool(settings.FEATURES['ALLOW_EMAIL_ADDRESS_CHANGE'])))
     __M_writer(u',\n        socialPlatforms = ')
     __M_writer(dump_js_escaped_json(settings.SOCIAL_PLATFORMS))
     __M_writer(u',\n\n        syncLearnerProfileData = ')
     __M_writer(
         dump_js_escaped_json(bool(sync_learner_profile_data)))
     __M_writer(u",\n        enterpriseName = '")
     __M_writer(js_escaped_string(enterprise_name))
     __M_writer(u"',\n        enterpriseReadonlyAccountFields = ")
     __M_writer(
         dump_js_escaped_json(enterprise_readonly_account_fields))
     __M_writer(u",\n        edxSupportUrl = '")
     __M_writer(js_escaped_string(edx_support_url))
     __M_writer(u"',\n        extendedProfileFields = ")
     __M_writer(dump_js_escaped_json(extended_profile_fields))
     __M_writer(u',\n        displayAccountDeletion = ')
     __M_writer(dump_js_escaped_json(enable_account_deletion))
     __M_writer(u';\n        isSecondaryEmailFeatureEnabled = ')
     __M_writer(
         dump_js_escaped_json(
             bool(is_secondary_email_feature_enabled_for_user(
                 user))))
     __M_writer(
         u",\n\n    AccountSettingsFactory(\n        fieldsData,\n        ordersHistoryData,\n        authData,\n        '"
     )
     __M_writer(js_escaped_string(password_reset_support_link))
     __M_writer(u"',\n        '")
     __M_writer(js_escaped_string(user_accounts_api_url))
     __M_writer(u"',\n        '")
     __M_writer(js_escaped_string(user_preferences_api_url))
     __M_writer(u"',\n        ")
     __M_writer(dump_js_escaped_json(user.id))
     __M_writer(
         u',\n        platformName,\n        contactEmail,\n        allowEmailChange,\n        socialPlatforms,\n\n        syncLearnerProfileData,\n        enterpriseName,\n        enterpriseReadonlyAccountFields,\n        edxSupportUrl,\n        extendedProfileFields,\n        displayAccountDeletion,\n        isSecondaryEmailFeatureEnabled\n    );\n'
     )
     return ''
Example #8
0
def render_js_extra(context,**pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        fragment = context.get('fragment', UNDEFINED)
        request = context.get('request', UNDEFINED)
        course = context.get('course', UNDEFINED)
        def js_extra():
            return render_js_extra(context)
        static = _mako_get_namespace(context, 'static')
        staff_access = context.get('staff_access', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n<script type="text/javascript" src="')
        __M_writer(filters.html_escape(filters.decode.utf8(static.url('common/js/vendor/jquery.scrollTo.js'))))
        __M_writer(u'"></script>\n<script type="text/javascript" src="')
        __M_writer(filters.html_escape(filters.decode.utf8(static.url('js/vendor/flot/jquery.flot.js'))))
        __M_writer(u'"></script>\n\n')
        def ccall(caller):
            def body():
                __M_writer = context.writer()
                return ''
            return [body]
        context.caller_stack.nextcaller = runtime.Namespace('caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(filters.html_escape(filters.decode.utf8(static.js(group=u'courseware'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n')
        runtime._include_file(context, u'/mathjax_include.html', _template_uri, disable_fast_preview=True)
        __M_writer(u'\n\n')
        if settings.FEATURES.get('ENABLE_COURSEWARE_SEARCH'):
            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    __M_writer(u"\nvar courseId = $('.courseware-results').data('courseId');\nCourseSearchFactory({\ncourseId: courseId,\nsearchHeader: $('.search-bar')\n});\n")
                    return ''
                return [body]
            context.caller_stack.nextcaller = runtime.Namespace('caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(filters.html_escape(filters.decode.utf8(static.require_module(class_name=u'CourseSearchFactory',module_name=u'course_search/js/course_search_factory'))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n')
        __M_writer(u'\n')
        def ccall(caller):
            def body():
                __M_writer = context.writer()
                __M_writer(u'\nCoursewareFactory();\n')
                return ''
            return [body]
        context.caller_stack.nextcaller = runtime.Namespace('caller', context, callables=ccall(__M_caller))
        try:
            __M_writer(filters.html_escape(filters.decode.utf8(static.require_module(class_name=u'CoursewareFactory',module_name=u'js/courseware/courseware_factory'))))
        finally:
            context.caller_stack.nextcaller = None
        __M_writer(u'\n\n')
        if staff_access:
            runtime._include_file(context, u'xqa_interface.html', _template_uri)
            __M_writer(u'\n')
        __M_writer(u'\n<script type="text/javascript">\n    var $$course_id = "')
        __M_writer(js_escaped_string(course.id ))
        __M_writer(u'";\n</script>\n\n')
        if not request.user.is_authenticated:
            __M_writer(u'<script type="text/javascript">\n    // Disable discussions\n    $(\'.xblock-student_view-discussion button.discussion-show\').attr(\'disabled\', true);\n\n    // Insert message informing user discussions are only available to logged in users.\n    $(\'.discussion-module\')\n</script>\n')
        __M_writer(u'\n')
        __M_writer(filters.html_escape(filters.decode.utf8(HTML(fragment.foot_html()))))
        __M_writer(u'\n\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #9
0
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        static = _mako_get_namespace(context, 'static')
        settings = context.get('settings', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(u'\n')
        __M_writer(
            u'\n\n<script type="text/javascript">\n  window.PLATFORM_NAME = "')
        __M_writer(js_escaped_string(settings.PLATFORM_NAME))
        __M_writer(u'";\n')
        if settings.FEATURES.get('ENABLE_DISCUSSION_HOME_PANEL', False):
            __M_writer(u'    window.ENABLE_DISCUSSION_HOME_PANEL = true;\n')
        else:
            __M_writer(u'    window.ENABLE_DISCUSSION_HOME_PANEL = false;\n')
        __M_writer(u'</script>\n\n')

        template_names = [
            'thread', 'thread-show', 'thread-edit', 'thread-response',
            'thread-response-show', 'thread-response-edit',
            'response-comment-show', 'response-comment-edit',
            'thread-list-item', 'search-alert', 'new-post',
            'new-post-menu-entry', 'new-post-menu-category', 'new-post-alert',
            'new-post-visibility', 'topic', 'post-user-display',
            'inline-discussion', 'pagination', 'profile-thread',
            'customwmd-prompt', 'nav-loading', 'thread-type'
        ]

        ## same, but without trailing "-template" in script ID - these templates does not contain any free variables
        template_names_no_suffix = [
            'forum-action-endorse', 'forum-action-answer',
            'forum-action-follow', 'forum-action-vote', 'forum-action-report',
            'forum-action-pin', 'forum-action-close', 'forum-action-edit',
            'forum-action-delete', 'forum-actions', 'alert-popup',
            'nav-load-more-link'
        ]

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([
                (__M_key, __M_locals_builtin_stored[__M_key])
                for __M_key in ['template_names', 'template_names_no_suffix']
                if __M_key in __M_locals_builtin_stored
            ]))
        __M_writer(u'\n\n')
        for template_name in template_names:
            __M_writer(u'<script aria-hidden="true" type="text/template" id="')
            __M_writer(filters.html_escape(filters.decode.utf8(template_name)))
            __M_writer(u'-template">\n    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(
                            static.include(
                                path=u'common/templates/discussion/' +
                                (template_name) + u'.underscore'))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n</script>\n')
        __M_writer(u'\n\n')
        for template_name in template_names_no_suffix:
            __M_writer(u'<script aria-hidden="true" type="text/template" id="')
            __M_writer(filters.html_escape(filters.decode.utf8(template_name)))
            __M_writer(u'">\n    ')

            def ccall(caller):
                def body():
                    __M_writer = context.writer()
                    return ''

                return [body]

            context.caller_stack.nextcaller = runtime.Namespace(
                'caller', context, callables=ccall(__M_caller))
            try:
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(
                            static.include(
                                path=u'common/templates/discussion/' +
                                (template_name) + u'.underscore'))))
            finally:
                context.caller_stack.nextcaller = None
            __M_writer(u'\n</script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #10
0
 def body():
     __M_writer = context.writer()
     __M_writer(u"\n    new CourseEnrollment('.enroll-btn', '")
     __M_writer(js_escaped_string(course_key))
     __M_writer(u"');\n")
     return ''
Example #11
0
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        display_name = context.get('display_name', UNDEFINED)
        branding_info = context.get('branding_info', UNDEFINED)
        track = context.get('track', UNDEFINED)
        poster = context.get('poster', UNDEFINED)
        transcript_download_formats_list = context.get(
            'transcript_download_formats_list', UNDEFINED)
        handout = context.get('handout', UNDEFINED)
        autoadvance_enabled = context.get('autoadvance_enabled', UNDEFINED)
        cdn_exp_group = context.get('cdn_exp_group', UNDEFINED)
        bumper_metadata = context.get('bumper_metadata', UNDEFINED)
        cdn_eval = context.get('cdn_eval', UNDEFINED)
        transcript_download_format = context.get('transcript_download_format',
                                                 UNDEFINED)
        download_video_link = context.get('download_video_link', UNDEFINED)
        id = context.get('id', UNDEFINED)
        metadata = context.get('metadata', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n\n')
        __M_writer(u'\n')
        if display_name is not UNDEFINED and display_name is not None:
            __M_writer(u'    <h3 class="hd hd-2">')
            __M_writer(filters.html_escape(filters.decode.utf8(display_name)))
            __M_writer(u'</h3>\n')
        __M_writer(u'\n<div\n    id="video_')
        __M_writer(filters.html_escape(filters.decode.utf8(id)))
        __M_writer(u'"\n    class="video closed"\n    data-metadata=\'')
        __M_writer(filters.html_escape(filters.decode.utf8(metadata)))
        __M_writer(u"'\n    data-bumper-metadata='")
        __M_writer(filters.html_escape(filters.decode.utf8(bumper_metadata)))
        __M_writer(u'\'\n    data-autoadvance-enabled="')
        __M_writer(
            filters.html_escape(filters.decode.utf8(autoadvance_enabled)))
        __M_writer(u'"\n    data-poster=\'')
        __M_writer(filters.html_escape(filters.decode.utf8(poster)))
        __M_writer(
            u'\'\n    tabindex="-1"\n>\n    <div class="focus_grabber first"></div>\n\n    <div class="tc-wrapper">\n      <div class="video-wrapper">\n          <span tabindex="0" class="spinner" aria-hidden="false" aria-label="'
        )
        __M_writer(
            filters.html_escape(filters.decode.utf8(
                _('Loading video player'))))
        __M_writer(
            u'"></span>\n          <span tabindex="-1" class="btn-play fa fa-youtube-play fa-2x is-hidden" aria-hidden="true" aria-label="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(_('Play video'))))
        __M_writer(
            u'"></span>\n          <div class="video-player-pre"></div>\n          <div class="video-player">\n              <div id="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(id)))
        __M_writer(
            u'"></div>\n              <h4 class="hd hd-4 video-error is-hidden">'
        )
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(_('No playable video sources found.'))))
        __M_writer(
            u'</h4>\n              <h4 class="hd hd-4 video-hls-error is-hidden">\n                  '
        )
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(
                    _('Your browser does not support this video format. Try using a different browser.'
                      ))))
        __M_writer(
            u'\n              </h4>\n          </div>\n          <div class="video-player-post"></div>\n          <div class="closed-captions"></div>\n          <div class="video-controls is-hidden">\n              <div>\n                  <div class="vcr"><div class="vidtime">0:00 / 0:00</div></div>\n                  <div class="secondary-controls"></div>\n              </div>\n          </div>\n      </div>\n    </div>\n\n    <div class="focus_grabber last"></div>\n\n'
        )
        if download_video_link or track or handout or branding_info:
            __M_writer(
                u'    <h3 class="hd hd-4 downloads-heading sr" id="video-download-transcripts_'
            )
            __M_writer(filters.html_escape(filters.decode.utf8(id)))
            __M_writer(u'">')
            __M_writer(
                filters.html_escape(
                    filters.decode.utf8(_('Downloads and transcripts'))))
            __M_writer(
                u'</h3>\n    <div class="wrapper-downloads" role="region" aria-labelledby="video-download-transcripts_'
            )
            __M_writer(filters.html_escape(filters.decode.utf8(id)))
            __M_writer(u'">\n')
            if download_video_link:
                __M_writer(
                    u'        <div class="wrapper-download-video">\n            <h4 class="hd hd-5">'
                )
                __M_writer(filters.html_escape(filters.decode.utf8(
                    _('Video'))))
                __M_writer(
                    u'</h4>\n            <a class="btn-link video-sources video-download-button" href="'
                )
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(download_video_link)))
                __M_writer(u'">\n                ')
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(_('Download video file'))))
                __M_writer(u'\n            </a>\n        </div>\n')
            if track:
                __M_writer(
                    u'        <div class="wrapper-download-transcripts">\n            <h4 class="hd hd-5">'
                )
                __M_writer(
                    filters.html_escape(filters.decode.utf8(_('Transcripts'))))
                __M_writer(u'</h4>\n')
                if transcript_download_format:
                    __M_writer(
                        u'            <ul class="list-download-transcripts">\n'
                    )
                    for item in transcript_download_formats_list:
                        __M_writer(
                            u'                    <li class="transcript-option">\n                        '
                        )
                        dname = _("Download {file}").format(
                            file=item['display_name'])

                        __M_locals_builtin_stored = __M_locals_builtin()
                        __M_locals.update(
                            __M_dict_builtin([
                                (__M_key, __M_locals_builtin_stored[__M_key])
                                for __M_key in ['dname']
                                if __M_key in __M_locals_builtin_stored
                            ]))
                        __M_writer(
                            u'\n                        <a class="btn btn-link" href="'
                        )
                        __M_writer(
                            filters.html_escape(filters.decode.utf8(track)))
                        __M_writer(u'" data-value="')
                        __M_writer(
                            filters.html_escape(
                                filters.decode.utf8(item['value'])))
                        __M_writer(u'">')
                        __M_writer(
                            filters.html_escape(filters.decode.utf8(dname)))
                        __M_writer(u'</a>\n                    </li>\n')
                    __M_writer(u'            </ul>\n')
                else:
                    __M_writer(
                        u'            <a class="btn-link external-track" href="'
                    )
                    __M_writer(filters.html_escape(filters.decode.utf8(track)))
                    __M_writer(u'">')
                    __M_writer(
                        filters.html_escape(
                            filters.decode.utf8(_('Download transcript'))))
                    __M_writer(u'</a>\n')
                __M_writer(u'        </div>\n')
            if handout:
                __M_writer(
                    u'        <div class="wrapper-handouts">\n            <h4 class="hd hd-5">'
                )
                __M_writer(
                    filters.html_escape(filters.decode.utf8(_('Handouts'))))
                __M_writer(u'</h4>\n            <a class="btn-link" href="')
                __M_writer(filters.html_escape(filters.decode.utf8(handout)))
                __M_writer(u'">')
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(_('Download Handout'))))
                __M_writer(u'</a>\n        </div>\n')
            if branding_info:
                __M_writer(
                    u'        <div class="branding">\n            <span class="host-tag">'
                )
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(branding_info['logo_tag'])))
                __M_writer(u'</span>\n            <a href="')
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(branding_info['url'])))
                __M_writer(u'"><img class="brand-logo" src="')
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(branding_info['logo_src'])))
                __M_writer(u'" alt="')
                __M_writer(
                    filters.html_escape(
                        filters.decode.utf8(branding_info['logo_tag'])))
                __M_writer(u'" /></a>\n        </div>\n')
            __M_writer(u'    </div>\n')
        __M_writer(u'</div>\n')
        if cdn_eval:
            __M_writer(
                u'<script>\n  //TODO: refactor this js into a separate file.\n  function sendPerformanceBeacon(id, expgroup, value, event_name) {\n    var data = {event: event_name, id: id, expgroup: expgroup, value: value, page: "html5vid"};\n    $.ajax({method: "POST", url: "/performance", data: data});\n  }\n  var cdnStartTime;\n  var salt = Math.floor((1 + Math.random()) * 0x100000).toString(36);\n  var id = "'
            )
            __M_writer(js_escaped_string(id))
            __M_writer(
                u'";\n  function initializeCDNExperiment() {\n    sendPerformanceBeacon(id + "_" + salt, '
            )
            __M_writer(filters.html_escape(filters.decode.utf8(cdn_exp_group)))
            __M_writer(
                u', "", "load");\n    cdnStartTime = Date.now();\n    $.each([\'loadstart\', \'abort\', \'error\', \'stalled\', \'loadedmetadata\',\n                    \'loadeddata\', \'canplay\', \'canplaythrough\', \'seeked\'],\n                    function(index, eventName) {\n      $("#video_" + id).bind("html5:" + eventName, null, function() {\n        timeElapsed = Date.now() - cdnStartTime;\n        sendPerformanceBeacon(id + "_" + salt, '
            )
            __M_writer(filters.html_escape(filters.decode.utf8(cdn_exp_group)))
            __M_writer(
                u', timeElapsed, eventName);\n      });\n    });\n  }\n  $("#video_" + id).bind("initialize", null, initializeCDNExperiment);\n  if ($("#video_" + id).hasClass("is-initialized")) {\n    initializeCDNExperiment();\n  }\n</script>\n'
            )
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #12
0
def render_body(context,
                grade_summary,
                grade_cutoffs,
                graph_div_id,
                show_grade_breakdown=True,
                show_grade_cutoffs=True,
                **kwargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(
            show_grade_breakdown=show_grade_breakdown,
            graph_div_id=graph_div_id,
            grade_summary=grade_summary,
            show_grade_cutoffs=show_grade_cutoffs,
            grade_cutoffs=grade_cutoffs,
            kwargs=kwargs)
        sorted = context.get('sorted', UNDEFINED)
        len = context.get('len', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(
            u'\n\n$(function () {\n  function showTooltip(x, y, contents) {\n      $("#tooltip").remove();\n      var $tooltip_div = $(\'<div id="tooltip"></div>\').css({\n          position: \'absolute\',\n          display: \'none\',\n          top: y + 5,\n          left: x + 15,\n          border: \'1px solid #000\',\n          padding: \'4px 6px\',\n          color: \'#fff\',\n          \'background-color\': \'#222\',\n          opacity: 0.90\n      });\n\n      edx.HtmlUtils.setHtml(\n          $tooltip_div,\n          edx.HtmlUtils.HTML(contents)\n      );\n      \n      edx.HtmlUtils.append(\n          $(\'body\'),\n          edx.HtmlUtils.HTML($tooltip_div)\n      );\n      \n      $(\'#tooltip\').fadeIn(200);\n  }\n  /* -------------------------------- Grade detail bars -------------------------------- */\n    \n  '
        )

        colors = ["#b72121", "#600101", "#666666", "#333333"]
        categories = {}

        tickIndex = 1
        sectionSpacer = 0.25
        sectionIndex = 0

        ticks = []  #These are the indices and x-axis labels for the data
        bottomTicks = []  #Labels on the bottom
        detail_tooltips = {
        }  #This an dictionary mapping from 'section' -> array of detail_tooltips
        droppedScores = [
        ]  #These are the datapoints to indicate assignments which are not factored into the total score
        dropped_score_tooltips = []

        for section in grade_summary['section_breakdown']:
            if section.get('prominent', False):
                tickIndex += sectionSpacer

            if section['category'] not in categories:
                colorIndex = len(categories) % len(colors)
                categories[section['category']] = {
                    'label': section['category'],
                    'data': [],
                    'color': colors[colorIndex]
                }

            categoryData = categories[section['category']]

            ## Because this is Python (Mako) embedded in JavaScript, our xss linting script is
            ## thoroughly confused. We should rewrite this file to remove Python/Mako.
            ## xss-lint: disable=javascript-jquery-append
            categoryData['data'].append([tickIndex, section['percent']])

            ## Note that some courses had stored images in the Abbreviation. We are no longer
            ## allowing the display of such images, and remove any previously stored HTML
            ## to prevent ugly HTML from being shown to learners.
            ## xss-lint: disable=javascript-jquery-append
            ticks.append([
                tickIndex,
                bleach.clean(section['label'], tags=[], strip=True)
            ])

            if section['category'] in detail_tooltips:
                ## xss-lint: disable=javascript-jquery-append
                detail_tooltips[section['category']].append(section['detail'])
            else:
                detail_tooltips[section['category']] = [
                    section['detail'],
                ]

            if 'mark' in section:
                ## xss-lint: disable=javascript-jquery-append
                droppedScores.append([tickIndex, 0.05])
                ## xss-lint: disable=javascript-jquery-append
                dropped_score_tooltips.append(section['mark']['detail'])

            tickIndex += 1

            if section.get('prominent', False):
                tickIndex += sectionSpacer

        ## ----------------------------- Grade overview bar ------------------------- ##
        tickIndex += sectionSpacer

        series = categories.values()
        overviewBarX = tickIndex
        extraColorIndex = len(
            categories
        )  #Keeping track of the next color to use for categories not in categories[]

        if show_grade_breakdown:
            for section in grade_summary['grade_breakdown'].itervalues():
                if section['percent'] > 0:
                    if section['category'] in categories:
                        color = categories[section['category']]['color']
                    else:
                        color = colors[extraColorIndex % len(colors)]
                        extraColorIndex += 1
                    ## xss-lint: disable=javascript-jquery-append
                    series.append({
                        'label': section['category'] + "-grade_breakdown",
                        'data': [[overviewBarX, section['percent']]],
                        'color': color
                    })

                    detail_tooltips[section['category'] +
                                    "-grade_breakdown"] = [section['detail']]

            ticks += [[overviewBarX, "Total"]]
            tickIndex += 1 + sectionSpacer

        totalScore = grade_summary['percent']
        detail_tooltips['Dropped Scores'] = dropped_score_tooltips

        ## ----------------------------- Grade cutoffs ------------------------- ##

        grade_cutoff_ticks = [[1, "100%"], [0, "0%"]]
        if show_grade_cutoffs:
            grade_cutoff_ticks = [[1, "100%"], [0, "0%"]]
            descending_grades = sorted(grade_cutoffs,
                                       key=lambda x: grade_cutoffs[x],
                                       reverse=True)
            for grade in descending_grades:
                percent = grade_cutoffs[grade]
                ## xss-lint: disable=javascript-jquery-append
                grade_cutoff_ticks.append(
                    [percent, u"{0} {1:.0%}".format(grade, percent)])
        else:
            grade_cutoff_ticks = []

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([
                (__M_key, __M_locals_builtin_stored[__M_key]) for __M_key in [
                    'colorIndex', 'color', 'series', 'extraColorIndex',
                    'grade_cutoff_ticks', 'colors', 'totalScore',
                    'sectionSpacer', 'dropped_score_tooltips',
                    'descending_grades', 'section', 'ticks', 'percent',
                    'detail_tooltips', 'grade', 'bottomTicks', 'tickIndex',
                    'categoryData', 'categories', 'sectionIndex',
                    'overviewBarX', 'droppedScores'
                ] if __M_key in __M_locals_builtin_stored
            ]))
        __M_writer(u'\n  \n  var series = ')
        __M_writer(dump_js_escaped_json(series))
        __M_writer(u';\n  var ticks = ')
        __M_writer(dump_js_escaped_json(ticks))
        __M_writer(u';\n  var bottomTicks = ')
        __M_writer(dump_js_escaped_json(bottomTicks))
        __M_writer(u';\n  var detail_tooltips = ')
        __M_writer(dump_js_escaped_json(detail_tooltips))
        __M_writer(u';\n  var droppedScores = ')
        __M_writer(dump_js_escaped_json(droppedScores))
        __M_writer(u';\n  var grade_cutoff_ticks = ')
        __M_writer(dump_js_escaped_json(grade_cutoff_ticks))
        __M_writer(
            u'\n  \n  var yAxisTooltips={};\n\n    /*\n    series looks like:\n    [\n        {\n            color: "#600101",\n            label: "Homework",\n            data: [[1, 0.06666666666666667], [2, 1], [3.25, .53]]\n        },\n        ...\n    ]\n\n    detail_tooltips looks like:\n    {\n        "Dropped Scores": [0: "The lowest 1...:],\n        "Homework": [\n            0: "Homework 1 -- Homework -- Question Styles 7% (1/15)",\n            1: "Homework 2 -- Homework -- Get Social 100% (1/1)",\n            2: "Homework Average = 53%"\n        ],\n        ...\n    }\n    */\n\n  // loop through the series and extract the matching tick and the series label\n  for (var seriesIndex = 0; seriesIndex < series.length; seriesIndex++) {\n      for (var dataIndex = 0; dataIndex < series[seriesIndex][\'data\'].length; dataIndex++) {\n          var tickIndex = series[seriesIndex][\'data\'][dataIndex][0];\n          // There may be more than one detail tooltip for a given tickIndex. If so,\n          // push the new tooltip on the existing list.\n          if (tickIndex in yAxisTooltips) {\n              yAxisTooltips[tickIndex].push(detail_tooltips[series[seriesIndex][\'label\']][dataIndex]);\n          } else {\n              yAxisTooltips[tickIndex] = [detail_tooltips[series[seriesIndex][\'label\']][dataIndex]];\n          }\n          // If this item was a dropped score, add the tooltip message about that.\n          for (var droppedIndex = 0; droppedIndex < droppedScores.length; droppedIndex++) {\n              if (tickIndex === droppedScores[droppedIndex][0]) {\n                  yAxisTooltips[tickIndex].push(detail_tooltips["Dropped Scores"][droppedIndex]);\n              }\n          }\n      }\n  }\n\n  // hide the vertical axis since they are audibly lacking context\n  for (var i = 0; i < grade_cutoff_ticks.length; i++) {\n      grade_cutoff_ticks[i][1] = edx.HtmlUtils.joinHtml(\n          edx.HtmlUtils.HTML(\'<span aria-hidden="true">\'),\n          grade_cutoff_ticks[i][1],\n          edx.HtmlUtils.HTML(\'</span>\')\n      ).text;\n  }\n    \n  //Always be sure that one series has the xaxis set to 2, or the second xaxis labels won\'t show up\n  series.push( {label: \'Dropped Scores\', data: droppedScores, points: {symbol: "cross", show: true, radius: 3}, bars: {show: false}, color: "#333"} );\n  \n  // Allow for arbitrary grade markers e.g. [\'A\', \'B\', \'C\'], [\'Pass\'], etc.\n  var ascending_grades = grade_cutoff_ticks.map(function (el) { return el[0]; }); // Percentage point (in decimal) of each grade cutoff\n  ascending_grades.sort();\n\n  var colors = [\'#f3f3f3\', \'#e9e9e9\', \'#ddd\'];\n  var markings = [];\n  for(var i=1; i<ascending_grades.length-1; i++) // Skip the i=0 marking, which starts from 0%\n    markings.push({yaxis: {from: ascending_grades[i], to: ascending_grades[i+1]}, color: colors[(i-1) % colors.length]});\n\n  var options = {\n    series: {\n        stack: true,\n        lines: {\n            show: false,\n            steps: false\n        },\n        bars: {\n            show: true,\n            barWidth: 0.8,\n            align: \'center\',\n            lineWidth: 0,\n            fill: .8\n        }\n    },\n    xaxis: {\n        tickLength: 0,\n        min: 0.0,\n        max: '
        )
        __M_writer(dump_js_escaped_json(tickIndex - sectionSpacer))
        __M_writer(
            u',\n        ticks: function() {\n            for (var i = 0; i < ticks.length; i++) {\n                var tickLabel = edx.HtmlUtils.joinHtml(\n                    // The very last tick will be for the total, and it usually is composed of a number of different\n                    // grading types. To help clarify, do NOT make the label ("Total") aria-hidden in that case.\n                    edx.HtmlUtils.HTML(i < ticks.length - 1 ? \'<span aria-hidden="true">\' : \'<span>\'),\n                    ticks[i][1],\n                    edx.HtmlUtils.HTML(\'</span>\')\n                );\n                var elementTooltips = yAxisTooltips[ticks[i][0]];\n                if (elementTooltips) {\n                    for (var tooltipIndex = 0; tooltipIndex < elementTooltips.length; tooltipIndex++) {\n                        tickLabel = edx.HtmlUtils.joinHtml(\n                            tickLabel,\n                            edx.HtmlUtils.HTML(\'<span class="sr">\'),\n                            elementTooltips[tooltipIndex],\n                            edx.HtmlUtils.HTML(\'<br></span>\')\n                        );\n                    }\n                }\n                ticks[i][1] = tickLabel;\n            }\n            return ticks;\n        },\n        labelAngle: 90\n    },\n    yaxis: {\n        ticks: grade_cutoff_ticks,\n        min: 0.0,\n        max: 1.0,\n        labelWidth: 100\n    },\n    grid: {\n        hoverable: true,\n        clickable: true,\n        borderWidth: 1,\n        markings: markings\n    },\n    legend: {\n        show: false\n    }\n  };\n  \n  var $grade_detail_graph = $("#'
        )
        __M_writer(js_escaped_string(graph_div_id))
        __M_writer(
            u'");\n  if ($grade_detail_graph.length > 0) {\n    var plot = $.plot($grade_detail_graph, series, options);\n    \n'
        )
        if show_grade_breakdown:
            __M_writer(u'      var o = plot.pointOffset(\n          {x: ')
            __M_writer(dump_js_escaped_json(overviewBarX))
            __M_writer(u' , y: ')
            __M_writer(dump_js_escaped_json(totalScore))
            __M_writer(
                u'}\n      );\n\n      edx.HtmlUtils.append(\n          $grade_detail_graph,\n          edx.HtmlUtils.joinHtml(\n              // xss-lint: disable=javascript-concat-html\n              edx.HtmlUtils.HTML(\'<div class="overallGrade" style="position:absolute;left:\' + (o.left - 12) + \'px;top:\' + (o.top - 20) + \'px">\'),\n              edx.HtmlUtils.HTML(\'<span class=sr>\'),\n              gettext(\'Overall Score\'),\n              edx.HtmlUtils.HTML(\'<br></span>\'),\n              \''
            )
            __M_writer(
                js_escaped_string(
                    '{totalscore:.0%}'.format(totalscore=totalScore)))
            __M_writer(
                u"',\n              edx.HtmlUtils.HTML('</div>')\n          )\n      );\n\n"
            )
        __M_writer(
            u'\n    $grade_detail_graph.find(\'.xAxis .tickLabel\').attr(\'tabindex\', \'0\').focus(function(event) {\n        var $target = $(event.target), srElements = $target.find(\'.sr\'), srText="", i;\n        if (srElements.length > 0) {\n            for (i = 0; i < srElements.length; i++) {\n                srText += srElements[i].innerHTML;\n            }\n            // Position the tooltip slightly above the tick label.\n            showTooltip($target.offset().left - 70, $target.offset().top - 120, srText);\n        }\n    });\n\n    $grade_detail_graph.focusout(function(){\n        $("#tooltip").remove();\n    });\n  }\n  \n      \n  var previousPoint = null;\n  $grade_detail_graph.bind("plothover", function (event, pos, item) {\n    if (item) {\n      if (previousPoint != (item.dataIndex, item.seriesIndex)) {\n        previousPoint = (item.dataIndex, item.seriesIndex);\n            \n        if (item.series.label in detail_tooltips) {\n          var series_tooltips = detail_tooltips[item.series.label];\n          if (item.dataIndex < series_tooltips.length) {\n            showTooltip(item.pageX, item.pageY, series_tooltips[item.dataIndex]);\n          }\n        }\n\n      }\n    } else {\n      $("#tooltip").remove();\n      previousPoint = null;            \n    }\n  });\n});\n'
        )
        return ''
    finally:
        context.caller_stack._pop_frame()
Example #13
0
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        can_create_subcomment = context.get('can_create_subcomment', UNDEFINED)
        display_name = context.get('display_name', UNDEFINED)
        discussion_target = context.get('discussion_target', UNDEFINED)
        discussion_category = context.get('discussion_category', UNDEFINED)
        can_create_thread = context.get('can_create_thread', UNDEFINED)
        user = context.get('user', UNDEFINED)
        login_msg = context.get('login_msg', UNDEFINED)
        can_create_comment = context.get('can_create_comment', UNDEFINED)
        course_id = context.get('course_id', UNDEFINED)
        discussion_id = context.get('discussion_id', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n\n')
        runtime._include_file(context, u'_underscore_templates.html',
                              _template_uri)
        __M_writer(u'\n')
        runtime._include_file(context, u'_thread_list_template.html',
                              _template_uri)
        __M_writer(u'\n\n')
        __M_writer(u'\n\n<div class="discussion-module" data-discussion-id="')
        __M_writer(filters.html_escape(filters.decode.utf8(discussion_id)))
        __M_writer(u'"\n    data-user-create-comment="')
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(json_dumps(can_create_comment))))
        __M_writer(u'"\n    data-user-create-subcomment="')
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(json_dumps(can_create_subcomment))))
        __M_writer(u'"\n    data-read-only="')
        __M_writer(
            filters.html_escape(
                filters.decode.utf8('false' if can_create_thread else 'true')))
        __M_writer(u'">\n')
        if not user.is_authenticated:
            __M_writer(
                u'        <div class="page-banner">\n            <div class="alert alert-warning" role="alert">\n                <span class="icon icon-alert fa fa fa-warning" aria-hidden="true"></span>\n                <div class="message-content">'
            )
            __M_writer(filters.html_escape(filters.decode.utf8(login_msg)))
            __M_writer(
                u'</div>\n            </div>\n        </div>\n        <br>\n')
        __M_writer(
            u'    <div class="discussion-module-header">\n        <h3 class="hd hd-3 discussion-module-title">'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(_(display_name))))
        __M_writer(
            u'</h3>\n        <div class="inline-discussion-topic"><span class="inline-discussion-topic-title">'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(_("Topic:"))))
        __M_writer(u'</span> ')
        __M_writer(
            filters.html_escape(filters.decode.utf8(discussion_category)))
        __M_writer(u'\n')
        if discussion_target:
            __M_writer(u'                    / ')
            __M_writer(
                filters.html_escape(filters.decode.utf8(discussion_target)))
            __M_writer(u'\n')
        __M_writer(
            u'           </div>\n    </div>\n    <button class="discussion-show btn"\n        data-discussion-id="'
        )
        __M_writer(filters.html_escape(filters.decode.utf8(discussion_id)))
        __M_writer(u'"\n        ')
        __M_writer(
            filters.html_escape(
                filters.decode.utf8(
                    "disabled=disabled" if not user.is_authenticated else "")))
        __M_writer(u'>\n        <span class="button-text">')
        __M_writer(
            filters.html_escape(filters.decode.utf8(_("Show Discussion"))))
        __M_writer(
            u'</span>\n    </button>\n\n</div>\n<script type="text/javascript">\nvar $$course_id = "'
        )
        __M_writer(js_escaped_string(course_id))
        __M_writer(
            u'";\n\nfunction DiscussionInlineBlock(runtime, element) {\n    \'use strict\';\n    var el = $(element).find(\'.discussion-module\');\n    new DiscussionInlineView({ el: el, readOnly: el.data(\'read-only\') });\n}\n</script>\n'
        )
        return ''
    finally:
        context.caller_stack._pop_frame()
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        root_url = context.get('root_url', UNDEFINED)
        annotated_content_info = context.get('annotated_content_info',
                                             UNDEFINED)
        course_settings = context.get('course_settings', UNDEFINED)
        roles = context.get('roles', UNDEFINED)
        thread_pages = context.get('thread_pages', UNDEFINED)
        is_commentable_divided = context.get('is_commentable_divided',
                                             UNDEFINED)
        sort_preference = context.get('sort_preference', UNDEFINED)
        user_info = context.get('user_info', UNDEFINED)
        threads = context.get('threads', UNDEFINED)
        unicode = context.get('unicode', UNDEFINED)
        discussion_default_topic_id = context.get(
            'discussion_default_topic_id', UNDEFINED)
        course = context.get('course', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(
            u"\n\n(function (require, define) {\n    var registerDiscussionClass = function(moduleName, modulePath) {\n        define(\n            modulePath,\n            [],\n            function() {\n                var discussionClass = window[moduleName];\n                if (!discussionClass) {\n                  throw new Error('Discussion class not loaded: ' + moduleName);\n                }\n                return discussionClass;\n            }\n        );\n    }\n\n"
        )
        __M_writer(u'    ')

        discussion_classes = [
            ['Discussion', 'common/js/discussion/discussion'],
            ['Content', 'common/js/discussion/content'],
            [
                'DiscussionModuleView',
                'common/js/discussion/discussion_module_view'
            ],
            [
                'DiscussionThreadView',
                'common/js/discussion/views/discussion_thread_view'
            ],
            [
                'DiscussionThreadListView',
                'common/js/discussion/views/discussion_thread_list_view'
            ],
            [
                'DiscussionThreadProfileView',
                'common/js/discussion/views/discussion_thread_profile_view'
            ],
            ['DiscussionUtil', 'common/js/discussion/utils'],
            [
                'DiscussionCourseSettings',
                'common/js/discussion/models/discussion_course_settings'
            ],
            ['DiscussionUser', 'common/js/discussion/models/discussion_user'],
            ['NewPostView', 'common/js/discussion/views/new_post_view'],
        ]

        __M_locals_builtin_stored = __M_locals_builtin()
        __M_locals.update(
            __M_dict_builtin([(__M_key, __M_locals_builtin_stored[__M_key])
                              for __M_key in ['discussion_classes']
                              if __M_key in __M_locals_builtin_stored]))
        __M_writer(u'\n\n')
        for discussion_class_info in discussion_classes:
            __M_writer(u"        registerDiscussionClass(\n            '")
            __M_writer(js_escaped_string(discussion_class_info[0]))
            __M_writer(u"',\n            '")
            __M_writer(js_escaped_string(discussion_class_info[1]))
            __M_writer(u"'\n        );\n")
        __M_writer(u'\n')
        __M_writer(
            u"    $(function() {\n        require(['discussion/js/discussion_board_factory'], function (DiscussionBoardFactory) {\n            DiscussionBoardFactory({\n                courseId: '"
        )
        __M_writer(js_escaped_string(unicode(course.id)))
        __M_writer(
            u'\',\n                $el: $(".discussion-board"),\n                rootUrl: \''
        )
        __M_writer(js_escaped_string(root_url))
        __M_writer(u"',\n                userInfo: ")
        __M_writer(dump_js_escaped_json(user_info))
        __M_writer(u',\n                roles: ')
        __M_writer(dump_js_escaped_json(roles))
        __M_writer(u",\n                sortPreference: '")
        __M_writer(js_escaped_string(sort_preference))
        __M_writer(u"',\n                threads: ")
        __M_writer(dump_js_escaped_json(threads))
        __M_writer(u",\n                threadPages: '")
        __M_writer(js_escaped_string(thread_pages))
        __M_writer(u"',\n                contentInfo: ")
        __M_writer(dump_js_escaped_json(annotated_content_info))
        __M_writer(u",\n                courseName: '")
        __M_writer(js_escaped_string(course.display_name_with_default))
        __M_writer(u"',\n                courseSettings: ")
        __M_writer(dump_js_escaped_json(course_settings))
        __M_writer(u',\n                isCommentableDivided: ')
        __M_writer(dump_js_escaped_json(is_commentable_divided))
        __M_writer(u",\n                defaultTopicId: '")
        __M_writer(js_escaped_string(discussion_default_topic_id))
        __M_writer(
            u"'\n            });\n        });\n    });\n}).call(this, require || RequireJS.require, define || RequireJS.define);\n"
        )
        return ''
    finally:
        context.caller_stack._pop_frame()