class Connection(Element): class_name = "connection" def __init__(self, title = None, element_model = None): super(Connection, self).__init__(title = title, element_model = element_model) self.src = self.add_input_connector() self.dst = self.add_output_connector() if element_model is None: self.connection_model = None else: self.connection_model = element_model.connectionmodel @classmethod def get_all_saved_connections(cls): return ConnectionModel.objects.all() def set_flow(self, flow): super(Connection, self).set_flow(flow) # this is the place where the element_model gets saved, so I can create the connection model if self.connection_model is None: self.connection_model = ConnectionModel(element = self.element_model) def set_src_dst(self, src, dst): self.src = self.replace_input_connector(self.src, src) self.dst = self.replace_output_connector(self.dst, dst) self.connection_model.src_element = src.element.element_model self.connection_model.src_connector = src.title self.connection_model.dst_element = dst.element.element_model self.connection_model.dst_connector = dst.title self.connection_model.save() if self.flow: self.flow.invalidate_chain(self.dst) else: self.dst.invalidate_connector() def run(self, debug = False): if DEBUG or debug: print " Connection %s from %s to %s" % (self.title, self.src.title, self.dst.title) self.dst.set_value(self.src.value) def block(self): # exceptional case for a connection: even if src is "blocked", we still want to copy # the data from src to dst, because we don't want a connection with different data on # both ends of the line. self.dst.set_value(self.src.value) super(Connection, self).block()
def set_flow(self, flow): super(Connection, self).set_flow(flow) # this is the place where the element_model gets saved, so I can create the connection model if self.connection_model is None: self.connection_model = ConnectionModel(element = self.element_model)