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


Python utils.yank_fields_from_attrs方法代码示例

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

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

示例1: rescan_fields

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def rescan_fields(cls):
        """Attempts to rescan fields and will insert any not converted initially"""

        converted_fields, self_referenced = construct_fields(
            cls._meta.model,
            cls._meta.registry,
            cls._meta.only_fields,
            cls._meta.exclude_fields,
        )

        mongoengine_fields = yank_fields_from_attrs(
            converted_fields, _as=graphene.Field
        )

        # The initial scan should take precedence
        for field in mongoengine_fields:
            if field not in cls._meta.fields:
                cls._meta.fields.update({field: mongoengine_fields[field]})
        # Self-referenced fields can't change between scans! 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:21,代码来源:types.py


示例2: __init_subclass_with_meta__

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def __init_subclass_with_meta__(
        cls, form_class=None, only_fields=(), exclude_fields=(), **options
    ):

        if not form_class:
            raise Exception("form_class is required for DjangoFormMutation")

        form = form_class()
        input_fields = fields_for_form(form, only_fields, exclude_fields)
        output_fields = fields_for_form(form, only_fields, exclude_fields)

        _meta = DjangoFormMutationOptions(cls)
        _meta.form_class = form_class
        _meta.fields = yank_fields_from_attrs(output_fields, _as=Field)

        input_fields = yank_fields_from_attrs(input_fields, _as=InputField)
        super(DjangoFormMutation, cls).__init_subclass_with_meta__(
            _meta=_meta, input_fields=input_fields, **options
        ) 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:21,代码来源:mutation.py


示例3: _get_input_attrs

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def _get_input_attrs(object_type):
    new = {}

    for attr, value in object_type.__dict__.items():
        if not isinstance(value, (MountedType, UnmountedType)):
            continue

        if isinstance(value, Structure) and issubclass(value.of_type, graphene.ObjectType):
            value = type(value)(_input_registry[value.of_type])
        elif isinstance(value, graphene.ObjectType):
            value = _input_registry[value.of_type]

        new[attr] = value

    return yank_fields_from_attrs(new, _as=graphene.InputField) 
开发者ID:0soft,项目名称:graphene-django-plus,代码行数:17,代码来源:utils.py


示例4: __init_subclass_with_meta__

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def __init_subclass_with_meta__(cls, model=None,
                                    object_permissions=None,
                                    object_permissions_any=True,
                                    return_field_name=None,
                                    required_fields=None,
                                    exclude_fields=None, only_fields=None,
                                    _meta=None, **kwargs):
        if not model:  # pragma: no cover
            raise ImproperlyConfigured("model is required for ModelMutation")
        if not _meta:
            _meta = ModelMutationOptions(cls)

        exclude_fields = exclude_fields or []
        only_fields = only_fields or []
        if not return_field_name:
            return_field_name = _get_model_name(model)

        input_fields = _get_fields(model, only_fields, exclude_fields,
                                   required_fields)
        input_fields = yank_fields_from_attrs(input_fields, _as=graphene.InputField)

        fields = _get_output_fields(model, return_field_name)

        _meta.model = model
        _meta.object_permissions = object_permissions or []
        _meta.object_permissions_any = object_permissions_any
        _meta.return_field_name = return_field_name
        _meta.exclude_fields = exclude_fields
        _meta.only_fields = only_fields
        _meta.required_fields = required_fields

        super().__init_subclass_with_meta__(
            _meta=_meta,
            input_fields=input_fields,
            **kwargs,
        )

        cls._meta.fields.update(fields) 
开发者ID:0soft,项目名称:graphene-django-plus,代码行数:40,代码来源:mutations.py


