当前位置: 首页>>代码示例>>Python>>正文


Python helpers.get_varname函数代码示例

本文整理汇总了Python中sekizai.helpers.get_varname函数的典型用法代码示例。如果您正苦于以下问题:Python get_varname函数的具体用法?Python get_varname怎么用?Python get_varname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_varname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_render_plugin_toolbar_config

    def test_render_plugin_toolbar_config(self):
        """
        Ensures that the render_plugin_toolbar_config tag
        sets the correct values in the sekizai context.
        """
        page = self._getfirst()
        placeholder = page.placeholders.get(slot='body')
        parent_plugin = add_plugin(placeholder, 'SolarSystemPlugin', 'en')
        child_plugin_1 = add_plugin(placeholder, 'PlanetPlugin', 'en', target=parent_plugin)
        child_plugin_2 = add_plugin(placeholder, 'PlanetPlugin', 'en', target=parent_plugin)

        parent_plugin.child_plugin_instances = [
            child_plugin_1,
            child_plugin_2,
        ]

        plugins = [
            parent_plugin,
            child_plugin_1,
            child_plugin_2,
        ]

        placeholder_slot = placeholder.slot

        with self.login_user_context(self.get_superuser()):
            context = self.get_context(path=page.get_absolute_url(), page=page)
            context['request'].toolbar = CMSToolbar(context['request'])
            context['request'].toolbar.edit_mode = True
            context[get_varname()] = defaultdict(UniqueSequence)

            parent_plugin.render_plugin(
                context,
                placeholder=placeholder,
                processors=[toolbar_plugin_processor],
            )

            # Rendering the parent plugin will put
            # three strings into the "js" collection in sekizai.
            # These strings contain the toolbar configuration
            # for each plugin.
            plugin_scripts = context[get_varname()]['js']

            self.assertEqual(len(plugin_scripts), 3)

            for plugin, script in zip(plugins, reversed(plugin_scripts)):
                plugin_instance = plugin.get_plugin_class_instance()

                child_classes = plugin_instance.get_child_classes(placeholder_slot, page) or []
                plugin_restrictions = ['"{}"'.format(klass) for klass in child_classes]
                plugin_restrictions_text = "plugin_restriction: [{}]".format(','.join(plugin_restrictions))

                parent_classes = plugin_instance.get_parent_classes(placeholder_slot, page) or []
                parent_restrictions = ['"{}"'.format(klass) for klass in parent_classes]
                parent_restrictions_text = "plugin_parent_restriction: [{}]".format(','.join(parent_restrictions))

                self.assertTrue(plugin_restrictions_text in script)
                self.assertTrue(parent_restrictions_text in script)
开发者ID:janwilliams,项目名称:CMS,代码行数:57,代码来源:test_templatetags.py

示例2: render_tag

 def render_tag(self, context, name, strip, nodelist):
     rendered_contents = nodelist.render(context)
     if strip:
         rendered_contents = rendered_contents.strip()
     varname = get_varname()
     context[varname][name].append(rendered_contents)
     return ""
开发者ID:AL000,项目名称:django-sekizai,代码行数:7,代码来源:sekizai_tags.py

示例3: restore_sekizai_context

def restore_sekizai_context(context, changes):
    varname = get_varname()
    sekizai_container = context.get(varname)
    for key, values in changes.items():
        sekizai_namespace = sekizai_container[key]
        for value in values:
            sekizai_namespace.append(value)
开发者ID:Air-Mark,项目名称:django-cms,代码行数:7,代码来源:placeholder.py

示例4: render_plugin_toolbar_config

