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


Python Context.update方法代码示例

本文整理汇总了Python中django.template.context.Context.update方法的典型用法代码示例。如果您正苦于以下问题:Python Context.update方法的具体用法?Python Context.update怎么用?Python Context.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.context.Context的用法示例。


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

示例1: render_globals

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
    def render_globals(self):
        print "!!"
        result = ""
        if self.template_globals:
            self.templates_list.insert(0, self.template_globals)

        default_dict = {"component": self, "window": self}
        context = Context(default_dict)

        for file_name in self.templates_list:
            if isinstance(file_name, (tuple, list)):
                file_context = Context(default_dict)
                file_context.update(file_name[1])
                file_name = file_name[0]
            else:
                file_context = context
            template = get_template(file_name)
            try:
                text = template.render(file_context)
            except Exception as err:
                # не надо молчать если есть проблемы
                raise ApplicationLogicException(
                    "Render error for template {} {}".format(file_name, get_exception_description(err))
                )

            # Комментарий для отладки
            remark = "\n//========== TEMPLATE: %s ==========\n" % file_name
            result += remark + text

        # Отмечает строку как безопасную (фильтр safe) для шаблонизатора
        return mark_safe(result)
开发者ID:sadykovildar,项目名称:bars_m3_blank,代码行数:33,代码来源:TemplateListRenderMixin.py

示例2: show_post

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def show_post(context, post):
    ''' shows an actual blog post '''
    ctx = {'post': post,
           'published_comment_count': post.published_comment_count()}
    ret = Context(context)
    ret.update(ctx)
    return ret
开发者ID:mdsn,项目名称:assorted-things,代码行数:9,代码来源:blog_extras.py

示例3: sphblog_showblogpost

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def sphblog_showblogpost(context, post):
    ret = {'post': post,
           'blogpost': post.blogpostextension_set.get(),
           }
    retctx = Context(context)
    retctx.update(ret)
    return retctx
开发者ID:ShaastraWebops,项目名称:Shaastra-2011-Website,代码行数:9,代码来源:sphblog_extras.py

示例4: submit_row

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def submit_row(context):
    """
    移除"保存后添加"按钮
    移除"保存继续编辑"按钮
    添加"保存为草稿"按钮
    """
    # ctx = original_submit_row(context)
    change = context['change']
    is_popup = context['is_popup']
    save_as = context['save_as']
    show_save = context.get('show_save', True)
    show_save_and_continue = context.get('show_save_and_continue', True)
    from django.template.context import Context

    ctx = Context(context)
    ctx.update({
        'show_delete_link': True,

        'show_save_as_new': not is_popup and change and save_as,
        'show_save_and_add_another': (
            context['has_add_permission'] and not is_popup and
            (not save_as or context['add'])
        ),
        'show_save_and_continue': not is_popup and context['has_change_permission'] and show_save_and_continue,
        'show_save': False,
        'show_save_as_draft': True,
    })
    # ctx.update({
    #     'show_save_and_add_another': False,
    #     'show_save_as_draft': True,
    #     'show_save_and_continue': False,
    # })
    print(ctx)
    return ctx
开发者ID:finderL,项目名称:django_blog,代码行数:36,代码来源:admin.py

示例5: submit_row

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def submit_row(context):
    """
    Display the row of buttons for delete and save.
    """
    add = context['add']
    change = context['change']
    is_popup = context['is_popup']
    save_as = context['save_as']
    show_save = context.get('show_save', True)
    show_save_and_continue = context.get('show_save_and_continue', True)
    has_add_permission = context['has_add_permission']
    has_change_permission = context['has_change_permission']
    has_view_permission = context['has_view_permission']
    has_editable_inline_admin_formsets = context['has_editable_inline_admin_formsets']
    can_save = (has_change_permission and change) or (has_add_permission and add) or has_editable_inline_admin_formsets
    can_save_and_continue = not is_popup and can_save and has_view_permission and show_save_and_continue
    can_change = has_change_permission or has_editable_inline_admin_formsets
    ctx = Context(context)
    ctx.update({
        'can_change': can_change,
        'show_delete_link': (
            not is_popup and context['has_delete_permission'] and
            change and context.get('show_delete', True)
        ),
        'show_save_as_new': not is_popup and has_change_permission and change and save_as,
        'show_save_and_add_another': (
            has_add_permission and not is_popup and
            (not save_as or add) and can_save
        ),
        'show_save_and_continue': can_save_and_continue,
        'show_save': show_save and can_save,
        'show_close': not(show_save and can_save)
    })
    return ctx
