def has_value(self, **kwargs): """ Has value? """ state = kwargs.get('state', None) value = self.get_value(**kwargs) if not state: return bool(value) relations = set(rel for rel in self.relations(state)) for doc in value: ctype = queryContentType(doc) if not ctype: continue name = ctype.getId() if name not in relations: continue relations.remove(name) if not relations: return True return False
def __call__(self, value, instance, *args, **kwargs): """ Validate """ if not value: return 1 if not isinstance(value, (tuple, list)): value = value, ctool = getToolByName(instance, 'portal_catalog') brains = ctool(UID={'query': value, 'operator': 'or'}) relations = set(self.relations(instance)) if not relations: return 1 for brain in brains: doc = brain.getObject() if not doc: continue ctype = queryContentType(doc) if not ctype: continue name = ctype.getId() if name not in relations: continue relations.remove(name) if not relations: return 1 rtool = getToolByName(instance, 'portal_relations') names = [rtool[rel].title_or_id() for rel in relations] return "Requires relations with: %s" % ', '.join(names)