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


Python template.Variable方法代码示例

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


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

示例1: render

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def render(self, context):
        request = context["request"]
        post = getattr(request, "POST", None)
        form = template.Variable(self.value).resolve(context)
        t = get_template("forms/includes/built_form.html")
        context["form"] = form
        form_args = (form, context, post or None)
        form_for_form = FormForForm(*form_args)

        # kind of a hack
        # add the 'data-verify' attribute if the field is marked
        # as a verifiable field
        for i, field in enumerate(form_for_form.form_fields):
            if field.verify:
                form_for_form.fields[field.slug].widget.attrs['data-verify'] = True

            # We give to all the form fields a common class so we can reference 
            # them in the frontend
            fieldAttrs = form_for_form.fields[field.slug].widget.attrs
            fieldAttrs['class'] = fieldAttrs['class']  + ' form-field'

        context["form_for_form"] = form_for_form
        return t.render(context) 
开发者ID:crowdata,项目名称:crowdata,代码行数:25,代码来源:crowdataapp_tags.py

示例2: render

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def render(self, context):
        try:
            if '.' in self.field_var:
                base, field_name = self.field_var.rsplit('.', 1)
                field = getattr(Variable(base).resolve(context), field_name)
            else:
                field = context[self.field_var]
        except (template.VariableDoesNotExist, KeyError, AttributeError):
            return settings.TEMPLATE_STRING_IF_INVALID

        h_attrs = {}
        for k, v in iteritems(self.html_attrs):
            try:
                h_attrs[k] = v.resolve(context)
            except template.VariableDoesNotExist:
                h_attrs[k] = settings.TEMPLATE_STRING_IF_INVALID

        return field(**h_attrs) 
开发者ID:jpush,项目名称:jbox,代码行数:20,代码来源:wtforms.py

示例3: do_form_field

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def do_form_field(parser, token):
    """
    Render a WTForms form field allowing optional HTML attributes.
    Invocation looks like this:
      {% form_field form.username class="big_text" onclick="alert('hello')" %}
    where form.username is the path to the field value we want.  Any number
    of key="value" arguments are supported. Unquoted values are resolved as
    template variables.
    """
    parts = token.contents.split(' ', 2)
    if len(parts) < 2:
        error_text = '%r tag must have the form field name as the first value, followed by optional key="value" attributes.'
        raise template.TemplateSyntaxError(error_text % parts[0])

    html_attrs = {}
    if len(parts) == 3:
        raw_args = list(args_split(parts[2]))
        if (len(raw_args) % 2) != 0:
            raise template.TemplateSyntaxError('%r tag received the incorrect number of key=value arguments.' % parts[0])
        for x in range(0, len(raw_args), 2):
            html_attrs[str(raw_args[x])] = Variable(raw_args[x + 1])

    return FormFieldNode(parts[1], html_attrs) 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:wtforms.py

示例4: do_form_field

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def do_form_field(parser, token):
    """
    Render a WTForms form field allowing optional HTML attributes.
    Invocation looks like this:
      {% form_field form.username class="big_text" onclick="alert('hello')" %}
    where form.username is the path to the field value we want.  Any number 
    of key="value" arguments are supported. Unquoted values are resolved as
    template variables.
    """
    parts = token.contents.split(' ', 2)
    if len(parts) < 2:
        raise template.TemplateSyntaxError('%r tag must have the form field name as the first value, followed by optional key="value" attributes.' % parts[0])

    html_attrs = {}
    if len(parts) == 3:
        raw_args = list(args_split(parts[2]))
        if (len(raw_args) % 2) != 0:
            raise template.TemplateSyntaxError('%r tag received the incorrect number of key=value arguments.' % parts[0])
        for x in range(0, len(raw_args), 2):
            html_attrs[str(raw_args[x])] = Variable(raw_args[x+1])

    return FormFieldNode(parts[1], html_attrs) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:24,代码来源:wtforms.py

示例5: value_from_settings

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def value_from_settings(parser, token):
    bits = token.split_contents()
    if len(bits) < 2:
        raise TemplateSyntaxError("'%s' takes at least one " \
                                  "argument (settings constant to retrieve)" % bits[0])
    settingsvar = bits[1]
    settingsvar = settingsvar[1:-1] if settingsvar[0] == '"' else settingsvar
    asvar = None
    bits = bits[2:]
    if len(bits) >= 2 and bits[-2] == 'as':
        asvar = bits[-1]
        bits = bits[:-2]
    if len(bits):
        raise TemplateSyntaxError("'value_from_settings' didn't recognise " \
                                  "the arguments '%s'" % ", ".join(bits))
    if settingsvar not in settings.TEMPLATE_ALLOWABLE_SETTINGS_VALUES:
        raise TemplateSyntaxError("The settings Variable %s is not allowed to be acessed" % settingsvar)
    return ValueFromSettings(settingsvar, asvar) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:20,代码来源:settings_value.py

