コード例 #1
0
ファイル: types.py プロジェクト: assembl/assembl
    def __new__(cls, name, bases, attrs):
        # Also ensure initialization is only performed for subclasses of
        # SQLAlchemyInterface (excluding SQLAlchemyInterface class itself).
        if not is_base_type(bases, SQLAlchemyInterfaceMeta):
            return type.__new__(cls, name, bases, attrs)

        options = Options(
            attrs.pop('Meta', None),
            name=name,
            description=attrs.pop('__doc__', None),
            model=None,
            local_fields=None,
            only_fields=(),
            exclude_fields=(),
            # id='id',
            registry=None
        )

        if not options.registry:
            options.registry = get_global_registry()
        assert isinstance(options.registry, Registry), (
            'The attribute registry in {}.Meta needs to be an'
            ' instance of Registry, received "{}".'
        ).format(name, options.registry)
        assert is_mapped(options.model), (
            'You need to pass a valid SQLAlchemy Model in '
            '{}.Meta, received "{}".'
        ).format(name, options.model)

        cls = type.__new__(cls, name, bases, dict(attrs, _meta=options))

        options.base_fields = ()
        options.base_fields = get_base_fields(bases, _as=Field)
        if not options.local_fields:
            options.local_fields = yank_fields_from_attrs(attrs, _as=Field)

        # options.registry.register(cls)

        options.fields = merge(
            options.base_fields,
            options.local_fields
        )

        options.sqlalchemy_fields = yank_fields_from_attrs(
            construct_fields(options),
            _as=Field,
        )
        options.fields = merge(
            options.sqlalchemy_fields,
            options.base_fields,
            options.local_fields
        )

        return cls
コード例 #2
0
    def __new__(cls, name, bases, attrs):
        # Also ensure initialization is only performed for subclasses of Model
        # (excluding Model class itself).
        if not is_base_type(bases, SQLAlchemyObjectTypeMeta):
            return type.__new__(cls, name, bases, attrs)

        options = Options(
            attrs.pop('Meta', None),
            name=name,
            description=attrs.pop('__doc__', None),
            model=None,
            local_fields=None,
            only_fields=(),
            exclude_fields=(),
            id='id',
            interfaces=(),
            registry=None,
            abstract=False,
        )

        cls = ObjectTypeMeta.__new__(cls, name, bases,
                                     dict(attrs, _meta=options))

        if options.abstract:
            return cls

        if not options.registry:
            options.registry = get_global_registry()
        assert isinstance(
            options.registry,
            Registry), ('The attribute registry in {}.Meta needs to be an'
                        ' instance of Registry, received "{}".').format(
                            name, options.registry)
        assert is_mapped_class(
            options.model), ('You need to pass a valid SQLAlchemy Model in '
                             '{}.Meta, received "{}".').format(
                                 name, options.model)

        options.registry.register(cls)

        options.sqlalchemy_fields = yank_fields_from_attrs(
            construct_fields(options),
            _as=Field,
        )
        options.fields = merge(options.interface_fields,
                               options.sqlalchemy_fields, options.base_fields,
                               options.local_fields)

        return cls
コード例 #3
0
ファイル: types.py プロジェクト: wowngasb/pykl
    def __new__(cls, name, bases, attrs):
        # Also ensure initialization is only performed for subclasses of Model
        # (excluding Model class itself).
        if not is_base_type(bases, SQLAlchemyObjectTypeMeta):
            return type.__new__(cls, name, bases, attrs)

        meta = attrs.pop('Meta', None)
        local_fields = OrderedDict(
            {k: v
             for k, v in attrs.items() if _is_graphql(v)})
        tbl_doc = attrs.pop('__doc__', getattr(meta.model, '__doc__', None))
        options = Options(meta,
                          name=name,
                          description=tbl_doc if not tbl_doc else
                          (tbl_doc if isinstance(tbl_doc, unicode) else
                           tbl_doc.decode('utf8')),
                          model=None,
                          local_fields=local_fields,
                          exclude_fields=set(),
                          interfaces=(),
                          registry=None)

        if not options.registry:
            options.registry = get_global_registry()
        assert isinstance(
            options.registry,
            Registry), ('The attribute registry in {}.Meta needs to be an'
                        ' instance of Registry, received "{}".').format(
                            name, options.registry)
        assert is_mapped(
            options.model), ('You need to pass a valid SQLAlchemy Model in '
                             '{}.Meta, received "{}".').format(
                                 name, options.model)

        cls = ObjectTypeMeta.__new__(cls, name, bases,
                                     dict(attrs, _meta=options))

        options.registry.register(cls)

        options.sqlalchemy_fields = yank_fields_from_attrs(
            construct_fields(options),
            _as=graphene.Field,
        )
        options.fields = merge(options.interface_fields,
                               options.sqlalchemy_fields, options.base_fields,
                               options.local_fields)

        return cls
コード例 #4
0
ファイル: types.py プロジェクト: wowngasb/kl_tool
    def __new__(cls, name, bases, attrs):
        # Also ensure initialization is only performed for subclasses of Model
        # (excluding Model class itself).
        if not is_base_type(bases, SQLAlchemyObjectTypeMeta):
            return type.__new__(cls, name, bases, attrs)

        meta = attrs.pop('Meta', None)
        local_fields = OrderedDict({k:v for k,v in attrs.items() if _is_graphql(v)})

        options = Options(
            meta,
            name=name,
            description=attrs.pop('__doc__', getattr(meta.model, '__doc__', None)),
            model=None,
            local_fields=local_fields,
            exclude_fields=set(),
            interfaces=(),
            registry=None
        )

        if not options.registry:
            options.registry = get_global_registry()
        assert isinstance(options.registry, Registry), (
            'The attribute registry in {}.Meta needs to be an'
            ' instance of Registry, received "{}".'
        ).format(name, options.registry)
        assert is_mapped(options.model), (
            'You need to pass a valid SQLAlchemy Model in '
            '{}.Meta, received "{}".'
        ).format(name, options.model)

        cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options))

        options.registry.register(cls)

        options.sqlalchemy_fields = yank_fields_from_attrs(
            construct_fields(options),
            _as = graphene.Field,
        )
        options.fields = merge(
            options.interface_fields,
            options.sqlalchemy_fields,
            options.base_fields,
            options.local_fields
        )

        return cls