def delete(self, relation_id, when=None): if when is None: when = datetime.now(utc) relation = Relation.load_by_relation_id(self.env, relation_id) source = relation.source destination = relation.destination relation_type = relation.type with self.env.db_transaction: cloned_relation = relation.clone() relation.delete() other_end = self.link_ends_map[relation_type] if other_end: reverted_relation = Relation(self.env, keys=dict( source=destination, destination=source, type=other_end, )) reverted_relation.delete() for listener in self.changing_listeners: listener.deleting_relation(cloned_relation, when) from bhrelations.notification import RelationNotifyEmail RelationNotifyEmail(self.env).notify(cloned_relation, deleted=when)
def add(self, source_resource_instance, destination_resource_instance, relation_type, comment=None, author=None, when=None): source = ResourceIdSerializer.get_resource_id_from_instance( self.env, source_resource_instance) destination = ResourceIdSerializer.get_resource_id_from_instance( self.env, destination_resource_instance) if relation_type not in self.link_ends_map: raise UnknownRelationType(relation_type) if when is None: when = datetime.now(utc) relation = Relation(self.env) relation.source = source relation.destination = destination relation.type = relation_type relation.comment = comment relation.author = author relation.when = when self.add_relation(relation) return relation