开发者ID:ArcTanSusan,项目名称:django,代码行数:36,代码来源:admin_modify.py

示例6: render

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
 def render(self, context, instance, placeholder):
     template_vars = {
         'placeholder': placeholder,
     }
     template_vars['object'] = instance
     # locate the plugins assigned to the given page for the indicated placeholder
     lang = None
     if context.has_key('request'):
         lang = context['request'].LANGUAGE_CODE
     else:
         lang = settings.LANGUAGE_CODE
     #print 'language CONTEXT FOR PLUGIN:', lang
     plugins = CMSPlugin.objects.filter(page=instance.parent_page, placeholder=placeholder, language=lang)
     plugin_output = []
     template_vars['parent_plugins'] = plugins 
     for plg in plugins:
         #print 'added a parent plugin:', plg, plg.__class__
         # use a temporary context to prevent plugins from overwriting context
         tmpctx = Context()
         tmpctx.update(template_vars)
         inst, name = plg.get_plugin_instance()
         #print 'got a plugin instance:', inst
         outstr = inst.render_plugin(tmpctx, placeholder)
         plugin_output.append(outstr)
         #print 'render result:', outstr
     template_vars['parent_output'] = plugin_output
     context.update(template_vars)
     return context
开发者ID:azdyb,项目名称:django-cms-inherit-plugin,代码行数:30,代码来源:cms_plugins.py

示例7: render_cell

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
    def render_cell(self, state, obj, render_context):
        """Renders the table cell containing column data."""
        datagrid = state.datagrid
        rendered_data = self.render_data(state, obj)
        url = ''
        css_class = ''

        if self.link:
            try:
                url = self.link_func(state, obj, rendered_data)
            except AttributeError:
                pass

        if self.css_class:
            if six.callable(self.css_class):
                css_class = self.css_class(obj)
            else:
                css_class = self.css_class

        key = "%s:%s:%s:%s" % (state.last, rendered_data, url, css_class)

        if key not in state.cell_render_cache:
            ctx = Context(render_context)
            ctx.update({
                'column': self,
                'column_state': state,
                'css_class': css_class,
                'url': url,
                'data': mark_safe(rendered_data)
            })

            state.cell_render_cache[key] = \
                mark_safe(datagrid.cell_template_obj.render(ctx))

        return state.cell_render_cache[key]
开发者ID:carloscorralesbitnami,项目名称:djblets,代码行数:37,代码来源:grids.py

示例8: render

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
 def render(self, context):
     form = FriendsSearchForm()
     ctx = Context()
     [ ctx.update(d) for d in context.dicts ]
     ctx.update({
         'friends_search_form' : form,
     })
     return render_to_string('friends/tags/search_form{0}.html'.format(self.postfix), ctx)
开发者ID:mshogin,项目名称:django-simple-friends,代码行数:10,代码来源:friends_tags.py

示例9: render

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
	def render(self, **kwargs):
		assert 'request' in kwargs
		template = getattr(self, 'render_template', getattr(self.get_content(), 'render_template', None) if hasattr(self, 'get_content') else None)
		if not template:
			raise NotImplementedError('No template defined for rendering %s content.' % self.__class__.__name__)
		context = Context({'content': self})
		if 'context' in kwargs:
			context.update(kwargs['context'])
		return render_to_string(template, context, context_instance=RequestContext(kwargs['request']))
开发者ID:ixc,项目名称:DEPRECATED_feincmstools,代码行数:11,代码来源:models.py

