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


Python compat.iteritems函数代码示例

本文整理汇总了Python中wtforms.compat.iteritems函数的典型用法代码示例。如果您正苦于以下问题:Python iteritems函数的具体用法?Python iteritems怎么用?Python iteritems使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __init__

    def __init__(self, formdata=None, obj=None, prefix='', **kwargs):
        """
        :param formdata:
            Used to pass data coming from the enduser, usually `request.POST` or
            equivalent. formdata should be some sort of request-data wrapper which
            can get multiple parameters from the form input, and values are unicode
            strings, e.g. a Werkzeug/Django/WebOb MultiDict
        :param obj:
            If `formdata` is empty or not provided, this object is checked for
            attributes matching form field names, which will be used for field
            values.
        :param prefix:
            If provided, all fields will have their name prefixed with the
            value.
        :param `**kwargs`:
            If `formdata` is empty or not provided and `obj` does not contain
            an attribute named the same as a field, form will assign the value
            of a matching keyword argument to the field, if one exists.
        """
        super(Form, self).__init__(self._unbound_fields, prefix=prefix)

        for name, field in iteritems(self._fields):
            # Set all the fields to attributes so that they obscure the class
            # attributes with the same names.
            setattr(self, name, field)

        self.process(formdata, obj, **kwargs)
开发者ID:7kfpun,项目名称:com.getmewrite,代码行数:27,代码来源:form.py

示例2: html_params

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 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]
        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:Razin-Tailor,项目名称:ChatterBot,代码行数:30,代码来源:core.py

示例3: html_params

