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


Python base.FilterExpression方法代码示例

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


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

示例1: render

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def render(self, context):

        for i, arg in enumerate(self.macro.args):
            try:
                fe = self.fe_args[i]
                context[arg] = fe.resolve(context)
            except IndexError:
                context[arg] = ""

        for name, default in iter(self.macro.kwargs.items()):
            if name in self.fe_kwargs:
                context[name] = self.fe_kwargs[name].resolve(context)
            else:
                context[name] = FilterExpression(default,
                                                 self.macro.parser
                                                 ).resolve(context)

        return self.macro.nodelist.render(context) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:20,代码来源:filters.py

示例2: render

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def render(self, context):
        resolve = lambda arg: arg.resolve(context) if isinstance(arg, FilterExpression) else arg

        prefs_obj = resolve(self.prefs_obj)
        if not isinstance(prefs_obj, tuple):
            if settings.DEBUG:
                raise SiteMessageConfigurationError(
                    '`sitemessage_prefs_table` template tag expects a tuple generated '
                    'by `get_user_preferences_for_ui` but `%s` is given.' % type(prefs_obj))
            return ''  # Silent fall.

        context.push()
        context['sitemessage_user_prefs'] = prefs_obj
        contents = get_template(
            resolve(self.use_template or 'sitemessage/user_prefs_table.html')
        ).render(context.flatten() if _CONTEXT_FLATTEN else context)
        context.pop()

        return contents 
开发者ID:idlesign,项目名称:django-sitemessage,代码行数:21,代码来源:sitemessage.py

示例3: render

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def render(self, context):

        for i, arg in enumerate(self.macro.args):
            try:
                fe = self.fe_args[i]
                context[arg] = fe.resolve(context)
            except IndexError:
                context[arg] = ""

        for name, default in self.macro.kwargs.items():
            if name in self.fe_kwargs:
                context[name] = self.fe_kwargs[name].resolve(context)
            else:
                context[name] = FilterExpression(default,
                                                 self.macro.parser
                                                 ).resolve(context)

        # Place output into context variable
        context[self.macro.name] = self.macro.nodelist.render(context)
        return '' if self.context_only else context[self.macro.name] 
开发者ID:twidi,项目名称:django-templates-macros,代码行数:22,代码来源:macros.py

示例4: do_usemacro

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def do_usemacro(parser, token):
    try:
        args = token.split_contents()
        tag_name, macro_name, values = args[0], args[1], args[2:]
    except IndexError:
        m = ("'%s' tag requires at least one argument (macro name)"
             % token.contents.split()[0])
        raise template.TemplateSyntaxError(m)
    try:
        macro = parser._macros[macro_name]
    except (AttributeError, KeyError):
        m = "Macro '%s' is not defined" % macro_name
        raise template.TemplateSyntaxError(m)

    fe_kwargs = {}
    fe_args = []

    for val in values:
        if "=" in val:
            # kwarg
            name, value = val.split("=")
            fe_kwargs[name] = FilterExpression(value, parser)
        else:  # arg
            # no validation, go for it ...
            fe_args.append(FilterExpression(val, parser))

    macro.parser = parser
    return UseMacroNode(macro, fe_args, fe_kwargs) 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:30,代码来源:filters.py

示例5: parse_tag

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def parse_tag(token, parser):
    """Parses template tag for name, arguments and keyword arguments.

    :param token: Template token containing all the tag contents
    :type token: django.template.base.Token
    :param parser: Template parser
    :type parser: django.template.base.Parser
    :return: Tuple with tag name, arguments and keyword arguments
    :rtype: tuple

    """
    # Split the tag content into words, respecting quoted strings.
    bits = token.split_contents()

    # Pull out the tag name.
    tag_name = bits.pop(0)

    # Parse the rest of the args, and build FilterExpressions from them so that
    # we can evaluate them later.
    args = []
    kwargs = {}
    for bit in bits:
        # Is this a kwarg or an arg?
        match = kwarg_re.match(bit)
        kwarg_format = match and match.group(1)
        if kwarg_format:
            key, value = match.groups()
            kwargs[key] = FilterExpression(value, parser)
        else:
            args.append(FilterExpression(bit, parser))

    return (tag_name, args, kwargs) 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:34,代码来源:utils.py

示例6: parse_usemacro

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def parse_usemacro(parser, token):
    try:
        args = token.split_contents()
        tag_name, macro_name, values = args[0], args[1], args[2:]
    except IndexError:
        m = ("'%s' tag requires at least one argument (macro name)"
             % token.contents.split()[0])
        raise template.TemplateSyntaxError(m)

    try:
        macro = parser._macros[macro_name]
    except (AttributeError, KeyError):
        m = "Macro '%s' is not defined" % macro_name
        raise template.TemplateSyntaxError(m)

    fe_kwargs = {}
    fe_args = []

    for val in values:
        if "=" in val:
            # kwarg
            name, value = val.split("=")
            fe_kwargs[name] = FilterExpression(value, parser)
        else:  # arg
            # no validation, go for it ...
            fe_args.append(FilterExpression(val, parser))

    macro.name = macro_name
    macro.parser = parser
    return macro, fe_args, fe_kwargs 
开发者ID:twidi,项目名称:django-templates-macros,代码行数:32,代码来源:macros.py

示例7: parse_usemacro

# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import FilterExpression [as 别名]
def parse_usemacro(parser, token):
    try:
        args = token.split_contents()
        macro_name, values = args[1], args[2:]
    except IndexError:
        m = ("'%s' tag requires at least one argument (macro name)"
             % token.contents.split()[0])
        raise template.TemplateSyntaxError(m)

    try:
        macro = parser._macros[macro_name]
    except (AttributeError, KeyError):
        m = "Macro '%s' is not defined" % macro_name
        raise template.TemplateSyntaxError(m)

    fe_kwargs = {}
    fe_args = []

    for val in values:
        if "=" in val:
            # kwarg
            name, value = val.split("=")
            fe_kwargs[name] = FilterExpression(value, parser)
        else:  # arg
            # no validation, go for it ...
            fe_args.append(FilterExpression(val, parser))

    macro.name = macro_name
    macro.parser = parser
    return macro, fe_args, fe_kwargs 
开发者ID:springload,项目名称:madewithwagtail,代码行数:32,代码来源:macros.py


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