Esempio n. 1
0
 def get_template(self, template_file, additional_dirs=None):
     """Computes location of template files for the current namespace."""
     self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
     self.template_value["is_course_admin"] = Roles.is_course_admin(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)
     template_environ = self.app_context.get_template_environ(
         self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
     )
     template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)
     return template_environ.get_template(template_file)
Esempio n. 2
0
    def _get_template_env(self, handler, expanded_gcb_tags):
        app_context = self.course.app_context
        if expanded_gcb_tags:
            tags = expanded_gcb_tags.strip().split()
            tags_filter = lambda k, v: k in tags
        else:
            tags_filter = lambda k, v: True

        env = app_context.get_template_environ(
            app_context.get_current_locale(), [_TEMPLATES_DIR])
        env.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(
            handler, tags_filter=tags_filter)
        return env
Esempio n. 3
0
    def _get_template_env(self, handler, expanded_gcb_tags):
        app_context = self.course.app_context
        if expanded_gcb_tags:
            tags = expanded_gcb_tags.strip().split()
            tags_filter = lambda k, v: k in tags
        else:
            tags_filter = lambda k, v: True

        env = app_context.get_template_environ(
            app_context.get_current_locale(), [_TEMPLATES_DIR])
        env.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(
            handler, tags_filter=tags_filter)
        return env
Esempio n. 4
0
 def get_template(self, template_file, additional_dirs=None):
     """Computes location of template files for the current namespace."""
     self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
     self.template_value['is_course_admin'] = Roles.is_course_admin(
         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)
     template_environ = self.app_context.get_template_environ(
         self.template_value[COURSE_INFO_KEY]['course']['locale'],
         additional_dirs)
     template_environ.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(
         self)
     return template_environ.get_template(template_file)
Esempio n. 5
0
    def get_template(self, template_file, additional_dirs=None):
        """Computes location of template files for the current namespace."""
        self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
        self.template_value["is_course_admin"] = Roles.is_course_admin(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)
        template_environ = self.app_context.get_template_environ(
            self.template_value[COURSE_INFO_KEY]["course"]["locale"], additional_dirs
        )
        template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)

        course = sites.get_course_for_current_request()
        if course.get_slug().split("_")[-1] == "DFR":
            self.template_value["gDefier_enabled"] = True

        return template_environ.get_template(template_file)
Esempio n. 6
0
    def get_template(self, template_file, additional_dirs=None, prefs=None):
        """Computes location of template files for the current namespace."""

        _p = self.app_context.get_environ()
        self.init_template_values(_p, prefs=prefs)
        template_environ = self.app_context.get_template_environ(
            self.app_context.get_current_locale(), additional_dirs)
        template_environ.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(
            self)
        template_environ.globals.update({
            'display_unit_title': (lambda unit: display_unit_title(unit, _p)),
            'display_short_unit_title':
            (lambda unit: display_short_unit_title(unit, _p)),
            'display_lesson_title':
            (lambda unit, lesson: display_lesson_title(unit, lesson, _p))
        })

        return template_environ.get_template(template_file)
Esempio n. 7
0
    def get_template(self, template_file, additional_dirs=None, prefs=None):
        """Computes location of template files for the current namespace."""

        _p = self.app_context.get_environ()
        self.init_template_values(_p, prefs=prefs)
        template_environ = self.app_context.get_template_environ(self.app_context.get_current_locale(), additional_dirs)
        template_environ.filters["gcb_tags"] = jinja_utils.get_gcb_tags_filter(self)
        template_environ.globals.update(
            {
                "display_unit_title": (lambda unit: resources_display.display_unit_title(unit, self.app_context)),
                "display_short_unit_title": (
                    lambda unit: resources_display.display_short_unit_title(unit, self.app_context)
                ),
                "display_lesson_title": (
                    lambda unit, lesson: resources_display.display_lesson_title(unit, lesson, self.app_context)
                ),
            }
        )

        return template_environ.get_template(template_file)
Esempio n. 8
0
    def get_template(self, template_file, additional_dirs=None, prefs=None):
        """Computes location of template files for the current namespace."""

        _p = self.app_context.get_environ()
        self.init_template_values(_p, prefs=prefs)
        # Added in order to support moving many instances of
        # courses/*/views to a single /templates/views
        additional_dirs = ["templates/views/"]
        template_environ = self.app_context.get_template_environ(
            self.app_context.get_current_locale(), additional_dirs)
        template_environ.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(
            self)
        template_environ.globals.update({
            'display_unit_title': (lambda unit: display_unit_title(unit, _p)),
            'display_short_unit_title':
            (lambda unit: display_short_unit_title(unit, _p)),
            'display_lesson_title':
            (lambda unit, lesson: display_lesson_title(unit, lesson, _p))
        })

        return template_environ.get_template(template_file)
