Esempio n. 1
0
 def test_wrongs(me):
     for a in me.Kid, me.Kid.name, 'alala':
         try:
             about_relation(a)
         except ValueError, e:
             if 'not a relation klas_attr' in e.message: continue
             raise
Esempio n. 2
0
 def test_wrongs( me):
     for a in me.Kid, me.Kid.name, 'alala':
         try:
             about_relation( a)
         except ValueError, e:
             if 'not a relation klas_attr' in e.message: continue
             raise
Esempio n. 3
0
        def get_which_owner(me):
            try:
                return me._which_owner
            except AttributeError:
                pass

            # here is walking refs at column-level; maybe mapperExt @ populate_instance
            from dbcook.aboutrel import about_relation
            for selector in me.possible_owners():
                ab = about_relation(me.__class__, selector)
                column = ab.thisside.column
                if getattr(me, column.key) is not None:
                    me._which_owner = selector
                    return selector

            # above alone is not enough -
            #  - a newly-created object + low-level copy of refs (not via .owner)
            # would not have column_id set-up yet (but would have an attr)

            # warning: this may fire lazy-loads
            for selector in me.possible_owners():
                if getattr(me, selector) is not None:
                    me._which_owner = selector
                    return selector

            return None
Esempio n. 4
0
def rel_has_or_anyhas(klas_attr_or_klas,
                      other_attr_name,
                      value,
                      attr_name=None):
    ab = about_relation(klas_attr_or_klas, attr_name)
    klasattr = ab.thisside.attr
    other_attr = getattr(ab.otherside.klas, other_attr_name)
    has = ab.thisside.has_many and klasattr.any or klasattr.has
    return has(other_attr == value)
Esempio n. 5
0
def test( attr, other={}, about_relation= about_relation, **this):
    a = about_relation( attr)
    print a
    if a.ownedside:
        if a.thisside.has_many:
            assert a.ownedside is a.otherside
            assert a.ownerside is a.thisside
        else:
            assert a.ownerside is a.otherside
            assert a.ownedside is a.thisside

    other.setdefault( 'has_many', not this['has_many'])
    for o,oexpect in [[a.thisside,this], [a.otherside,other]]:
        target = dict( (k,getattr(o,k)) for k in oexpect)
        assert target == oexpect, '%(o)s:\n result: %(target)r\n expect: %(oexpect)r' % locals()
    return a
Esempio n. 6
0
def test(attr, other={}, about_relation=about_relation, **this):
    a = about_relation(attr)
    print a
    if a.ownedside:
        if a.thisside.has_many:
            assert a.ownedside is a.otherside
            assert a.ownerside is a.thisside
        else:
            assert a.ownerside is a.otherside
            assert a.ownedside is a.thisside

    other.setdefault('has_many', not this['has_many'])
    for o, oexpect in [[a.thisside, this], [a.otherside, other]]:
        target = dict((k, getattr(o, k)) for k in oexpect)
        assert target == oexpect, '%(o)s:\n result: %(target)r\n expect: %(oexpect)r' % locals(
        )
    return a
Esempio n. 7
0
def rel_is_or_contains(klas_attr_or_klas, value, attr_name=None):
    """може ли да се прави OR !??x
    може ли да отиде в expression.py вместо join-ite там?
    """
    if attr_name is None:
        klas_attr = klas_attr_or_klas
    else:
        klas_attr = getattr(klas_attr_or_klas, attr_name)
    op = klasattr.__eq__
    try:
        ab = about_relation(klas_attr)
    except ValueError:
        pass  # non-rel
    else:
        if ab.thisside.has_many:
            op = klasattr.contains
    return op(value)
Esempio n. 8
0
def rel_is_or_contains(
    klas_attr_or_klas,
    value,
    attr_name=None,
):
    '''може ли да се прави OR !??x
    може ли да отиде в expression.py вместо join-ite там?
    '''
    if attr_name is None: klas_attr = klas_attr_or_klas
    else: klas_attr = getattr(klas_attr_or_klas, attr_name)
    op = klasattr.__eq__
    try:
        ab = about_relation(klas_attr)
    except ValueError:
        pass  #non-rel
    else:
        if ab.thisside.has_many: op = klasattr.contains
    return op(value)
Esempio n. 9
0
        def get_which_owner( me):
            try: return me._which_owner
            except AttributeError: pass

            # here is walking refs at column-level; maybe mapperExt @ populate_instance
            from dbcook.aboutrel import about_relation
            for selector in me.possible_owners():
                ab = about_relation( me.__class__, selector)
                column = ab.thisside.column
                if getattr( me, column.key) is not None:
                    me._which_owner = selector
                    return selector

            # above alone is not enough -
            #  - a newly-created object + low-level copy of refs (not via .owner)
            # would not have column_id set-up yet (but would have an attr)

            # warning: this may fire lazy-loads
            for selector in me.possible_owners():
                if getattr( me, selector) is not None:
                    me._which_owner = selector
                    return selector

            return None
Esempio n. 10
0
def rel_has_or_anyhas(klas_attr_or_klas, other_attr_name, value, attr_name=None):
    ab = about_relation(klas_attr_or_klas, attr_name)
    klasattr = ab.thisside.attr
    other_attr = getattr(ab.otherside.klas, other_attr_name)
    has = ab.thisside.has_many and klasattr.any or klasattr.has
    return has(other_attr == value)