def html_params(**kwargs):
    """
    This is Verbatim from WTForms BUT "aria_" is handled like "data_"

    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_') or k.startswith('aria_') :
            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:MM1nd,项目名称:wtfoundation,代码行数:35,代码来源:widgets.py

示例4: process

    def process(self, formdata=None, obj=None, **kwargs):
        """
        Take form, object data, and keyword arg input and have the fields
        process them.

        :param formdata:
            Used to pass data coming from the enduser, usually `request.POST` or
            equivalent.
        :param obj:
            If `formdata` is empty or not provided, this object is checked for
            attributes matching form field names, which will be used for field
            values.
        :param `**kwargs`:
            If `formdata` is empty or not provided and `obj` does not contain
            an attribute named the same as a field, form will assign the value
            of a matching keyword argument to the field, if one exists.
        """
        if formdata is not None and not hasattr(formdata, 'getlist'):
            if hasattr(formdata, 'getall'):
                formdata = WebobInputWrapper(formdata)
            else:
                raise TypeError("formdata should be a multidict-type wrapper that supports the 'getlist' method")

        for name, field, in iteritems(self._fields):
            if obj is not None and hasattr(obj, name):
                field.process(formdata, getattr(obj, name))
            elif name in kwargs:
                field.process(formdata, kwargs[name])
            else:
                field.process(formdata)
开发者ID:7kfpun,项目名称:com.getmewrite,代码行数:30,代码来源:form.py

示例5: validate

    def validate(self, filter=[], extra_validators=None, isParent=False):

        if isParent:
            return super(Form, self).validate()

        self._errors = None
        success = True
        if callable(getattr(self, "_validate", None)):
            _fields = self._validate()
        else:
            _fields = self._fields
        for name, field in iteritems(_fields):
            if name in filter or field in filter:
                continue

            if extra_validators is not None and name in extra_validators:
                extra = extra_validators[name]
            else:
                extra = list()
            inline = getattr(self.__class__, 'validate_%s' % name, None)

            if inline is not None:
                extra.append(inline)

            if not field.validate(self, extra):
                success = False
        return success
开发者ID:main1015,项目名称:co-work,代码行数:27,代码来源:__init__.py

示例6: process

    def process(self, formdata=None, obj=None, data=None, **kwargs):
        """
        Take form, object data, and keyword arg input and have the fields
        process them.

        :param formdata:
            Used to pass data coming from the enduser, usually `request.POST` or
            equivalent.
        :param obj:
            If `formdata` is empty or not provided, this object is checked for
            attributes matching form field names, which will be used for field
            values.
        :param data:
            If provided, must be a dictionary of data. This is only used if
            `formdata` is empty or not provided and `obj` does not contain
            an attribute named the same as the field.
        :param `**kwargs`:
            If `formdata` is empty or not provided and `obj` does not contain
            an attribute named the same as a field, form will assign the value
            of a matching keyword argument to the field, if one exists.
        """
        formdata = self.meta.wrap_formdata(self, formdata)

        if data is not None:
            # XXX we want to eventually process 'data' as a new entity.
            #     Temporarily, this can simply be merged with kwargs.
            kwargs = dict(data, **kwargs)

        for name, field in iteritems(self._fields):
            if obj is not None and hasattr(obj, name):
                field.process(formdata, getattr(obj, name))
            elif name in kwargs:
                field.process(formdata, kwargs[name])
            else:
                field.process(formdata)
开发者ID:Razin-Tailor,项目名称:ChatterBot,代码行数:35,代码来源:form.py

示例7: __init__

    def __init__(self, formdata=None, obj=None, prefix="", data=None, meta=None, **kwargs):
        """
        :param formdata:
            Used to pass data coming from the enduser, usually `request.POST` or
            equivalent. formdata should be some sort of request-data wrapper which
            can get multiple parameters from the form input, and values are unicode
            strings, e.g. a Werkzeug/Django/WebOb MultiDict
        :param obj:
            If `formdata` is empty or not provided, this object is checked for
            attributes matching form field names, which will be used for field
            values.
        :param prefix:
            If provided, all fields will have their name prefixed with the
            value.
        :param data:
            Accept a dictionary of data. This is only used if `formdata` and
            `obj` are not present.
        :param meta:
            If provided, this is a dictionary of values to override attributes
            on this form's meta instance.
        :param `**kwargs`:
            If `formdata` is empty or not provided and `obj` does not contain
            an attribute named the same as a field, form will assign the value
            of a matching keyword argument to the field, if one exists.
        """
        meta_obj = self._wtforms_meta()
        if meta is not None and isinstance(meta, dict):
            meta_obj.update_values(meta)
        super(Form, self).__init__(self._unbound_fields, meta=meta_obj, prefix=prefix)

        for name, field in iteritems(self._fields):
            # Set all the fields to attributes so that they obscure the class
            # attributes with the same names.
            setattr(self, name, field)
        self.process(formdata, obj, data=data, **kwargs)
开发者ID:Razin-Tailor,项目名称:ChatterBot,代码行数:35,代码来源:form.py

示例8: __init__

    def __init__(self, formdata=None, obj=None, prefix="", **kwargs):
        """
        :param formdata:
            Used to pass data coming from the enduser, usually `request.POST` or
            equivalent.
        :param obj:
            If `formdata` is empty or not provided, this object is checked for
            attributes matching form field names, which will be used for field
            values.
        :param prefix:
            If provided, all fields will have their name prefixed with the
            value.
        :param `**kwargs`:
            If `formdata` is empty or not provided and `obj` does not contain
            an attribute named the same as a field, form will assign the value
            of a matching keyword argument to the field, if one exists.
        """
        super(Form, self).__init__(self._unbound_fields, prefix=prefix)

        for name, field in iteritems(self._fields):
            # Set all the fields to attributes so that they obscure the class
            # attributes with the same names.
            setattr(self, name, field)

        self.process(formdata, obj, **kwargs)
开发者ID:joshainglis,项目名称:sa-tools,代码行数:25,代码来源:form.py

示例9: process

    def process(self, formdata=None, obj=None, data=None, **kwargs):
        """
        Overrides wtforms.form.py BaseForm.process.
        Since we're going to load form fields from repeating fields in the object,
        We have to play games with the field names.
        """
        formdata = self.meta.wrap_formdata(self, formdata)

        if data is not None:
            # XXX we want to eventually process 'data' as a new entity.
            #     Temporarily, this can simply be merged with kwargs.
            kwargs = dict(data, **kwargs)

        for name, field, in iteritems(self._fields):
            processed_from_obj = False
            if obj is not None:
                m = re.search(r'^(.+)_([0-6])$', name)
                if m:
                    attr_name = m.group(1)
                    index = int(m.group(2))
                    day_prefs_obj = obj.days[index]
                    if hasattr(day_prefs_obj, attr_name):
                        field.process(formdata, getattr(day_prefs_obj, attr_name))
                        processed_from_obj = True
            if not processed_from_obj:
                if name in kwargs:
                    field.process(formdata, kwargs[name])
                else:
                    field.process(formdata) 
开发者ID:ksdtech,项目名称:gafe-conferences,代码行数:29,代码来源:forms.py

示例10: patch_data

    def patch_data(self):
        data = {}

        for name, f in iteritems(self._fields):
            if f.raw_data and (f.data != f.object_data):
                data[name] = f.data

        return data
开发者ID:coyotevz,项目名称:nbs,代码行数:8,代码来源:forms.py

示例11: populate_obj

    def populate_obj(self, obj):
        for name, field in iteritems(self._fields):
            if not name.startswith('comment_service'):
                field.populate_obj(obj, name)

        csn = self._fields['comment_service_name']
        csi = self._fields['comment_service_id']
        if csn and csi:
            obj.comment_service = '%s-%s' % (csn.data, csi.data)
开发者ID:cnhans,项目名称:yuan,代码行数:9,代码来源:account.py

示例12: populate_obj

    def populate_obj(self, obj):
        """
        Populates the attributes of the passed `obj` with data from the form's
        fields.

        :note: This is a destructive operation; Any attribute with the same name
               as a field will be overridden. Use with caution.
        """
        for name, field in iteritems(self._fields):
            field.populate_obj(obj, name)
开发者ID:Razin-Tailor,项目名称:ChatterBot,代码行数:10,代码来源:form.py

示例13: __init__

    def __init__(self, extra_converters=None, simple_conversions=None):
        converters = {}
        if simple_conversions is None:
            simple_conversions = self.DEFAULT_SIMPLE_CONVERSIONS
        for field_type, django_fields in iteritems(simple_conversions):
            converter = self.make_simple_converter(field_type)
            for name in django_fields:
                converters[name] = converter

        if extra_converters:
            converters.update(extra_converters)
        super(ModelConverter, self).__init__(converters)
开发者ID:sherrycherish,项目名称:qiubai,代码行数:12,代码来源:orm.py

示例14: populate_obj

    def populate_obj(self, obj):
        """
        Populate form to object.

        Since Form's default `populate_obj` function populate all
        the fields in this class, this function will do the same
        function except `emails` field.

        :param obj: Job Model object.
        """
        for name, field in iteritems(self._fields):
            if name not in ['query_time_out', 'emails', 'schedules']:
                field.populate_obj(obj, name)
开发者ID:scattm,项目名称:DanceCat,代码行数:13,代码来源:Forms.py

示例15: populate_obj

 def populate_obj(self, obj):
     """
     Overrides wtforms.form.py BaseForm.process.
     Since we're going to populate to repeating fields in the object,
     We have to play games with the field names.
     """
     for name, field in iteritems(self._fields):
         m = re.search(r'^(.+)_([0-6])$', name)
         if m:
             attr_name = m.group(1)
             index = int(m.group(2))
             day_prefs_obj = obj.days[index]
             field.populate_obj(day_prefs_obj, attr_name)
开发者ID:ksdtech,项目名称:gafe-conferences,代码行数:13,代码来源:forms.py


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