def _potential_relations(obj): """Given an object return tuples of name, index, relation value. Returns both IRelationValue attributes as well as ITemporaryRelationValue attributes. If this is a IRelationList attribute, index will contain the index in the list. If it's a IRelation attribute, index will be None. """ for iface in providedBy(obj).flattened(): for name, field in getFields(iface).items(): frel = name + '_rel' _rel = iface.queryTaggedValue(frel) if _rel is not None: field = _rel name = frel if IRelation.providedBy(field): try: relation = getattr(obj, name) except AttributeError: # can't find this relation on the object continue yield name, None, relation if IRelationList.providedBy(field): try: l = getattr(obj, name) except AttributeError: # can't find the relation list on this object continue if l is not None: for i, relation in enumerate(l): yield name, i, relation
def append_links(self, obj, link_objs): for name, field, schemata in self._iter_fields(obj.portal_type): storage = schemata(obj) fieldvalue = getattr(storage, name) if not fieldvalue: continue if IRelation.providedBy(field): if fieldvalue.isBroken(): link = Link() link.complete_information_for_broken_relation_with_broken_relation_obj( obj, field) link_objs.append(link) elif IURI.providedBy(field): link = Link() link.complete_information_with_external_path(obj, fieldvalue) link_objs.append(link) elif IRichText.providedBy(field): content = fieldvalue.raw self._extract_and_append_link_objs(content, obj, link_objs) return link_objs
def _potential_relations(obj): """Given an object return tuples of name, index, relation value. Returns both IRelationValue attributes as well as ITemporaryRelationValue attributes. If this is a IRelationList attribute, index will contain the index in the list. If it's a IRelation attribute, index will be None. """ for iface in providedBy(obj).flattened(): for name, field in getFields(iface).items(): if IRelation.providedBy(field): try: relation = getattr(obj, name) except AttributeError: # can't find this relation on the object continue yield name, None, relation if IRelationList.providedBy(field): try: l = getattr(obj, name) except AttributeError: # can't find the relation list on this object continue if l is not None: for i, relation in enumerate(l): yield name, i, relation
def extract_relations(obj): assignable = IBehaviorAssignable(obj, None) if assignable is None: return for behavior in assignable.enumerateBehaviors(): if behavior.marker != behavior.interface: for name, field in getFields(behavior.interface).items(): if IRelation.providedBy(field): try: relation = getattr(behavior.interface(obj), name) except AttributeError: continue yield behavior.interface, name, relation if IRelationList.providedBy(field): try: l = getattr(behavior.interface(obj), name) except AttributeError: continue if l is not None: for relation in l: yield behavior.interface, name, relation
def extract_relations(obj): assignable = IBehaviorAssignable(obj, None) if assignable is None: return for behavior in assignable.enumerateBehaviors(): if behavior.marker == behavior.interface: continue for name, field in getFields(behavior.interface).items(): if IRelation.providedBy(field): try: relation = getattr(behavior.interface(obj), name) except AttributeError: continue yield behavior.interface, name, relation if IRelationList.providedBy(field): try: rel_list = getattr(behavior.interface(obj), name) except AttributeError: continue if rel_list is not None: for relation in rel_list: yield behavior.interface, name, relation