entity.py
branch3.5
changeset 2941 196493bd099c
parent 2931 17224e90a1c4
child 2942 77ebdbe93cf8
equal deleted inserted replaced
2940:db2fb2907389 2941:196493bd099c
   180         for rschema, _ in eschema.attribute_definitions():
   180         for rschema, _ in eschema.attribute_definitions():
   181             if rschema.type == 'eid':
   181             if rschema.type == 'eid':
   182                 continue
   182                 continue
   183             setattr(cls, rschema.type, Attribute(rschema.type))
   183             setattr(cls, rschema.type, Attribute(rschema.type))
   184         mixins = []
   184         mixins = []
   185         for rschema, _, x in eschema.relation_definitions():
   185         for rschema, _, role in eschema.relation_definitions():
   186             if (rschema, x) in MI_REL_TRIGGERS:
   186             if (rschema, role) in MI_REL_TRIGGERS:
   187                 mixin = MI_REL_TRIGGERS[(rschema, x)]
   187                 mixin = MI_REL_TRIGGERS[(rschema, role)]
   188                 if not (issubclass(cls, mixin) or mixin in mixins): # already mixed ?
   188                 if not (issubclass(cls, mixin) or mixin in mixins): # already mixed ?
   189                     mixins.append(mixin)
   189                     mixins.append(mixin)
   190                 for iface in getattr(mixin, '__implements__', ()):
   190                 for iface in getattr(mixin, '__implements__', ()):
   191                     if not interface.implements(cls, iface):
   191                     if not interface.implements(cls, iface):
   192                         interface.extend(cls, iface)
   192                         interface.extend(cls, iface)
   193             if x == 'subject':
   193             if role == 'subject':
   194                 setattr(cls, rschema.type, SubjectRelation(rschema))
   194                 setattr(cls, rschema.type, SubjectRelation(rschema))
   195             else:
   195             else:
   196                 attr = 'reverse_%s' % rschema.type
   196                 attr = 'reverse_%s' % rschema.type
   197                 setattr(cls, attr, ObjectRelation(rschema))
   197                 setattr(cls, attr, ObjectRelation(rschema))
   198         if mixins:
   198         if mixins:
   613             # handle attributes
   613             # handle attributes
   614             for i in xrange(1, lastattr):
   614             for i in xrange(1, lastattr):
   615                 self[str(selected[i-1][0])] = rset[i]
   615                 self[str(selected[i-1][0])] = rset[i]
   616             # handle relations
   616             # handle relations
   617             for i in xrange(lastattr, len(rset)):
   617             for i in xrange(lastattr, len(rset)):
   618                 rtype, x = selected[i-1][0]
   618                 rtype, role = selected[i-1][0]
   619                 value = rset[i]
   619                 value = rset[i]
   620                 if value is None:
   620                 if value is None:
   621                     rrset = ResultSet([], rql, {'x': self.eid})
   621                     rrset = ResultSet([], rql, {'x': self.eid})
   622                     self.req.decorate_rset(rrset)
   622                     self.req.decorate_rset(rrset)
   623                 else:
   623                 else:
   624                     rrset = self.req.eid_rset(value)
   624                     rrset = self.req.eid_rset(value)
   625                 self.set_related_cache(rtype, x, rrset)
   625                 self.set_related_cache(rtype, role, rrset)
   626 
   626 
   627     def get_value(self, name):
   627     def get_value(self, name):
   628         """get value for the attribute relation <name>, query the repository
   628         """get value for the attribute relation <name>, query the repository
   629         to get the value if necessary.
   629         to get the value if necessary.
   630 
   630