Ejemplo n.º 1
0
    def init_template_values(self, environ, prefs=None):
        """Initializes template variables with common values."""
        self.template_value[COURSE_INFO_KEY] = environ
        self.template_value[
            'page_locale'] = self.app_context.get_current_locale()
        self.template_value['html_hooks'] = HtmlHooks(self.get_course(),
                                                      prefs=prefs)
        self.template_value['is_course_admin'] = Roles.is_course_admin(
            self.app_context)
        self.template_value['can_see_drafts'] = (
            courses_module.courses.can_see_drafts(self.app_context))
        self.template_value[
            'is_read_write_course'] = self.app_context.fs.is_read_write()
        self.template_value['is_super_admin'] = Roles.is_super_admin()
        self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
        self.template_value['left_links'] = []
        for func in self.LEFT_LINKS:
            self.template_value['left_links'].extend(func(self.app_context))
        self.template_value['right_links'] = []
        for func in self.RIGHT_LINKS:
            self.template_value['right_links'].extend(func(self.app_context))

        if not prefs:
            prefs = models.StudentPreferencesDAO.load_or_create()
        self.template_value['student_preferences'] = prefs

        if (Roles.is_course_admin(self.app_context)
                and not appengine_config.PRODUCTION_MODE and prefs
                and prefs.show_jinja_context):

            @jinja2.contextfunction
            def get_context(context):
                return context

            self.template_value['context'] = get_context

        if CAN_PUT_DEBUG_INFO_INTO_PAGES.value:
            self.template_value['debug_info'] = self.debug_info()

        self.template_value[
            'extra_global_css_urls'] = self.EXTRA_GLOBAL_CSS_URLS
        self.template_value['extra_global_js_urls'] = self.EXTRA_GLOBAL_JS_URLS

        # Common template information for the locale picker (only shown for
        # user in session)
        can_student_change_locale = (
            self.get_course().get_course_setting('can_student_change_locale')
            or self.get_course().app_context.can_pick_all_locales())
        if can_student_change_locale:
            self.template_value['available_locales'] = [{
                'name':
                locales.get_locale_display_name(loc),
                'value':
                loc
            } for loc in self.app_context.get_allowed_locales()]
            self.template_value['locale_xsrf_token'] = (
                XsrfTokenManager.create_xsrf_token(
                    StudentLocaleRESTHandler.XSRF_TOKEN_NAME))
            self.template_value['selected_locale'] = self.get_locale_for(
                self.request, self.app_context, prefs=prefs)
Ejemplo n.º 2
0
    def init_template_values(self, environ, prefs=None):
        """Initializes template variables with common values."""
        self.template_value[COURSE_INFO_KEY] = environ
        self.template_value[
            'page_locale'] = self.app_context.get_current_locale()
        self.template_value['html_hooks'] = HtmlHooks(
            self.get_course(), prefs=prefs)
        self.template_value['is_course_admin'] = Roles.is_course_admin(
            self.app_context)
        self.template_value['can_see_drafts'] = (
            courses_module.courses.can_see_drafts(self.app_context))
        self.template_value[
            'is_read_write_course'] = self.app_context.fs.is_read_write()
        self.template_value['is_super_admin'] = Roles.is_super_admin()
        self.template_value[COURSE_BASE_KEY] = self.get_base_href(self)
        self.template_value['left_links'] = []
        for func in self.LEFT_LINKS:
            self.template_value['left_links'].extend(func(self.app_context))
        self.template_value['right_links'] = []
        for func in self.RIGHT_LINKS:
            self.template_value['right_links'].extend(func(self.app_context))

        if not prefs:
            prefs = models.StudentPreferencesDAO.load_or_create()
        self.template_value['student_preferences'] = prefs

        if (Roles.is_course_admin(self.app_context) and
            not appengine_config.PRODUCTION_MODE and
            prefs and prefs.show_jinja_context):

            @jinja2.contextfunction
            def get_context(context):
                return context
            self.template_value['context'] = get_context

        if CAN_PUT_DEBUG_INFO_INTO_PAGES.value:
            self.template_value['debug_info'] = self.debug_info()

        self.template_value[
            'extra_global_css_urls'] = self.EXTRA_GLOBAL_CSS_URLS
        self.template_value[
            'extra_global_js_urls'] = self.EXTRA_GLOBAL_JS_URLS

        # Common template information for the locale picker (only shown for
        # user in session)
        can_student_change_locale = (
            self.get_course().get_course_setting('can_student_change_locale')
            or self.get_course().app_context.can_pick_all_locales())
        if can_student_change_locale:
            self.template_value['available_locales'] = [
                {
                    'name': locales.get_locale_display_name(loc),
                    'value': loc
                } for loc in self.app_context.get_allowed_locales()]
            self.template_value['locale_xsrf_token'] = (
                XsrfTokenManager.create_xsrf_token(
                    StudentLocaleRESTHandler.XSRF_TOKEN_NAME))
            self.template_value['selected_locale'] = self.get_locale_for(
                self.request, self.app_context, prefs=prefs)
Ejemplo n.º 3
0
 def test_localized_display_name(self):
     self.assertEquals('Deutsch (de)', locales.get_locale_display_name('de'))
Ejemplo n.º 4
0
 def test_localized_display_name(self):
     self.assertEquals('Deutsch (de)', locales.get_locale_display_name('de'))