def remove(self, first, second, relation_type): """Remove the relation between the first and the second.""" self._validate_relation_type(relation_type) sr = SiblingsRelation(relation_type) sr.remove(pid=second.pid) # remove any metadata for this relation, if any # both first and second could have metadata for the relation RecordRelationsMetadata.remove_metadata_from( first, relation_type.name, second.pid.pid_value, second._pid_type ) RecordRelationsMetadata.remove_metadata_from( second, relation_type.name, first.pid.pid_value, first._pid_type ) return first, second
def get(self): """Get all relations of this record, adding any relations metadata.""" relations = {} for relation_type in current_app.config["PARENT_CHILD_RELATION_TYPES"]: pcr = ParentChildRelation(relation_type) name = relation_type.name # self.record is a child for parent_pid in pcr.parents_of(self.record.pid): child_pid = self.record.pid r = self._build_child(parent_pid, child_pid, name) relations.setdefault(name, []) relations[name].append(r) for relation_type in current_app.config["SIBLINGS_RELATION_TYPES"]: sr = SiblingsRelation(relation_type) name = relation_type.name for related_pid in sr.all(self.record.pid): r = self._build_sibling(related_pid, name) relations.setdefault(name, []) relations[name].append(r) for relation_type in current_app.config["SEQUENCE_RELATION_TYPES"]: sqr = SequenceRelation(relation_type) name = relation_type.name for next_pid in sqr.next_relations(self.record.pid): relations.setdefault("next", []) r = self._build_sequence(next_pid, name) relations["next"].append(r) for previous_pid in sqr.previous_relations(self.record.pid): relations.setdefault("previous", []) r = self._build_sequence(previous_pid, name) relations["previous"].append(r) return relations