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


Python fields.empty方法代码示例

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


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

示例1: get_value

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def get_value(self, data):
        if isinstance(data, MultiValueDict):
            regex = re.compile(r"^%s\.(.*)$" % re.escape(self.field_name))
            ret = {}
            for name, value in data.items():
                match = regex.match(name)
                if not match:
                    continue
                key = match.groups()[0]
                if value != '':
                    ret[key] = value
        elif isinstance(data, dict):
            ret = data.get(self.field_name, fields.empty)
        else:
            raise ValidationError("not a dict: " + str(type(data)))

        if ret is fields.empty or len(ret) == 0:
            return fields.empty
        return ret 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:21,代码来源:fields.py

示例2: __init__

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def __init__(self, instance=None, data=empty, **kwargs):
        """Initialize attributes."""
        if (
            instance is not None
            and data is not empty
            and hasattr(self.Meta, "update_protected_fields")
        ):
            for field in self.Meta.update_protected_fields:
                if field in data:
                    data.pop(field)

            # prevent modification if there are no updates
            if set(data.keys()).issubset(set(self.Meta.read_only_fields)):
                raise NoContentError()

        super().__init__(instance, data, **kwargs) 
开发者ID:genialis,项目名称:resolwe,代码行数:18,代码来源:base.py

示例3: to_internal_value

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def to_internal_value(self, data):
        validated_data = super().to_internal_value(data)

        if self.partial:
            empty_fields = []
            restql_nested_fields = self.restql_source_field_map.keys()

            for field in restql_nested_fields:
                if field in validated_data and validated_data[field] == empty:
                    empty_fields.append(field)

            for field in empty_fields:
                # Ignore empty fields for partial update
                validated_data.pop(field)

        return validated_data 
开发者ID:yezyilomo,项目名称:django-restql,代码行数:18,代码来源:mixins.py

示例4: to_internal_value

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def to_internal_value(self, data):
        """
        Dicts of native values <- Dicts of primitive datatypes.
        """

        if html.is_html_input(data):
            data = html.parse_html_dict(data)
        if not isinstance(data, dict):
            self.fail('not_a_dict', input_type=type(data).__name__)
        if not self.allow_empty and len(data.keys()) == 0:
            message = self.error_messages['empty']
            raise ValidationError({
                api_settings.NON_FIELD_ERRORS_KEY: [message]
            })
        return {
            str(key): self.child.run_validation(value)
            for key, value in data.items()
        } 
开发者ID:umutbozkurt,项目名称:django-rest-framework-mongoengine,代码行数:20,代码来源:fields.py

示例5: run_validation

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def run_validation(self, data=empty):
        resource_type = self._get_resource_type_from_mapping(data)
        serializer = self._get_serializer_from_resource_type(resource_type)
        validated_data = serializer.run_validation(data)
        validated_data[self.resource_type_field_name] = resource_type
        return validated_data


    # --------------
    # Implementation 
开发者ID:apirobot,项目名称:django-rest-polymorphic,代码行数:12,代码来源:serializers.py

示例6: _get_default_value

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def _get_default_value(self):
        """
        :return: default value for field
        :rtype: any
        """
        default_value = getattr(self._field, 'default', None)

        if default_value == fields.empty:
            default_value = None

        if hasattr(default_value, '__call__'):
            default_value = default_value()

        return default_value 
开发者ID:Arello-Mobile,项目名称:py2swagger,代码行数:16,代码来源:field.py

示例7: parse_value

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def parse_value(self, querydict):
        """ extract value

        extarct value from querydict and convert it to native
        missing and empty values result to None
        """
        value = self.field.get_value(querydict)
        if value in (None, fields.empty, ''):
            return None
        return self.field.to_internal_value(value) 
开发者ID:qwiglydee,项目名称:drf-mongo-filters,代码行数:12,代码来源:filters.py

示例8: __init__

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def __init__(self, instance=None, data=empty, **kwargs):
        """Initialize attributes."""
        # Use the correct User model.
        if self.Meta.model is None:
            self.Meta.model = auth.get_user_model()

        super().__init__(instance, data, **kwargs) 
开发者ID:genialis,项目名称:resolwe,代码行数:9,代码来源:contributor.py

