def action(self) -> ActionResult: if html.request.var("_search"): # just commit to search form return None folder_url = self._folder.url() # Operations on SUBFOLDERS if html.request.var("_delete_folder"): if transactions.check_transaction(): self._folder.delete_subfolder(html.request.var("_delete_folder")) return redirect(folder_url) if html.request.has_var("_move_folder_to"): if transactions.check_transaction(): what_folder = watolib.Folder.folder(html.request.var("_ident")) target_folder = watolib.Folder.folder(html.request.var("_move_folder_to")) watolib.Folder.current().move_subfolder_to(what_folder, target_folder) return redirect(folder_url) # Operations on HOSTS # Deletion of single hosts delname = html.request.var("_delete_host") if delname and watolib.Folder.current().has_host(delname): watolib.Folder.current().delete_hosts([delname]) return redirect(folder_url) # Move single hosts to other folders if html.request.has_var("_move_host_to"): hostname = html.request.var("_ident") if hostname and watolib.Folder.current().has_host(hostname): target_folder = watolib.Folder.folder(html.request.var("_move_host_to")) watolib.Folder.current().move_hosts([hostname], target_folder) return redirect(folder_url) # bulk operation on hosts if not transactions.transaction_valid(): return redirect(folder_url) # Host table: No error message on search filter reset if html.request.var("_hosts_reset_sorting") or html.request.var("_hosts_sort"): return None selected_host_names = get_hostnames_from_checkboxes() if not selected_host_names: raise MKUserError(None, _("Please select some hosts before doing bulk operations on hosts.")) # Move if html.request.var("_bulk_move"): target_folder_path = html.request.var("_bulk_moveto", html.request.var("_top_bulk_moveto")) if target_folder_path == "@": raise MKUserError("_bulk_moveto", _("Please select the destination folder")) target_folder = watolib.Folder.folder(target_folder_path) watolib.Folder.current().move_hosts(selected_host_names, target_folder) flash(_("Moved %d hosts to %s") % (len(selected_host_names), target_folder.title())) return redirect(folder_url) # Move to target folder (from import) if html.request.var("_bulk_movetotarget"): self._move_to_imported_folders(selected_host_names) return redirect(folder_url) # Deletion if html.request.var("_bulk_delete"): return self._delete_hosts(selected_host_names) search_text = html.request.get_unicode_input_mandatory("search", "") for request_var, mode_name in [ ("_bulk_inventory", "bulkinventory"), ("_parentscan", "parentscan"), ("_bulk_edit", "bulkedit"), ("_bulk_cleanup", "bulkcleanup"), ]: if html.request.var(request_var): return redirect( self._folder.url(add_vars=[ ("mode", mode_name), ("search", search_text), ("selection", weblib.selection_id()), ])) return None
def action(self): if html.request.var("_search"): # just commit to search form return # Operations on SUBFOLDERS if html.request.var("_delete_folder"): if html.transaction_valid(): return self._delete_subfolder_after_confirm(html.request.var("_delete_folder")) return if html.request.has_var("_move_folder_to"): if html.check_transaction(): what_folder = watolib.Folder.folder(html.request.var("_ident")) target_folder = watolib.Folder.folder(html.request.var("_move_folder_to")) watolib.Folder.current().move_subfolder_to(what_folder, target_folder) return # Operations on HOSTS # Deletion of single hosts delname = html.request.var("_delete_host") if delname and watolib.Folder.current().has_host(delname): return delete_host_after_confirm(delname) # Move single hosts to other folders if html.request.has_var("_move_host_to"): hostname = html.request.var("_ident") if hostname: target_folder = watolib.Folder.folder(html.request.var("_move_host_to")) watolib.Folder.current().move_hosts([hostname], target_folder) return # bulk operation on hosts if not html.transaction_valid(): return # Host table: No error message on search filter reset if html.request.var("_hosts_reset_sorting") or html.request.var("_hosts_sort"): return selected_host_names = get_hostnames_from_checkboxes() if len(selected_host_names) == 0: raise MKUserError(None, _("Please select some hosts before doing bulk operations on hosts.")) if html.request.var("_bulk_inventory"): return "bulkinventory" if html.request.var("_parentscan"): return "parentscan" # Deletion if html.request.var("_bulk_delete"): return self._delete_hosts_after_confirm(selected_host_names) # Move if html.request.var("_bulk_move"): target_folder_path = html.request.var("bulk_moveto", html.request.var("_top_bulk_moveto")) if target_folder_path == "@": raise MKUserError("bulk_moveto", _("Please select the destination folder")) target_folder = watolib.Folder.folder(target_folder_path) watolib.Folder.current().move_hosts(selected_host_names, target_folder) return None, _("Moved %d hosts to %s") % (len(selected_host_names), target_folder.title()) # Move to target folder (from import) if html.request.var("_bulk_movetotarget"): return self._move_to_imported_folders(selected_host_names) if html.request.var("_bulk_edit"): return "bulkedit" if html.request.var("_bulk_cleanup"): return "bulkcleanup"