コード例 #1
0
ファイル: core.py プロジェクト: pengqi/quick_orm
    def register():
        for i in range(len(models)):
            model = models[i]
            if '_decl_class_registry' in model.__dict__:
                continue
            _as_declarative(model, model.__name__, model.__dict__)

            #for auto-update timestamps
            event.listen(model, 'before_insert', ModelExtension.before_insert_listener)
            event.listen(model, 'before_update', ModelExtension.before_update_listener)

            # for ref grandchildren
            for j in range(i):
                if not models[j] in model.__bases__:
                    continue
                parent = models[j]
                for grandparent in parent._many_to_models:
                    setattr(grandparent, model._readable_names,
                        (lambda parent, model: property(lambda self: getattr(self, parent._readable_names)
                        .filter_by(real_type = model._readable_name)))(parent, model))

                for grandparent in parent._one_to_models:
                    setattr(grandparent, model._readable_name,
                        (lambda parent, model: property(lambda self: getattr(self, parent._readable_name)
                            if getattr(self, parent._readable_name).real_type == model._readable_name else None))(parent, model))
        models[:] = []
コード例 #2
0
    def register():
        for i in range(len(models)):
            model = models[i]
            if '_decl_class_registry' in model.__dict__:
                continue
            _as_declarative(model, model.__name__, model.__dict__)

            #for auto-update timestamps
            event.listen(model, 'before_insert',
                         ModelExtension.before_insert_listener)
            event.listen(model, 'before_update',
                         ModelExtension.before_update_listener)

            # for ref grandchildren
            for j in range(i):
                if not models[j] in model.__bases__:
                    continue
                parent = models[j]
                for grandparent in parent._many_to_models:
                    setattr(
                        grandparent, model._readable_names,
                        (lambda parent, model: property(lambda self: getattr(
                            self, parent._readable_names).filter_by(
                                real_type=model._readable_name)))(parent,
                                                                  model))

                for grandparent in parent._one_to_models:
                    setattr(
                        grandparent, model._readable_name,
                        (lambda parent, model: property(
                            lambda self: getattr(self, parent._readable_name)
                            if getattr(self, parent._readable_name).real_type
                            == model._readable_name else None))(parent, model))
        models[:] = []
コード例 #3
0
    def __init__(cls, classname, bases, dict_):
        if '_decl_class_registry' in cls.__dict__:
            return MetaHasTraits.__init__(cls, classname, bases, dict_)

       # create sql columns from flagged traits
        if '__class_traits__' in cls.__dict__:
            traits = cls.__dict__['__class_traits__']
            for key, trait in traits.items():
                if getattr( trait, 'sqldb' ):
                    args = getattr( trait, 'col_args' ) or ()
                    kwargs = getattr( trait, 'col_kwargs' ) or {}
                    if 'name' not in kwargs:
                        kwargs['name'] = key
                    if 'type_' not in kwargs:
                        kwargs['type_'] = eval(TRAIT_MAPPING[type(trait.trait_type)])

                    c = Column(*args, **kwargs)
                    dict_[key] = c

        _as_declarative(cls, classname, dict_)
        return MetaHasTraits.__init__(cls, classname, bases, dict_)
コード例 #4
0
ファイル: __init__.py プロジェクト: CIRB/cirb.organizations
 def __init__(cls, classname, bases, dict_):
     if '_decl_class_registry' in cls.__dict__:
         return type.__init__(cls, classname, bases, dict_)
     else:
         _as_declarative(cls, classname, cls.__dict__)
     return type.__init__(cls, classname, bases, dict_)