def render_plugin_toolbar_config(context, plugin):
    content_renderer = context['cms_content_renderer']

    instance, plugin_class = plugin.get_plugin_instance()

    if not instance:
        return ''

    with context.push():
        content = content_renderer.render_editable_plugin(
            instance,
            context,
            plugin_class,
        )
        # render_editable_plugin will populate the plugin
        # parents and children cache.
        placeholder_cache = content_renderer.get_rendered_plugins_cache(instance.placeholder)
        toolbar_js = get_plugin_toolbar_js(
            instance,
            request_language=content_renderer.request_language,
            children=placeholder_cache['plugin_children'][instance.plugin_type],
            parents=placeholder_cache['plugin_parents'][instance.plugin_type],
        )
        varname = get_varname()
        toolbar_js = '<script>{}</script>'.format(toolbar_js)
        # Add the toolbar javascript for this plugin to the
        # sekizai "js" namespace.
        context[varname]['js'].append(toolbar_js)
    return mark_safe(content)
开发者ID:evildmp,项目名称:django-cms,代码行数:29,代码来源:cms_admin.py

示例5: validate_context

def validate_context(context):
    """
    Validates a given context.

    Returns True if the context is valid.

    Returns False if the context is invalid but the error should be silently
    ignored.

    Raises a TemplateSyntaxError if the context is invalid and we're in debug
    mode.
    """
    try:
        template_debug = context.template.engine.debug
    except AttributeError:
        # Get the default engine debug value
        template_debug = template.Engine.get_default().debug

    if get_varname() in context:
        return True
    if not template_debug:
        return False
    raise template.TemplateSyntaxError(
        "You must enable the 'sekizai.context_processors.sekizai' template "
        "context processor or use 'sekizai.context.SekizaiContext' to "
        "render your templates."
    )
开发者ID:ojii,项目名称:django-sekizai,代码行数:27,代码来源:sekizai_tags.py

示例6: test_watcher_add_namespace

 def test_watcher_add_namespace(self):
     context = SekizaiContext()
     watcher = Watcher(context)
     varname = get_varname()
     context[varname]['key'].append('value')
     changes = watcher.get_changes()
     self.assertEqual(changes, {'key': ['value']})
开发者ID:AL000,项目名称:django-sekizai,代码行数:7,代码来源:tests.py

示例7: merge_sekizai_data

 def merge_sekizai_data(context, sub_context):
     """Utility function to call in post_render to merge the sekizai data in
     the component context into the global context."""
     varname = get_varname()
     for sub_block, sub_values in sub_context[varname].items():
         for item in sub_values:
             if item not in context[varname][sub_block]:
                 context[varname][sub_block].append(item)
开发者ID:SawdustSoftware,项目名称:django-components,代码行数:8,代码来源:component.py

示例8: render_tag

 def render_tag(self, context, image, ratio, nodelist):
     self.image = ResponsiveImage(image, ratio)
     varname = get_varname()
     count = context[varname].get('responsive-img-count', '1')
     try:
         count = int(count)
     except TypeError:
         count = 1
     self.remember(context, count)
     return self.html(image, ratio, count)
开发者ID:philippze,项目名称:django-responsive-image,代码行数:10,代码来源:responsive_image.py

示例9: remember

 def remember(self, context, count):
     #print (count)
     #print (count.__class__)
     name = 'css'
     varname = get_varname()
     context[varname]['responsive-img-count'] = '%s' % (count + 1)
     style_tag = self.style(300, count)
     context[varname][name].append(style_tag)
     if count == '1':
         context[varname][name].append('<style>%s</style>' % GLOBAL_STYLE)
开发者ID:philippze,项目名称:django-responsive-image,代码行数:10,代码来源:responsive_image.py

示例10: render_tag

 def render_tag(self, context, name, strip, preprocessor, nodelist):
     rendered_contents = nodelist.render(context)
     if strip:
         rendered_contents = rendered_contents.strip()
     if preprocessor:
         func = import_processor(preprocessor)
         rendered_contents = func(context, rendered_contents, name)
     varname = get_varname()
     context[varname][name].append(rendered_contents)
     return ""
开发者ID:click-ripple,项目名称:revolv,代码行数:10,代码来源:sekizai_tags.py

