當前位置: 首頁>>代碼示例>>Python>>正文


Python compat.text_type方法代碼示例

本文整理匯總了Python中wtforms.compat.text_type方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.text_type方法的具體用法?Python compat.text_type怎麽用?Python compat.text_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wtforms.compat的用法示例。


在下文中一共展示了compat.text_type方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _value

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def _value(self):
        if self.raw_data:
            return self.raw_data[0]
        elif self.data is not None:
            if self.use_locale:
                return text_type(self._format_decimal(self.data))
            elif self.places is not None:
                if hasattr(self.data, 'quantize'):
                    exp = decimal.Decimal('.1') ** self.places
                    if self.rounding is None:
                        quantized = self.data.quantize(exp)
                    else:
                        quantized = self.data.quantize(exp, rounding=self.rounding)
                    return text_type(quantized)
                else:
                    # If for some reason, data is a float or int, then format
                    # as we would for floats using string formatting.
                    format = '%%0.%df' % self.places
                    return format % self.data
            else:
                return text_type(self.data)
        else:
            return '' 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:25,代碼來源:core.py

示例2: __call__

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def __call__(self, field, **kwargs):
        html = []
        if self.with_table_tag:
            kwargs.setdefault('id', field.id)
            html.append('<table %s>' % html_params(**kwargs))
        hidden = ''
        for subfield in field:
            if subfield.type in ('HiddenField', 'CSRFTokenField'):
                hidden += text_type(subfield)
            else:
                html.append('<tr><th>%s</th><td>%s%s</td></tr>' % (text_type(subfield.label), hidden, text_type(subfield)))
                hidden = ''
        if self.with_table_tag:
            html.append('</table>')
        if hidden:
            html.append(hidden)
        return HTMLString(''.join(html)) 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:19,代碼來源:core.py

示例3: _value

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def _value(self):
        if self.raw_data:
            return self.raw_data[0]
        elif self.data is not None:
            if self.places is not None:
                if hasattr(self.data, 'quantize'):
                    exp = decimal.Decimal('.1') ** self.places
                    if self.rounding is None:
                        quantized = self.data.quantize(exp)
                    else:
                        quantized = self.data.quantize(exp, rounding=self.rounding)
                    return text_type(quantized)
                else:
                    # If for some reason, data is a float or int, then format
                    # as we would for floats using string formatting.
                    format = '%%0.%df' % self.places
                    return format % self.data
            else:
                return text_type(self.data)
        else:
            return '' 
開發者ID:RoseOu,項目名稱:flasky,代碼行數:23,代碼來源:core.py

示例4: html_params

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def html_params(**kwargs):
    """
    Generate HTML parameters from inputted keyword arguments.

    The output value is sorted by the passed keys, to provide consistent output
    each time this function is called with the same parameters.  Because of the
    frequent use of the normally reserved keywords `class` and `for`, suffixing
    these with an underscore will allow them to be used.

    >>> html_params(name='text1', id='f', class_='text') == 'class="text" id="f" name="text1"'
    True
    """
    params = []
    for k,v in sorted(iteritems(kwargs)):
        if k in ('class_', 'class__', 'for_'):
            k = k[:-1]
        if v is True:
            params.append(k)
        else:
            params.append('%s="%s"' % (text_type(k), escape(text_type(v), quote=True)))
    return ' '.join(params) 
開發者ID:RoseOu,項目名稱:flasky,代碼行數:23,代碼來源:core.py

示例5: __call__

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def __call__(self, field, **kwargs):
        html = []
        if self.with_table_tag:
            kwargs.setdefault('id', field.id)
            html.append('<table %s>' % html_params(**kwargs))
        hidden = ''
        for subfield in field:
            if subfield.type == 'HiddenField':
                hidden += text_type(subfield)
            else:
                html.append('<tr><th>%s</th><td>%s%s</td></tr>' % (text_type(subfield.label), hidden, text_type(subfield)))
                hidden = ''
        if self.with_table_tag:
            html.append('</table>')
        if hidden:
            html.append(hidden)
        return HTMLString(''.join(html)) 
開發者ID:RoseOu,項目名稱:flasky,代碼行數:19,代碼來源:core.py

示例6: default_values_formatter

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def default_values_formatter(values):
        return ', '.join(text_type(x) for x in values) 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:4,代碼來源:validators.py

示例7: _get_object_list

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def _get_object_list(self):
        if self._object_list is None:
            query = self.query or self.query_factory()
            get_pk = self.get_pk
            self._object_list = list((text_type(get_pk(obj)), obj) for obj in query)
        return self._object_list 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:8,代碼來源:fields.py

示例8: get_pk_from_identity

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def get_pk_from_identity(obj):
    cls, key = identity_key(instance=obj)
    return ':'.join(text_type(x) for x in key) 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:5,代碼來源:fields.py

示例9: _value

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def _value(self):
        if self.raw_data:
            return self.raw_data[0]
        else:
            return self.data and text_type("\n".join(self.data)) or '' 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:7,代碼來源:fields.py

示例10: __init__

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def __init__(self, label=None, validators=None, coerce=text_type, choices=None, **kwargs):
        super(SelectField, self).__init__(label, validators, **kwargs)
        self.coerce = coerce
        self.choices = choices 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:6,代碼來源:core.py

示例11: html_params

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def html_params(**kwargs):
    """
    Generate HTML attribute syntax from inputted keyword arguments.

    The output value is sorted by the passed keys, to provide consistent output
    each time this function is called with the same parameters. Because of the
    frequent use of the normally reserved keywords `class` and `for`, suffixing
    these with an underscore will allow them to be used.

    In order to facilitate the use of ``data-`` attributes, the first underscore
    behind the ``data``-element is replaced with a hyphen.

    >>> html_params(data_any_attribute='something')
    'data-any_attribute="something"'

    In addition, the values ``True`` and ``False`` are special:
      * ``attr=True`` generates the HTML compact output of a boolean attribute,
        e.g. ``checked=True`` will generate simply ``checked``
      * ``attr=False`` will be ignored and generate no output.

    >>> html_params(name='text1', id='f', class_='text')
    'class="text" id="f" name="text1"'
    >>> html_params(checked=True, readonly=False, name="text1", abc="hello")
    'abc="hello" checked name="text1"'
    """
    params = []
    for k, v in sorted(iteritems(kwargs)):
        if k in ('class_', 'class__', 'for_'):
            k = k[:-1]
        elif k.startswith('data_'):
            k = k.replace('_', '-', 1)
        if v is True:
            params.append(k)
        elif v is False:
            pass
        else:
            params.append('%s="%s"' % (text_type(k), escape(text_type(v), quote=True)))
    return ' '.join(params) 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:40,代碼來源:core.py

示例12: render_option

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def render_option(cls, value, label, selected, **kwargs):
        if value is True:
            # Handle the special case of a 'True' value.
            value = text_type(value)

        options = dict(kwargs, value=value)
        if selected:
            options['selected'] = True
        return HTMLString('<option %s>%s</option>' % (html_params(**options), escape(text_type(label), quote=False))) 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:11,代碼來源:core.py

示例13: default_values_formatter

# 需要導入模塊: from wtforms import compat [as 別名]
# 或者: from wtforms.compat import text_type [as 別名]
def default_values_formatter(v):
        return ', '.join(text_type(x) for x in v) 
開發者ID:snverse,項目名稱:Sci-Finder,代碼行數:4,代碼來源:validators.py


注:本文中的wtforms.compat.text_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。