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


Python template.Node方法代码示例

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


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

示例1: handle_token

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def handle_token(cls, parser, token):
        """
        Class method to parse prefix node and return a Node.
        """
        bits = token.split_contents()

        if len(bits) < 2:
            raise template.TemplateSyntaxError(
                "'%s' takes at least one argument (path to file)" % bits[0])

        path = parser.compile_filter(bits[1])

        if len(bits) >= 2 and bits[-2] == 'as':
            varname = bits[3]
        else:
            varname = None

        return cls(varname, path) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:static.py

示例2: context_tag

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def context_tag(self, func):
        params, xx, xxx, defaults = getargspec(func)

        class ContextNode(django_template.Node):
            def __init__(self, vars_to_resolve):
                self.vars_to_resolve = map(django_template.Variable, vars_to_resolve)

            def render(self, context):
                resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]
                return func(context, *resolved_vars)

        compile_func = curry(django_template.generic_tag_compiler,
                             params[1:],
                             defaults[1:] if defaults else None,
                             getattr(func, "_decorated_function", func).__name__,
                             ContextNode)

        compile_func.__doc__ = func.__doc__

        self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
        return func 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:23,代码来源:template.py

示例3: __repr__

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def __repr__(self):
        return "<GetAdminLog Node>" 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:4,代码来源:log.py

示例4: verbatim

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def verbatim(parser, token):
    if django.VERSION >= (1, 5):
        from django.template.defaulttags import verbatim as verbatim_defaulttag
        return verbatim_defaulttag(parser, token)

    # 1.4; not available from django
    # Source: https://github.com/aljosa/django-verbatim
    class VerbatimNode(template.Node):
        def __init__(self, content):
            self.content = content

        def render(self, context):
            return self.content

    text = []
    while 1:
        token = parser.tokens.pop(0)
        if token.contents == 'endverbatim':
            break
        if token.token_type == template.TOKEN_VAR:
            text.append('{{ ')
        elif token.token_type == template.TOKEN_BLOCK:
            text.append('{% ')
        text.append(token.contents)
        if token.token_type == template.TOKEN_VAR:
            text.append(' }}')
        elif token.token_type == template.TOKEN_BLOCK:
            text.append(' %}')
    return VerbatimNode(''.join(text)) 
开发者ID:arteria,项目名称:django-compat,代码行数:31,代码来源:compat.py

示例5: render_markdown_instead_of_escaping

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def render_markdown_instead_of_escaping(parser, token):
	class Node(template.Node):
		def __init__(self, variable_name):
			self.variable = template.Variable(variable_name)
		def render(self, context):
			md = self.variable.resolve(context)
			if not context.autoescape:
				# Auto-escaping is off, so we're in the text portion
				# of a notification email. Return the raw markdown.
				return md
			else:
				# Auto-escaping is on, so we're in the HTML portion
				# of a notification email. Rather than returning the
				# raw Markdown, which will look funny because e.g.
				# line breaks will be ignored when it is placed within
				# HTML, render the Markdown to HTML. Turn on safe mode
				# since the content can't be trusted.
				import commonmark
				return commonmark.HtmlRenderer({ "safe": True })\
					.render(commonmark.Parser().parse(md))
	try:
		tag_name, variable_name = token.split_contents()
	except ValueError:
		raise template.TemplateSyntaxError(
			"%r tag requires a single argument naming a variable" % token.contents.split()[0]
		)
	return Node(variable_name) 
开发者ID:GovReady,项目名称:govready-q,代码行数:29,代码来源:notification_helpers.py

示例6: render

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def render(self, context):
        resolved_options = template.Variable(self.options).resolve(context)

        try:
            if self.gizmo_name is None or self.gizmo_name not in GIZMO_NAME_MAP:
                if hasattr(resolved_options, GIZMO_NAME_PROPERTY):
                    self._load_gizmo_name(resolved_options.gizmo_name)
                else:
                    raise TemplateSyntaxError('A valid gizmo name is required for this input format.')

            self._load_gizmos_rendered(context)

            # Derive path to gizmo template
            if self.gizmo_name not in EXTENSION_PATH_MAP:
                # Determine path to gizmo template
                gizmo_templates_root = os.path.join('tethys_gizmos', 'gizmos')

            else:
                gizmo_templates_root = os.path.join(EXTENSION_PATH_MAP[self.gizmo_name], 'templates', 'gizmos')

            gizmo_file_name = '{0}.html'.format(self.gizmo_name)
            template_name = os.path.join(gizmo_templates_root, gizmo_file_name)

            # reset gizmo_name in case Node is rendered with different options
            self._load_gizmo_name(None)

            # Retrieve the gizmo template and render
            t = get_template(template_name)
            return t.render(resolved_options)

        except Exception:
            if hasattr(settings, 'TEMPLATES'):
                for template_settings in settings.TEMPLATES:
                    if 'OPTIONS' in template_settings \
                            and 'debug' in template_settings['OPTIONS'] \
                            and template_settings['OPTIONS']['debug']:
                        raise
            return '' 
开发者ID:tethysplatform,项目名称:tethys,代码行数:40,代码来源:tethys_gizmos.py

示例7: execute

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Node [as 别名]
def execute(self, sql, params=()):
        start = datetime.now()
        try:
            return self.cursor.execute(sql, params)
        finally:
            stop = datetime.now()
            duration = ms_from_timedelta(stop - start)
            stacktrace = tidy_stacktrace(traceback.extract_stack())
            _params = ''
            try:
                _params = simplejson.dumps([force_unicode(x, strings_only=True) for x in params])
            except TypeError:
                pass # object not JSON serializable

            template_info = None
            cur_frame = sys._getframe().f_back
            try:
                while cur_frame is not None:
                    if cur_frame.f_code.co_name == 'render':
                        node = cur_frame.f_locals['self']
                        if isinstance(node, Node):
                            template_info = get_template_info(node.source)
                            break
                    cur_frame = cur_frame.f_back
            except:
                pass
            del cur_frame

            # We keep `sql` to maintain backwards compatibility
            self.db.queries.append({
                'sql': self.db.ops.last_executed_query(self.cursor, sql, params),
                'duration': duration,
                'raw_sql': sql,
                'params': _params,
                'hash': sha_constructor(settings.SECRET_KEY + sql + _params).hexdigest(),
                'stacktrace': stacktrace,
                'start_time': start,
                'stop_time': stop,
                'is_slow': (duration > SQL_WARNING_THRESHOLD),
                'is_select': sql.lower().strip().startswith('select'),
                'template_info': template_info,
            }) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:44,代码来源:sql.py


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