1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
667 super(CubicWebEntitySchema, self).__init__(schema, edef, **kwargs) |
667 super(CubicWebEntitySchema, self).__init__(schema, edef, **kwargs) |
668 if eid is None and edef is not None: |
668 if eid is None and edef is not None: |
669 eid = getattr(edef, 'eid', None) |
669 eid = getattr(edef, 'eid', None) |
670 self.eid = eid |
670 self.eid = eid |
671 |
671 |
|
672 def targets(self, role): |
|
673 assert role in ('subject', 'object') |
|
674 if role == 'subject': |
|
675 return self.subjrels.values() |
|
676 return self.objrels.values() |
|
677 |
|
678 @cachedproperty |
|
679 def composite_rdef_roles(self): |
|
680 """Return all relation definitions that define the current entity |
|
681 type as a composite. |
|
682 """ |
|
683 rdef_roles = [] |
|
684 for role in ('subject', 'object'): |
|
685 for rschema in self.targets(role): |
|
686 if rschema.final: |
|
687 continue |
|
688 for rdef in rschema.rdefs.values(): |
|
689 crole = rdef.composite |
|
690 if crole == role: |
|
691 rdef_roles.append((rdef, role)) |
|
692 return rdef_roles |
|
693 |
|
694 @cachedproperty |
|
695 def is_composite(self): |
|
696 return bool(len(self.composite_rdef_roles)) |
|
697 |
672 def check_permission_definitions(self): |
698 def check_permission_definitions(self): |
673 super(CubicWebEntitySchema, self).check_permission_definitions() |
699 super(CubicWebEntitySchema, self).check_permission_definitions() |
674 for groups in self.permissions.itervalues(): |
700 for groups in self.permissions.itervalues(): |
675 for group_or_rqlexpr in groups: |
701 for group_or_rqlexpr in groups: |
676 if isinstance(group_or_rqlexpr, RRQLExpression): |
702 if isinstance(group_or_rqlexpr, RRQLExpression): |