Esempio n. 9
0
    def get_template(self, template_file, additional_dirs=None, prefs=None):
        """Computes location of template files for the current namespace."""

        _p = self.app_context.get_environ()
        self.init_template_values(_p, prefs=prefs)
        # Added in order to support moving many instances of 
        # courses/*/views to a single /templates/views
        additional_dirs = ["templates/views/"] 
        template_environ = self.app_context.get_template_environ(
            self.app_context.get_current_locale(), additional_dirs)
        template_environ.filters[
            'gcb_tags'] = jinja_utils.get_gcb_tags_filter(self)
        template_environ.globals.update({
            'display_unit_title': (
                lambda unit: display_unit_title(unit, _p)),
            'display_short_unit_title': (
                lambda unit: display_short_unit_title(unit, _p)),
            'display_lesson_title': (
                lambda unit, lesson: display_lesson_title(unit, lesson, _p))})

        return template_environ.get_template(template_file)
Esempio n. 10
0
 def _get_template_env(self, handler):
     app_context = self.course.app_context
     env = app_context.get_template_environ(
         app_context.get_current_locale(), [_TEMPLATES_DIR])
     env.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(handler)
     return env
Esempio n. 11
0
 def _apply_gcb_tags(self, text):
     return jinja_utils.get_gcb_tags_filter(self)(text)
Esempio n. 12
0
File: gql.py Progetto: blckt/lib
 def _get_template_env(self, handler):
     app_context = self.course.app_context
     env = app_context.get_template_environ(
         app_context.get_current_locale(), [_TEMPLATES_DIR])
     env.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(handler)
     return env
Esempio n. 13
0
    def get_template(self, template_file, additional_dirs=None):
        """Computes location of template files for the current namespace."""
        self.template_value[COURSE_INFO_KEY] = self.app_context.get_environ()
        self.template_value['is_course_admin'] = Roles.is_course_admin(
            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)
        template_environ = self.app_context.get_template_environ(
            self.template_value[COURSE_INFO_KEY]['course']['locale'],
            additional_dirs)
        import khan.util as util
        import khan.templatefilters as templatefilters
        import badges.templatetags
        import avatars.templatetags
        import js_css_packages.templatetags
        import app
        import templatetags
        import user_models
        template_environ.filters['gcb_tags'] = jinja_utils.get_gcb_tags_filter(
            self)
        template_environ.filters[
            'thousands_separated'] = util.thousands_separated_number
        template_environ.filters['pluralize'] = templatefilters.pluralize
        template_environ.filters["escapejs"] = templatefilters.escapejs
        template_environ.globals["badges"] = badges.templatetags
        template_environ.globals["avatars"] = avatars.templatetags
        template_environ.globals[
            "js_css_packages"] = js_css_packages.templatetags
        template_environ.globals["App"] = app.App
        template_environ.globals["templatetags"] = templatetags
        from user_models import StudentList, UserData, ParentChildPair
        import logging
        current_user_data = UserData.current(True)
        #logging.error("Current user: %s" % current_user_data)
        #logging.error("Nickname: %s" % current_user_data.nickname)
        #logging.error("Username: %s" % current_user_data.username)
        #logging.error("UserNickname: %s" % current_user_data.user_nickname)
        #logging.error("UserEmail: %s" % current_user_data.user_email)
        if current_user_data:
            template_environ.globals[
                "username"] = current_user_data.nickname or current_user_data.username or current_user_data.user_nickname or current_user_data.user_email
        else:
            template_environ.globals["username"] = ""

        #template_environ['environment_args'] = {'autoescape' : False}


#        template_environ["filters"] = {
#            'gcb_tags': jinja_utils.get_gcb_tags_filter(self),
#            #"thousands_separated": util.thousands_separated_number,
#        }
#        template_environ["globals"] = {
#            "templatetags": templatetags,
#            "profiles": profiles.templatetags,
#            "avatars": avatars.templatetags,
#            "badges": badges.templatetags,
#            "phantom_users": phantom_users.templatetags,
##            "gae_mini_profiler": gae_mini_profiler.templatetags,
##            "xsrf": api.auth.xsrf,
##            "UserData": UserData,
##            "json": json,
##            "App": App,
##            "handlebars_template": handlebars.render.render_from_jinja,
##            "gandalf": gandalf.bridge.gandalf,
#        }
        return template_environ.get_template(template_file)