示例11: test_render_plugin_toolbar_config

    def test_render_plugin_toolbar_config(self):
        """
        Ensures that the render_plugin_toolbar_config tag
        sets the correct values in the sekizai context.
        """
        page = self._getfirst()
        placeholder = page.placeholders.get(slot='body')
        parent_plugin = add_plugin(placeholder, 'SolarSystemPlugin', 'en')
        child_plugin_1 = add_plugin(placeholder, 'PlanetPlugin', 'en', target=parent_plugin)
        child_plugin_2 = add_plugin(placeholder, 'PlanetPlugin', 'en', target=parent_plugin)

        parent_plugin.child_plugin_instances = [
            child_plugin_1,
            child_plugin_2,
        ]

        plugins = [
            parent_plugin,
            child_plugin_1,
            child_plugin_2,
        ]

        with self.login_user_context(self.get_superuser()):
            context = self.get_context(path=page.get_absolute_url(), page=page)
            context['request'].toolbar = CMSToolbar(context['request'])
            context['request'].toolbar.edit_mode = True
            context[get_varname()] = defaultdict(UniqueSequence)

            content_renderer = context['cms_content_renderer']

            output = content_renderer.render_plugin(
                instance=parent_plugin,
                context=context,
                placeholder=placeholder,
                editable=True
            )

            tag_format = '<template class="cms-plugin cms-plugin-start cms-plugin-{}">'

            for plugin in plugins:
                start_tag = tag_format.format(plugin.pk)
                self.assertIn(start_tag, output)
开发者ID:quanpower,项目名称:django-cms,代码行数:42,代码来源:test_templatetags.py

示例12: validate_context

def validate_context(context):
    """
    Validates a given context.
    
    Returns True if the context is valid.
    
    Returns False if the context is invalid but the error should be silently
    ignored.
    
    Raises a TemplateSyntaxError if the context is invalid and we're in debug
    mode.
    """
    if get_varname() in context:
        return True
    if not settings.TEMPLATE_DEBUG:
        return False
    raise template.TemplateSyntaxError(
        "You must enable the 'sekizai.context_processors.sekizai' template "
        "context processor or use 'sekizai.context.SekizaiContext' to "
        "render your templates."
    )
开发者ID:AL000,项目名称:django-sekizai,代码行数:21,代码来源:sekizai_tags.py

示例13: render_tag

    def render_tag(self, context, datafile):
        from sekizai.helpers import get_varname
        from cmsplugin_cascade.strides import StrideContentRenderer

        jsonfile = finders.find(datafile)
        if not jsonfile:
            raise IOError("Unable to find file: {}".format(datafile))

        with io.open(jsonfile) as fp:
            tree_data = json.load(fp)

        content_renderer = StrideContentRenderer(context['request'])
        with context.push(cms_content_renderer=content_renderer):
            content = content_renderer.render_cascade(context, tree_data)

        # some templates use Sekizai's templatetag `addtoblock` or `add_data`, which have to be re-added to the context
        cache = caches['default']
        if cache:
            varname = get_varname()
            SEKIZAI_CONTENT_HOLDER = cache.get_or_set(varname, context.get(varname))
            if SEKIZAI_CONTENT_HOLDER:
                for name in SEKIZAI_CONTENT_HOLDER:
                    context[varname][name] = SEKIZAI_CONTENT_HOLDER[name]
        return content
开发者ID:jrief,项目名称:djangocms-cascade,代码行数:24,代码来源:cascade_tags.py

示例14: sekizai_add_to_block

def sekizai_add_to_block(context, block, value):
    """Sekizai has no python API yet so gotta hack it."""
    context[get_varname()][block].append(value)
开发者ID:SawdustSoftware,项目名称:django-components,代码行数:3,代码来源:component.py

示例15: sekizai

def sekizai(request=None):
    """
    Simple context processor which makes sure that the SekizaiDictionary is
    available in all templates.
    """
    return {get_varname(): SekizaiDictionary()}
开发者ID:Mondego,项目名称:pyreco,代码行数:6,代码来源:allPythonContent.py


注:本文中的sekizai.helpers.get_varname函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。