python类BooleanField()的实例源码

params.py 文件源码 项目:django-openapi-gen 作者: Ecognize 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def typemap(self, p):
        mapping = {
            ParameterType.String : serializers.CharField,
            ParameterType.Number : serializers.FloatField,
            ParameterType.Integer : serializers.IntegerField,
            ParameterType.Boolean : serializers.BooleanField,
            ParameterType.Array : serializers.ListField,
            ParameterType.Enum : serializers.ChoiceField,
            ParameterType.File : serializers.FileField
        }

        return mapping.get(p, None)

    # TODO: properly handle array and enums
common.py 文件源码 项目:django-elasticsearch-dsl-drf 作者: barseghyanartur 项目源码 文件源码 阅读 111 收藏 0 点赞 0 评论 0
def get_value(self, dictionary):
        """Get value."""
        value = super(BooleanField, self).get_value(dictionary)
        return to_representation(value)
test_serializers.py 文件源码 项目:drf-friendly-errors 作者: FutureMind 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_boolean_field_error_content(self):
        self.data_set['linenos'] = 'A text instead of a bool'
        s = run_is_valid(SnippetSerializer, data=self.data_set)
        code = settings.FRIENDLY_FIELD_ERRORS['BooleanField']['invalid']
        self.assertEqual(s.errors['errors'][0]['code'], code)
        self.assertEqual(s.errors['errors'][0]['field'], 'linenos')
test_field_converter.py 文件源码 项目:graphene-django 作者: graphql-python 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_should_boolean_convert_boolean():
    assert_conversion(serializers.BooleanField, graphene.Boolean)
schemas.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def field_to_schema(field):
    title = force_text(field.label) if field.label else ''
    description = force_text(field.help_text) if field.help_text else ''

    if isinstance(field, serializers.ListSerializer):
        child_schema = field_to_schema(field.child)
        return coreschema.Array(
            items=child_schema,
            title=title,
            description=description
        )
    elif isinstance(field, serializers.Serializer):
        return coreschema.Object(
            properties=OrderedDict([
                (key, field_to_schema(value))
                for key, value
                in field.fields.items()
            ]),
            title=title,
            description=description
        )
    elif isinstance(field, serializers.ManyRelatedField):
        return coreschema.Array(
            items=coreschema.String(),
            title=title,
            description=description
        )
    elif isinstance(field, serializers.RelatedField):
        return coreschema.String(title=title, description=description)
    elif isinstance(field, serializers.MultipleChoiceField):
        return coreschema.Array(
            items=coreschema.Enum(enum=list(field.choices.keys())),
            title=title,
            description=description
        )
    elif isinstance(field, serializers.ChoiceField):
        return coreschema.Enum(
            enum=list(field.choices.keys()),
            title=title,
            description=description
        )
    elif isinstance(field, serializers.BooleanField):
        return coreschema.Boolean(title=title, description=description)
    elif isinstance(field, (serializers.DecimalField, serializers.FloatField)):
        return coreschema.Number(title=title, description=description)
    elif isinstance(field, serializers.IntegerField):
        return coreschema.Integer(title=title, description=description)

    if field.style.get('base_template') == 'textarea.html':
        return coreschema.String(
            title=title,
            description=description,
            format='textarea'
        )
    return coreschema.String(title=title, description=description)


问题


面经


文章

微信
公众号

扫码关注公众号