selectors.py
branchtls-sprint
changeset 1178 8d9b705168d3
parent 1138 22f634977c95
child 1263 01152fffd593
equal deleted inserted replaced
1177:7074698c6522 1178:8d9b705168d3
   651 
   651 
   652     def complete(self, cls):
   652     def complete(self, cls):
   653         self.rtype = cls.rtype
   653         self.rtype = cls.rtype
   654         self.role = role(cls)
   654         self.role = role(cls)
   655         self.target_etype = getattr(cls, 'etype', None)
   655         self.target_etype = getattr(cls, 'etype', None)
   656 
       
   657 
       
   658 class has_editable_relation(EntitySelector):
       
   659     """accept if some relations for an entity found in the result set is
       
   660     editable by the logged user.
       
   661 
       
   662     See `EntitySelector` documentation for behaviour when row is not specified.
       
   663     """
       
   664         
       
   665     def score_entity(self, entity):
       
   666         # if user has no update right but it can modify some relation,
       
   667         # display action anyway
       
   668         for dummy in entity.srelations_by_category(('generic', 'metadata'),
       
   669                                                    'add'):
       
   670             return 1
       
   671         for rschema, targetschemas, role in entity.relations_by_category(
       
   672             ('primary', 'secondary'), 'add'):
       
   673             if not rschema.is_final():
       
   674                 return 1
       
   675         return 0
       
   676 
   656 
   677 
   657 
   678 class may_add_relation(EntitySelector):
   658 class may_add_relation(EntitySelector):
   679     """accept if the relation can be added to an entity found in the result set
   659     """accept if the relation can be added to an entity found in the result set
   680     by the logged user.
   660     by the logged user.