示例10: sphboard_displayCategories

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def sphboard_displayCategories(context, categories, maxDepth=5, level=-1):
    if maxDepth < level:
        return { }
    ret = {'categories': [c for c in categories if c.get_category_type().is_displayed()],
           'level': level + 1,
           'maxDepth': maxDepth}
    retctx = Context(context)
    retctx.update(ret)
    return retctx
开发者ID:pigletto,项目名称:sct-communitytools,代码行数:11,代码来源:sphboard_extras.py

示例11: __unicode__

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
 def __unicode__(self):
     if self.template_path:
         t = template.loader.get_template(self.template_path)
         ctxt = Context()
         ctxt['_tab'] = self
         ctxt['_widgets'] = self.widgets
         ctxt.update(self.widgets)
         return t.render(ctxt)
     else:
         return '\n'.join([w.__unicode__() for w in self.widgets.values()])
开发者ID:jergason,项目名称:topicalguide,代码行数:12,代码来源:common.py

示例12: sphboard_displayCategories

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def sphboard_displayCategories(context, categories, maxDepth=5, level=-1):
    if maxDepth < level:
        return {}
    ret = {
        "categories": [c for c in categories if c.get_category_type().is_displayed()],
        "level": level + 1,
        "maxDepth": maxDepth,
    }
    retctx = Context(context)
    retctx.update(ret)
    return retctx
开发者ID:sunilpatelmca,项目名称:dishnine,代码行数:13,代码来源:sphboard_extras.py

示例13: render

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
    def render(self, **kwargs):
        assert 'request' in kwargs

        template = self.render_template or self._find_render_template_path(self.region)
        if not template:
            raise NotImplementedError('No template found for rendering %s content. I tried ["%s"].' % (self.__class__.__name__, '", "'.join(self._render_template_paths(self.region))))
        context = Context()
        if 'context' in kwargs:
            context.update(kwargs['context'])
        context['content'] = self
        if hasattr(self, 'extra_context') and callable(self.extra_context):
            context.update(self.extra_context(kwargs['request']))
        return render_to_string(template, context, context_instance=RequestContext(kwargs['request']))
开发者ID:tttallis,项目名称:glamkit-feincmstools,代码行数:15,代码来源:base.py

示例14: render

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
def render(template_name, dictionary=None, context=None):
    if isinstance(template_name, (list, tuple)):
        template = select_template(template_name)
    else:
        template = get_template(template_name)

    dictionary = dictionary or {}
    if context is None:
        context = Context(dictionary)
    else:
        context.update(dictionary)
    data = {}
    [data.update(d) for d in context]
    return template.render(**data)
开发者ID:AshitakaLax,项目名称:SmartHome,代码行数:16,代码来源:mako_django.py

示例15: render_listview

# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import update [as 别名]
    def render_listview(self, render_context=None):
        """
        Renders the standard list view of the grid.

        This can be called from templates.
        """
        try:
            if render_context is None:
                render_context = self._build_render_context()

            self.load_state(render_context)
            
            if self.page.has_next():
                next_page_number = self.page.next_page_number()
            else:
                next_page_number = None
            
            if self.page.has_previous():
                previous_page_number = self.page.previous_page_number()
            else:
                previous_page_number = None

            context = Context({
                'datagrid': self,
                'is_paginated': self.page.has_other_pages(),
                'results_per_page': self.paginate_by,
                'has_next': self.page.has_next(),
                'has_previous': self.page.has_previous(),
                'page': self.page.number,
                'next': next_page_number,
                'previous': previous_page_number,
                'last_on_page': self.page.end_index(),
                'first_on_page': self.page.start_index(),
                'pages': self.paginator.num_pages,
                'hits': self.paginator.count,
                'page_range': self.paginator.page_range,
            })
            context.update(self.extra_context)
            context.update(render_context)

            return mark_safe(render_to_string(self.listview_template,
                                              context))
        except Exception:
            trace = traceback.format_exc();
            logging.error('Failed to render datagrid:\n%s' % trace,
                          extra={
                              'request': self.request,
                          })
            return mark_safe('<pre>%s</pre>' % trace)
开发者ID:leliocampanile,项目名称:djblets,代码行数:51,代码来源:grids.py


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