示例6: render

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def render(self, context):
        bounded_field = template.Variable(self.field).resolve(context)
        field = bounded_field.field.fields[self.index]
        widget = bounded_field.field.widget.widgets[self.index]

        attrs = widget.attrs.copy()
        print(attrs)
        for k, v in self.assign_dict.items():
            attrs[k] = v.resolve(context)
        for k, v in self.concat_dict.items():
            attrs[k] = widget.attrs.get(k, '') + ' ' + v.resolve(context)
        if bounded_field.errors:
            attrs['class'] = attrs.get('class', '') + ' error'

        if not bounded_field.form.is_bound:
            data = bounded_field.form.initial.get(bounded_field.name,
                                                  field.initial)
            if callable(data):
                data = data()
            data = bounded_field.field.widget.decompress(data)[self.index]
        else:
            data = bounded_field.data[self.index]
        return widget.render('%s_%d' % (bounded_field.html_name, self.index),
                             data, attrs) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:26,代码来源:widget_tweaks_extras.py

示例7: render

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

        # add all of the use_macros args into context
        for i, arg in enumerate(self.macro.args):
            try:
                template_variable = self.args[i]
                context[arg] = template_variable.resolve(context)
            except IndexError:
                context[arg] = ""

        # add all of use_macros kwargs into context
        for name, default in self.macro.kwargs.items():
            if name in self.kwargs:
                context[name] = self.kwargs[name].resolve(context)
            else:
                if isinstance(default, template.Variable):
                    # variables must be resolved explicitly,
                    # because otherwise if macro's loaded from
                    # a separate file things will break
                    context[name] = default.resolve(context)
                else:
                    context[name] = default

        # return the nodelist rendered in the adjusted context
        return self.macro.nodelist.render(context) 
开发者ID:nalourie,项目名称:django-macros,代码行数:27,代码来源:macros.py

示例8: __init__

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def __init__(self, field_str):
        self.field = template.Variable(field_str) 
开发者ID:dulacp,项目名称:django-accounting,代码行数:4,代码来源:form_tags.py

示例9: __init__

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def __init__(self, tag, page='request.GET.page'):
        self.tag = tag
        self.page = template.Variable(page) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:5,代码来源:donation_tags.py

示例10: render

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def render(self, context):
        sort = tryresolve(template.Variable('request.GET.sort'), context)
        order = tryresolve(template.Variable('request.GET.order'), context)
        if self.tag == 'pagefirst':
            return sortlink('first', '|< ', sort=sort, order=order, page=1)
        elif self.tag == 'pagelast':
            page = self.page.resolve(context)
            return sortlink('last', '>| ', sort=sort, order=order, page=page)
        elif self.tag == 'pagefull':
            return sortlink(None, 'View Full List', sort=sort, order=order, page='full') 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:12,代码来源:donation_tags.py

示例11: hash

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def hash(object, attr):
    pseudo_context = { 'object' : object }
    try:
        value = Variable('object.%s' % attr).resolve(pseudo_context)
    except VariableDoesNotExist:
        value = None
    return value 
开发者ID:sfu-fas,项目名称:coursys,代码行数:9,代码来源:course_display.py

示例12: __init__

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def __init__(self, dictionary, aslug, userid):
        self.dictionary = template.Variable(dictionary)
        self.aslug = template.Variable(aslug)
        self.userid = template.Variable(userid) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:6,代码来源:grade_student.py

示例13: __init__

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def __init__(self, handler, action, editor, person, varname):
        self.handler = template.Variable(handler)
        self.editor = template.Variable(editor)
        self.person = template.Variable(person)
        self.action = action
        self.varname = varname 
开发者ID:sfu-fas,项目名称:coursys,代码行数:8,代码来源:event_display.py

示例14: __init__

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def __init__(self, obj):
        self.obj = template.Variable(obj)
        #self.user = template.Variable('user') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:5,代码来源:sims_check.py

示例15: is_in_qs

# 需要导入模块: from django import template [as 别名]
# 或者: from django.template import Variable [as 别名]
def is_in_qs(context, key, value):
    req = template.Variable('request').resolve(context)
    return _is_in_qs(req.GET.copy(), key, value) 
开发者ID:ideascube,项目名称:ideascube,代码行数:5,代码来源:ideascube_tags.py


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