def postprocess(self): web = WebContainer.get_web() value = web.get_form_value( self.get_input_name() ) if not value: return # get all fo the sobjects from the search keys instance_type = self.get_option("instance_type") # path is used for self-relating in an instance table src_path = self.get_option("path") #src_sobject = self.sobject search = Search(self.sobject.get_search_type()) search.add_id_filter(self.sobject.get_id()) src_sobject = search.get_sobject() # this is passed in from EditCmd in insert mode parent_key = self.get_option('parent_key') # in some rare cases we have project as the parent_key if parent_key and self.is_insert and 'sthpw/project' not in parent_key: # this is the parent dst_sobject = SearchKey.get_by_search_key(parent_key) # add all the new sobjects #instances = dst_sobject.get_related_sobject(instance_type) instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path) instance.commit()
def postprocess(my): web = WebContainer.get_web() value = web.get_form_value(my.get_input_name()) if not value: return # get all fo the sobjects from the search keys instance_type = my.get_option("instance_type") # path is used for self-relating in an instance table src_path = my.get_option("path") #src_sobject = my.sobject search = Search(my.sobject.get_search_type()) search.add_id_filter(my.sobject.get_id()) src_sobject = search.get_sobject() # this is passed in from EditCmd in insert mode parent_key = my.get_option('parent_key') # in some rare cases we have project as the parent_key if parent_key and my.is_insert and 'sthpw/project' not in parent_key: # this is the parent dst_sobject = SearchKey.get_by_search_key(parent_key) # add all the new sobjects #instances = dst_sobject.get_related_sobject(instance_type) instance = SearchType.create(instance_type) instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path) instance.commit()
def do_search(my): '''this widget has its own search mechanism''' web = WebContainer.get_web() # get the sobject that is to be edited id = my.search_id # if no id is given, then create a new one for insert search = None sobject = None search_type_base = SearchType.get(my.search_type).get_base_key() if my.mode == "insert": sobject = SearchType.create(my.search_type) my.current_id = -1 # prefilling default values if available value_keys = web.get_form_keys() if value_keys: for key in value_keys: value = web.get_form_value(key) sobject.set_value(key, value) else: search = Search(my.search_type) # figure out which id to search for if web.get_form_value("do_edit") == "Edit/Next": search_ids = web.get_form_value("%s_search_ids" % search_type_base) if search_ids == "": my.current_id = id else: search_ids = search_ids.split("|") next = search_ids.index(str(id)) + 1 if next == len(search_ids): next = 0 my.current_id = search_ids[next] last_search = Search(my.search_type) last_search.add_id_filter(id) my.last_sobject = last_search.get_sobject() else: my.current_id = id search.add_id_filter(my.current_id) sobject = search.get_sobject() if not sobject and my.current_id != -1: raise EditException("No SObject found") # set all of the widgets to contain this sobject my.set_sobjects([sobject], search)
def do_search(my): '''this widget has its own search mechanism''' web = WebContainer.get_web() # get the sobject that is to be edited id = my.search_id # if no id is given, then create a new one for insert search = None sobject = None search_type_base = SearchType.get(my.search_type).get_base_key() if my.mode == "insert": sobject = SearchType.create(my.search_type) my.current_id = -1 # prefilling default values if available value_keys = web.get_form_keys() if value_keys: for key in value_keys: value = web.get_form_value(key) sobject.set_value(key, value) else: search = Search(my.search_type) # figure out which id to search for if web.get_form_value("do_edit") == "Edit/Next": search_ids = web.get_form_value("%s_search_ids" %search_type_base) if search_ids == "": my.current_id = id else: search_ids = search_ids.split("|") next = search_ids.index(str(id)) + 1 if next == len(search_ids): next = 0 my.current_id = search_ids[next] last_search = Search(my.search_type) last_search.add_id_filter( id ) my.last_sobject = last_search.get_sobject() else: my.current_id = id search.add_id_filter( my.current_id ) sobject = search.get_sobject() if not sobject and my.current_id != -1: raise EditException("No SObject found") # set all of the widgets to contain this sobject my.set_sobjects( [sobject], search )
def execute(self): web = WebContainer.get_web() # get the input names input_names = web.get_form_value( SerialStatusWdg.STATUS_CMD_INPUT).split('|') values = [] for input_name in input_names: value = web.get_form_value(input_name) if value: values.append(web.get_form_value(input_name)) # FIXME: HARDCODED Value for status column!!!! column = "status" for value in values: # get the sobject to be updated search_type, id, status = value.split("|") search = Search(search_type) search.add_id_filter(id) self.sobject = search.get_sobject() status_attr = self.sobject.get_attr(column) cur_status = status_attr.get_current_process() if cur_status == status: continue status_attr.set_status(status) update_column = 'time_update' if update_column in self.sobject.get_attr_names(): self.sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False) self.sobject.commit() # if this is successful, the store it in the status_log status_log = SObjectFactory.create("sthpw/status_log") status_log.set_value("login", Environment.get_user_name()) status_log.set_value("search_type", search_type) status_log.set_value("search_id", id) #status_log.set_value("status", "%s to %s" % (cur_status, status) ) status_log.commit() status_log.set_value("from_status", cur_status) status_log.set_value("to_status", status) # Call the finaled trigger Trigger.call(self, status)
def execute(my): web = WebContainer.get_web() # get the input names input_names = web.get_form_value(SerialStatusWdg.STATUS_CMD_INPUT).split('|') values = [] for input_name in input_names: value = web.get_form_value(input_name) if value: values.append(web.get_form_value(input_name)) # FIXME: HARDCODED Value for status column!!!! column = "status" for value in values: # get the sobject to be updated search_type,id,status = value.split("|") search = Search(search_type) search.add_id_filter(id) my.sobject = search.get_sobject() status_attr = my.sobject.get_attr(column) cur_status = status_attr.get_current_process() if cur_status == status: continue status_attr.set_status(status) update_column = 'time_update' if update_column in my.sobject.get_attr_names(): my.sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False) my.sobject.commit() # if this is successful, the store it in the status_log status_log = SObjectFactory.create("sthpw/status_log") status_log.set_value("login", Environment.get_user_name() ) status_log.set_value("search_type", search_type) status_log.set_value("search_id", id) #status_log.set_value("status", "%s to %s" % (cur_status, status) ) status_log.commit() status_log.set_value("from_status", cur_status) status_log.set_value("to_status", status) # Call the finaled trigger Trigger.call(my, status)
def execute(self): web = WebContainer.get_web() search_type = web.get_form_value("search_type") search_id = web.get_form_value("search_id") # check if item is already in the clipboard search = Search("sthpw/clipboard") search.add_filter("search_type", search_type) search.add_filter("search_id", search_id) search.add_filter("category", "select") if search.get_count(): # if is already selected then remove. item = search.get_sobject() item.delete() search = Search(search_type) search.add_id_filter(search_id) sobject = search.get_sobject() search_type_obj = sobject.get_search_type_obj() self.description = "Removed %s '%s' from clipboard" % ( search_type_obj.get_title(), sobject.get_code()) else: search = Search(search_type) search.add_id_filter(search_id) sobject = search.get_sobject() search_type_obj = sobject.get_search_type_obj() clipboard = SearchType.create("sthpw/clipboard") clipboard.set_value("search_type", search_type) clipboard.set_value("search_id", search_id) #TODO: set project_code as well clipboard.set_value("category", "select") clipboard.set_user() clipboard.commit() self.description = "Added %s '%s' to clipboard" % ( search_type_obj.get_title(), sobject.get_code())
def execute(self): web = WebContainer.get_web() search_type = web.get_form_value("search_type") search_id = web.get_form_value("search_id") # check if item is already in the clipboard search = Search("sthpw/clipboard") search.add_filter("search_type", search_type) search.add_filter("search_id", search_id) search.add_filter("category", "select") if search.get_count(): # if is already selected then remove. item = search.get_sobject() item.delete() search = Search(search_type) search.add_id_filter(search_id) sobject = search.get_sobject() search_type_obj = sobject.get_search_type_obj() self.description = "Removed %s '%s' from clipboard" % (search_type_obj.get_title(), sobject.get_code() ) else: search = Search(search_type) search.add_id_filter(search_id) sobject = search.get_sobject() search_type_obj = sobject.get_search_type_obj() clipboard = SearchType.create("sthpw/clipboard") clipboard.set_value("search_type", search_type) clipboard.set_value("search_id", search_id) #TODO: set project_code as well clipboard.set_value("category", "select") clipboard.set_user() clipboard.commit() self.description = "Added %s '%s' to clipboard" % (search_type_obj.get_title(), sobject.get_code() )
def init(self): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = self.get_current_sobject() if not sobject: if not self.__dict__.has_key("search_type"): web = WebContainer.get_web() self.search_type = web.get_form_value("search_type") self.search_id = web.get_form_value("search_id") if not self.search_type: self.add("No search type") return search = Search(self.search_type) search.add_id_filter(self.search_id) sobject = search.get_sobject() self.add("<h3>Design Review: Annotation</h3>") table = TableWdg(self.search_type) table.set_sobject(sobject) self.add(table) url = WebContainer.get_web().get_widget_url() url.set_option("widget", "AnnotateWdg") url.set_option("search_type", self.search_type) url.set_option("search_id", self.search_id) src = url.to_string() self.add("<h3>Click on image to add an annotation</h3>") self.add( "The annotation will be located where you clicked on the image") self.add(""" <iframe id="annotate_frame" scrolling="no" src="%s" style='width: 800; height: 450; margin-left: 30px; border: none;"> WARNING: iframes are not supported </iframe> """ % src)
def init(my): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = my.get_current_sobject() if not sobject: if not my.__dict__.has_key("search_type"): web = WebContainer.get_web() my.search_type = web.get_form_value("search_type") my.search_id = web.get_form_value("search_id") if not my.search_type: my.add("No search type") return search = Search(my.search_type) search.add_id_filter(my.search_id) sobject = search.get_sobject() my.add("<h3>Design Review: Annotation</h3>") table = TableWdg(my.search_type) table.set_sobject(sobject) my.add(table) url = WebContainer.get_web().get_widget_url() url.set_option("widget", "AnnotateWdg") url.set_option("search_type", my.search_type) url.set_option("search_id", my.search_id) src = url.to_string() my.add("<h3>Click on image to add an annotation</h3>") my.add("The annotation will be located where you clicked on the image") my.add( """ <iframe id="annotate_frame" scrolling="no" src="%s" style='width: 800; height: 450; margin-left: 30px; border: none;"> WARNING: iframes are not supported </iframe> """ % src )
def _execute_single(my, code, name=None): # only do actions if the edit button has been pressed from pyasm.web import WebContainer web = WebContainer.get_web() no_commit = (web.get_form_value("sobject_commit") == 'false') sobject = None if my.search_key: sobject = SearchKey.get_by_search_key(my.search_key) # this is needed for action handler below my.search_type = sobject.get_search_type() else: # get the search type and search id my.search_type = web.get_form_value("search_type") if my.search_type == "": raise EditCmdException( "Search type not found" ) search_id = web.get_form_value("search_id") if search_id == "": raise EditCmdException( "Search id not found" ) # get the search object based on these parameters if search_id == "" or search_id == "-1": sobject = SearchType.create(my.search_type) else: search = Search(my.search_type) search.add_id_filter( search_id ) sobject = search.get_sobject() # there has to be an sobject to edit if sobject == None: raise EditCmdException("No sobject found with search type [%s] and id [%s]" % (my.search_type, search_id) ) action_handlers = my._get_action_handlers() # set the sobject for each action handler for action_handler in action_handlers: action_handler.set_sobject(sobject) if action_handler.check(): if my.parent_key: action_handler.set_option('parent_key', my.parent_key) if my.connect_key: action_handler.set_option('connect_key', my.connect_key) action_handler.execute() # set the parent, if there is one and it's in insert if sobject.is_insert() and my.parent_key: sobject.add_relationship(my.parent_key) if sobject.is_insert(): action = "Inserted" else: action = "Updated" # before we commit, we set what got changed in the info update_data = sobject.update_data for key, value in update_data.items(): # don't include None if value != None: my.info[key] = value if code: sobject.set_value("code", code) # only fill in a new with the passed in name if it has been # specified if name: sobject.set_value("name", name) # commit the changes unless told not to. # NOTE: this prevents any connections to be made if not no_commit: try: if sobject.is_insert(): is_insert = True else: is_insert = False sobject.commit() # only connect on insert if is_insert and my.connect_key and my.connect_key != "__NONE__": sobject.connect(my.connect_key, "task") except SqlException, e: msg = "An error was encountered adding this item. The error reported was [%s]" % e raise SqlException(msg) # ask the sobject for the description my.add_description( sobject.get_update_description() )
def init(self): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = self.get_current_sobject() if not sobject: if not self.__dict__.has_key("search_type"): web = WebContainer.get_web() self.search_type = web.get_form_value("search_type") self.search_id = web.get_form_value("search_id") if not self.search_type: self.add("No search type") return search = Search(self.search_type) search.add_id_filter(self.search_id) sobject = search.get_sobject() snapshot = Snapshot.get_latest_by_sobject(sobject) # TODO: # this is a bit klunky snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value( "snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name()) # add the annotate js object script = HtmlElement.script("annotate = new Annotate()") self.add(script) # add the image self.add("<h3>Image Annotations</h3>") width = 600 img = HtmlElement.img(path) img.add_style("position: absolute") img.set_id("annotate_image") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 1") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") self.add(img) # test version = snapshot.get_value("version") if version != 1: last_version = version - 1 snapshot = Snapshot.get_by_version( \ self.search_type, self.search_id, version=last_version ) snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value( "snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name()) img = HtmlElement.img(path) img.set_id("annotate_image_alt") img.add_style("position: absolute") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 0") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") self.add(img) #script = HtmlElement.script("align_element('%s','%s')" % \ # ("annotate_image", "annotate_image_alt") ) #self.add(script) div = DivWdg() div.add_style("position: absolute") div.add_style("left: 620") div.add_style("top: 300") self.add(div) button = IconButtonWdg("Switch", IconWdg.REFRESH, True) button.add_event("onclick", "annotate.switch_alt()") div.add(button) button = IconButtonWdg("Opacity", IconWdg.LOAD, True) button.add_event("onclick", "annotate.set_opacity()") div.add(button) # add the new annotation div new_annotation_div = DivWdg() new_annotation_div.set_id("annotate_msg") new_annotation_div.set_class("annotate_new") new_annotation_div.add_style("top: 0") new_annotation_div.add_style("left: 0") title = DivWdg("Enter Annotation:") title.add_style("background-color: #000000") title.add_style("color: #ffffff") new_annotation_div.add(title) text = TextAreaWdg("annotate_msg") text.set_attr("cols", "30") text.set_attr("rows", "3") new_annotation_div.add(text) new_annotation_div.add("<br/>") cancel = ButtonWdg("Cancel") cancel.add_style("float: right") cancel.add_event("onclick", "toggle_display('annotate_msg')") new_annotation_div.add(cancel) submit = SubmitWdg("Add Annotation") submit.add_style("float: right") new_annotation_div.add(submit) new_annotation_div.add_style("display: none") new_annotation_div.add_style("position: absolute") self.add(new_annotation_div) # get all of the stored annotations for this image search = Search("sthpw/annotation") search.add_order_by("login") search.add_filter("file_code", file_code) annotations = search.get_sobjects() # sort by user sorted_annotations = {} for annotation in annotations: user = annotation.get_value("login") if not sorted_annotations.has_key(user): sorted_annotations[user] = [] sorted_annotations[user].append(annotation) buttons = [] for user, annotations in sorted_annotations.items(): button = IconButtonWdg(user, IconWdg.INSERT, True) button.add_event( "onclick", "annotate.show_marks('%s','%s')" % (user, len(annotations) - 1)) buttons.append(button) count = 0 for annotation in annotations: self.add(self.get_annotate_wdg(annotation, count)) count += 1 # add the user buttons table = Table() table.set_class("table") table.add_style("width: 0px") table.add_style("position: absolute") table.add_style("left: 620") table.add_style("top: 0") table.add_row() table.add_header("Annotations") for button in buttons: table.add_row() legend_wdg = DivWdg() legend_wdg.set_class("annotate_mark") legend_wdg.add_style("position: relative") legend_wdg.add(" ") table.add_cell(legend_wdg) table.add_cell(button) self.add(table) # add form elements hidden = HiddenWdg("mouse_xpos") self.add(hidden) hidden = HiddenWdg("mouse_ypos") self.add(hidden) hidden = HiddenWdg("file_code", file_code) self.add(hidden) # move the rest below self.add("<div style='height:300'> </div>")
def init(my): WebContainer.register_cmd("pyasm.widget.AnnotateCbk") sobject = my.get_current_sobject() if not sobject: if not my.__dict__.has_key("search_type"): web = WebContainer.get_web() my.search_type = web.get_form_value("search_type") my.search_id = web.get_form_value("search_id") if not my.search_type: my.add("No search type") return search = Search(my.search_type) search.add_id_filter(my.search_id) sobject = search.get_sobject() snapshot = Snapshot.get_latest_by_sobject(sobject) # TODO: # this is a bit klunky snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value("snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name() ) # add the annotate js object script = HtmlElement.script("annotate = new Annotate()") my.add(script) # add the image my.add("<h3>Image Annotations</h3>") width = 600 img = HtmlElement.img(path) img.add_style("position: absolute") img.set_id("annotate_image") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 1") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") my.add(img) # test version = snapshot.get_value("version") if version != 1: last_version = version - 1 snapshot = Snapshot.get_by_version( \ my.search_type, my.search_id, version=last_version ) snapshot_xml = snapshot.get_xml_value("snapshot") file_code = snapshot_xml.get_value("snapshot/file[@type='web']/@file_code") file = File.get_by_code(file_code) web_dir = snapshot.get_web_dir() path = "%s/%s" % (web_dir, file.get_full_file_name() ) img = HtmlElement.img(path) img.set_id("annotate_image_alt") img.add_style("position: absolute") img.add_style("left: 0px") img.add_style("top: 0px") img.add_style("opacity: 1.0") img.add_style("z-index: 0") img.add_style("width", width) img.add_event("onmouseup", "annotate.add_new(event)") my.add(img) #script = HtmlElement.script("align_element('%s','%s')" % \ # ("annotate_image", "annotate_image_alt") ) #my.add(script) div = DivWdg() div.add_style("position: absolute") div.add_style("left: 620") div.add_style("top: 300") my.add(div) button = IconButtonWdg("Switch", IconWdg.REFRESH, True) button.add_event("onclick", "annotate.switch_alt()") div.add(button) button = IconButtonWdg("Opacity", IconWdg.LOAD, True) button.add_event("onclick", "annotate.set_opacity()") div.add(button) # add the new annotation div new_annotation_div = DivWdg() new_annotation_div.set_id("annotate_msg") new_annotation_div.set_class("annotate_new") new_annotation_div.add_style("top: 0") new_annotation_div.add_style("left: 0") title = DivWdg("Enter Annotation:") title.add_style("background-color: #000000") title.add_style("color: #ffffff") new_annotation_div.add(title) text = TextAreaWdg("annotate_msg") text.set_attr("cols", "30") text.set_attr("rows", "3") new_annotation_div.add(text) new_annotation_div.add("<br/>") cancel = ButtonWdg("Cancel") cancel.add_style("float: right") cancel.add_event("onclick", "toggle_display('annotate_msg')") new_annotation_div.add( cancel ) submit = SubmitWdg("Add Annotation") submit.add_style("float: right") new_annotation_div.add( submit ) new_annotation_div.add_style("display: none") new_annotation_div.add_style("position: absolute") my.add(new_annotation_div) # get all of the stored annotations for this image search = Search("sthpw/annotation") search.add_order_by("login") search.add_filter("file_code", file_code) annotations = search.get_sobjects() # sort by user sorted_annotations = {} for annotation in annotations: user = annotation.get_value("login") if not sorted_annotations.has_key(user): sorted_annotations[user] = [] sorted_annotations[user].append(annotation) buttons = [] for user, annotations in sorted_annotations.items(): button = IconButtonWdg(user, IconWdg.INSERT, True) button.add_event("onclick", "annotate.show_marks('%s','%s')" % (user, len(annotations)-1) ) buttons.append(button) count = 0 for annotation in annotations: my.add( my.get_annotate_wdg(annotation,count) ) count += 1 # add the user buttons table = Table() table.set_class("table") table.add_style("width: 0px") table.add_style("position: absolute") table.add_style("left: 620") table.add_style("top: 0") table.add_row() table.add_header("Annotations") for button in buttons: table.add_row() legend_wdg = DivWdg() legend_wdg.set_class("annotate_mark") legend_wdg.add_style("position: relative") legend_wdg.add(" ") table.add_cell(legend_wdg) table.add_cell(button) my.add(table) # add form elements hidden = HiddenWdg("mouse_xpos") my.add(hidden) hidden = HiddenWdg("mouse_ypos") my.add(hidden) hidden = HiddenWdg("file_code", file_code) my.add(hidden) # move the rest below my.add("<div style='height:300'> </div>")
def _execute_single(my, code, name=None): # only do actions if the edit button has been pressed from pyasm.web import WebContainer web = WebContainer.get_web() no_commit = (web.get_form_value("sobject_commit") == 'false') sobject = None if my.search_key: sobject = SearchKey.get_by_search_key(my.search_key) if not sobject: raise TacticException('This search key [%s] no longer exists.'%my.search_key) # this is needed for action handler below my.search_type = sobject.get_search_type() else: # get the search type and search id my.search_type = web.get_form_value("search_type") if my.search_type == "": raise EditCmdException( "Search type not found" ) search_id = web.get_form_value("search_id") # get the search object based on these parameters if search_id == "" or search_id == "-1": sobject = SearchType.create(my.search_type) else: search = Search(my.search_type) search.add_id_filter( search_id ) sobject = search.get_sobject() # there has to be an sobject to edit if sobject == None: raise EditCmdException("No sobject found with search type [%s] and id [%s]" % (my.search_type, search_id) ) action_handlers = my._get_action_handlers() # set the sobject for each action handler for action_handler in action_handlers: action_handler.set_sobject(sobject) if action_handler.check(): if my.parent_key: action_handler.set_option('parent_key', my.parent_key) if my.connect_key: action_handler.set_option('connect_key', my.connect_key) action_handler.execute() # set the parent, if there is one and it's in insert if sobject.is_insert() and my.parent_key: sobject.add_relationship(my.parent_key) if sobject.is_insert(): action = "Inserted" else: action = "Updated" # before we commit, we set what got changed in the info update_data = sobject.update_data for key, value in update_data.items(): # don't include None if value != None: my.info[key] = value if code: sobject.set_value("code", code) # only fill in a new with the passed in name if it has been # specified if name: sobject.set_value("name", name) # commit the changes unless told not to. # NOTE: this prevents any connections to be made if not no_commit: try: if sobject.is_insert(): is_insert = True else: is_insert = False sobject.commit() # only connect on insert if is_insert and my.connect_key and my.connect_key != "__NONE__": sobject.connect(my.connect_key, "task") except SqlException, e: msg = "An error was encountered adding this item. The error reported was [%s]" % e raise SqlException(msg) # ask the sobject for the description my.add_description( sobject.get_update_description() )
def _execute_single(self, code, name=None): # only do actions if the edit button has been pressed from pyasm.web import WebContainer web = WebContainer.get_web() no_commit = (web.get_form_value("sobject_commit") == 'false') sobject = None if self.search_key: sobject = SearchKey.get_by_search_key(self.search_key) if not sobject: raise TacticException('This search key [%s] no longer exists.'%self.search_key) # this is needed for action handler below self.search_type = sobject.get_search_type() elif self.sobject: sobject = self.sobject self.search_type = sobject.get_search_type() else: # get the search type and search id self.search_type = web.get_form_value("search_type") if self.search_type == "": raise EditCmdException( "Search type not found" ) search_id = web.get_form_value("search_id") # get the search object based on these parameters if search_id == "" or search_id == "-1": sobject = SearchType.create(self.search_type) else: search = Search(self.search_type) search.add_id_filter( search_id ) sobject = search.get_sobject() # there has to be an sobject to edit if sobject == None: raise EditCmdException("No sobject found with search type [%s] and id [%s]" % (self.search_type, search_id) ) action_handlers = self._get_action_handlers() # set the sobject for each action handler for action_handler in action_handlers: action_handler.set_sobject(sobject) if action_handler.check(): if self.parent_key: action_handler.set_option('parent_key', self.parent_key) if self.connect_key: action_handler.set_option('connect_key', self.connect_key) action_handler.execute() # set the parent, if there is one and it's in insert if sobject.is_insert() and self.parent_key: sobject.add_relationship(self.parent_key) if sobject.is_insert(): action = "Inserted" else: action = "Updated" # before we commit, we set what got changed in the info update_data = sobject.update_data for key, value in update_data.items(): # don't include None if value != None: self.info[key] = value if code: sobject.set_value("code", code) # only fill in a new with the passed in name if it has been # specified if name: sobject.set_value("name", name) for key, value in self.extra_data.items(): sobject.set_value(key, value) # commit the changes unless told not to. # NOTE: this prevents any connections to be made if not no_commit: try: if sobject.is_insert(): is_insert = True else: is_insert = False sobject.commit(triggers=self.trigger_mode) # only connect on insert if is_insert and self.connect_key and self.connect_key != "__NONE__": sobject.connect(self.connect_key, "task") except SqlException as e: msg = "An error was encountered adding this item. The error reported was [%s]" % e raise SqlException(msg) # ask the sobject for the description self.add_description( sobject.get_update_description() ) # do a post action for action_handler in action_handlers: try: action_handler.post_execute() except Exception as e: print "WARNING: ", e self.sobject = sobject # post process each action handers, post commit for action_handler in action_handlers: action_handler.postprocess() action_desc = action_handler.get_description() if action_desc: self.add_description(action_desc) # add the necessary data for triggers self.sobjects.append(sobject) self.info['action'] = action self.info['search_key'] = SearchKey.get_by_sobject(sobject, use_id=True) self.info['sobject'] = sobject.get_sobject_dict() return sobject