示例5: __init_subclass_with_meta__

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=False,
                                    only_fields=(), exclude_fields=(), connection=None,
                                    use_connection=None, interfaces=(), **options):

        if not model:
            raise Exception((
                'NdbObjectType {name} must have a model in the Meta class attr'
            ).format(name=cls.__name__))

        if not inspect.isclass(model) or not issubclass(model, ndb.Model):
            raise Exception((
                'Provided model in {name} is not an NDB model'
            ).format(name=cls.__name__))

        if not registry:
            registry = get_global_registry()

        assert isinstance(registry, Registry), (
            'The attribute registry in {} needs to be an instance of '
            'Registry, received "{}".'
        ).format(cls.__name__, registry)

        ndb_fields = fields_for_ndb_model(model, registry, only_fields, exclude_fields)
        ndb_fields = yank_fields_from_attrs(
            ndb_fields,
            _as=Field,
        )

        if use_connection is None and interfaces:
            use_connection = any((issubclass(interface, Node) for interface in interfaces))

        if use_connection and not connection:
            # We create the connection automatically
            connection = Connection.create_type('{}Connection'.format(cls.__name__), node=cls)

        if connection is not None:
            assert issubclass(connection, Connection), (
                "The connection must be a Connection. Received {}"
            ).format(connection.__name__)

        _meta = NdbObjectTypeOptions(cls)
        _meta.model = model
        _meta.registry = registry
        _meta.fields = ndb_fields
        _meta.connection = connection

        super(NdbObjectType, cls).__init_subclass_with_meta__(_meta=_meta, interfaces=interfaces, **options)

        if not skip_registry:
            registry.register(cls) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:52,代码来源:types.py


示例6: __init_subclass_with_meta__

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def __init_subclass_with_meta__(
        cls,
        model=None,
        registry=None,
        skip_registry=False,
        only_fields=(),
        exclude_fields=(),
        include_fields=(),
        filter_fields=None,
        interfaces=(),
        filterset_class=None,
        **options,
    ):
        assert is_valid_django_model(model), (
            'You need to pass a valid Django Model in {}.Meta, received "{}".'
        ).format(cls.__name__, model)

        if not registry:
            registry = get_global_registry()

        assert isinstance(registry, Registry), (
            "The attribute registry in {} needs to be an instance of "
            'Registry, received "{}".'
        ).format(cls.__name__, registry)

        if not DJANGO_FILTER_INSTALLED and (filter_fields or filterset_class):
            raise Exception(
                "Can only set filter_fields or filterset_class if Django-Filter is installed"
            )

        django_fields = yank_fields_from_attrs(
            construct_fields(
                model, registry, only_fields, include_fields, exclude_fields
            ),
            _as=Field,
        )

        _meta = DjangoObjectOptions(cls)
        _meta.model = model
        _meta.registry = registry
        _meta.filter_fields = filter_fields
        _meta.fields = django_fields
        _meta.filterset_class = filterset_class

        super(DjangoObjectType, cls).__init_subclass_with_meta__(
            _meta=_meta, interfaces=interfaces, **options
        )

        if not skip_registry:
            registry.register(cls) 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:52,代码来源:types.py


示例7: __init_subclass_with_meta__

# 需要导入模块: from graphene.types import utils [as 别名]
# 或者: from graphene.types.utils import yank_fields_from_attrs [as 别名]
def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=False,
                                    only_fields=(), exclude_fields=(), connection=None,
                                    use_connection=None, interfaces=(), id=None, **options):
        assert model and isclass(model) and issubclass(model, Model), (
            'You need to pass a valid PynamoDB Model in '
            '{}.Meta, received "{}".'
        ).format(cls.__name__, model)

        if not registry:
            registry = get_global_registry()

        assert isinstance(registry, Registry), (
            'The attribute registry in {} needs to be an instance of '
            'Registry, received "{}".'
        ).format(cls.__name__, registry)

        pynamo_fields = yank_fields_from_attrs(
            construct_fields(model, registry, only_fields, exclude_fields),
            _as=Field,
        )

        if use_connection is None and interfaces:
            use_connection = any((issubclass(interface, Node) for interface in interfaces))

        if use_connection and not connection:
            # We create the connection automatically
            connection = Connection.create_type('{}Connection'.format(cls.__name__), node=cls)

        if connection is not None:
            assert issubclass(connection, Connection), (
                "The connection must be a Connection. Received {}"
            ).format(connection.__name__)

        _meta = PynamoObjectTypeOptions(cls)
        _meta.model = model
        _meta.registry = registry
        _meta.fields = pynamo_fields
        _meta.connection = connection
        _meta.id = id or 'id'

        super(PynamoObjectType, cls).__init_subclass_with_meta__(_meta=_meta, interfaces=interfaces, **options)

        if not skip_registry:
            registry.register(cls) 
开发者ID:yfilali,项目名称:graphql-pynamodb,代码行数:46,代码来源:types.py



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