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