示例9: __init__

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def __init__(self, instance=None, data=empty, **kwargs):
        """Initialize the Provider Serializer.

        Here we ensure we use the appropriate serializer to validate the
        authentication and billing_source parameters.
        """
        super().__init__(instance, data, **kwargs)

        provider_type = None
        if data and data != empty:
            provider_type = data.get("type")

        if provider_type and provider_type.lower() not in LCASE_PROVIDER_CHOICE_LIST:
            key = "type"
            message = f"{provider_type} is not a valid source type."
            raise serializers.ValidationError(error_obj(key, message))

        if provider_type:
            provider_type = provider_type.lower()
            self.fields["authentication"] = AUTHENTICATION_SERIALIZERS.get(
                Provider.PROVIDER_CASE_MAPPING.get(provider_type)
            )()
            self.fields["billing_source"] = BILLING_SOURCE_SERIALIZERS.get(
                Provider.PROVIDER_CASE_MAPPING.get(provider_type)
            )(default={"bucket": "", "data_source": {"bucket": ""}})
        else:
            self.fields["authentication"] = ProviderAuthenticationSerializer()
            self.fields["billing_source"] = ProviderBillingSourceSerializer() 
开发者ID:project-koku,项目名称:koku,代码行数:30,代码来源:serializers.py

示例10: get_field_info

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def get_field_info(self, field):
        """Adds `related_to` and `nullable` to the metadata response."""
        field_info = OrderedDict()
        for attr in ('required', 'read_only', 'default', 'label'):
            field_info[attr] = getattr(field, attr)
        if field_info['default'] is empty:
            field_info['default'] = None
        if hasattr(field, 'immutable'):
            field_info['immutable'] = field.immutable
        field_info['nullable'] = field.allow_null
        if hasattr(field, 'choices'):
            field_info['choices'] = [
                {
                    'value': choice_value,
                    'display_name': force_text(choice_name, strings_only=True)
                }
                for choice_value, choice_name in field.choices.items()
            ]
        many = False
        if isinstance(field, DynamicRelationField):
            field = field.serializer
        if isinstance(field, ListSerializer):
            field = field.child
            many = True
        if isinstance(field, ModelSerializer):
            type = 'many' if many else 'one'
            field_info['related_to'] = field.get_plural_name()
        else:
            type = self.label_lookup[field]

        field_info['type'] = type
        return field_info 
开发者ID:AltSchool,项目名称:dynamic-rest,代码行数:34,代码来源:metadata.py

示例11: run_validation

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def run_validation(self, data=empty):
        data = super().run_validation(data)
        validate_password(data)
        return data 
开发者ID:CodeForPoznan,项目名称:volontulo,代码行数:6,代码来源:serializers.py

示例12: empty_none

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def empty_none(self, val):
    if(val == ""):
        return None
    return val

# def remove_empty_str(data):
#     for k, v in data.items():
#         if v == "":
#             data.pop(k)
# def serializer_init(self, instance=None, data=empty, **kwargs):
#     if data is not empty:
#         for k,v in data.items():
#             if(v==""):
#                 data.pop(k)
#     super(Serializer, self).__init__(instance, data, **kwargs) 
开发者ID:open-cmdb,项目名称:cmdb,代码行数:17,代码来源:initialize.py

示例13: __init__

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def __init__(self, instance=None, data=empty, **kwargs):
        # Init dicts for later purpose (see below)
        self.__implied_permissions = {}
        self.__contradictory_permissions = {}
        super().__init__(instance=instance, data=data, **kwargs)

        self.__asset_key = self.__get_key(Asset._meta.app_label,
                                          Asset._meta.model_name)
        self.__collection_key = self.__get_key(Collection._meta.app_label,
                                               Collection._meta.model_name)
        # Prepare dicts for later purpose
        # (i.e. `get_implied` & `get_contradictory`)
        self.__init_implied_permissions()
        self.__init_contradictory_permissions() 
开发者ID:kobotoolbox,项目名称:kpi,代码行数:16,代码来源:permission.py

示例14: repr_fields

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def repr_fields(self):
        return [field for field in self.fields.values()
                if (not field.read_only) or (field.default is not empty)] 
开发者ID:akaariai,项目名称:drf-fast-serializer,代码行数:5,代码来源:__init__.py

示例15: get_value

# 需要导入模块: from rest_framework import fields [as 别名]
# 或者: from rest_framework.fields import empty [as 别名]
def get_value(self, data):
        result = super(StrictManyRelatedField, self).get_value(data)
        if not result:
            raise serializers.ValidationError(
                {self.field_name: [self.error_messages['null']]}
            )
        if result != fields.empty and not isinstance(result, list):
            raise serializers.ValidationError({self.field_name: ['Expected a list.']})
        return result 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:11,代码来源:serializers.py


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