當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。