def delete_host_after_confirm(delname): c = wato_confirm( _("Confirm host deletion"), _("Do you really want to delete the host <tt>%s</tt>?") % delname) if c: watolib.Folder.current().delete_hosts([delname]) # Delete host files return "folder" elif c is False: # not yet confirmed return "" return None # browser reload
def _delete_hosts_after_confirm(self, host_names): c = wato_confirm( _("Confirm deletion of %d hosts") % len(host_names), _("Do you really want to delete the %d selected hosts?") % len(host_names)) if c: self._folder.delete_hosts(host_names) return "folder", _("Successfully deleted %d hosts") % len( host_names) elif c is False: # not yet confirmed return "" return None # browser reload
def _delete_subfolder_after_confirm(self, subfolder_name): subfolder = self._folder.subfolder(subfolder_name) msg = _("Do you really want to delete the folder %s?") % subfolder.title() if not config.wato_hide_filenames: msg += _(" Its directory is <tt>%s</tt>.") % subfolder.filesystem_path() num_hosts = subfolder.num_hosts_recursively() if num_hosts: msg += _( " The folder contains <b>%d</b> hosts, which will also be deleted!") % num_hosts c = wato_confirm(_("Confirm folder deletion"), msg) if c: self._folder.delete_subfolder(subfolder_name) # pylint: disable=no-member return "folder" elif c is False: # not yet confirmed return "" return None # browser reload
def _delete_subfolder_after_confirm(self, subfolder_name) -> ActionResult: subfolder = self._folder.subfolder(subfolder_name) msg = _("Do you really want to delete the folder %s?") % subfolder.title() if not config.wato_hide_filenames: msg += _(" Its directory is <tt>%s</tt>.") % subfolder.filesystem_path() num_hosts = subfolder.num_hosts_recursively() if num_hosts: msg += _( " The folder contains <b>%d</b> hosts, which will also be deleted!") % num_hosts c = wato_confirm(_("Confirm folder deletion"), msg) if c: self._folder.delete_subfolder(subfolder_name) return redirect(mode_url("folder", folder=self._folder.path())) if c is False: # not yet confirmed return FinalizeRequest(code=200) return None # browser reload
def action(self): if not html.transaction_valid(): return action_var = html.request.get_str_input("_action") if action_var is None: return if action_var != "delete": return self._handle_custom_action(action_var) confirm = wato_confirm(_("Confirm deletion"), self._delete_confirm_message()) if confirm is False: return False if not confirm: return html.check_transaction() # invalidate transid entries = self._store.load_for_modification() ident = html.request.get_ascii_input("_delete") if ident not in entries: raise MKUserError( "_delete", _("This %s does not exist.") % self._mode_type.name_singular()) if ident not in self._store.filter_editable_entries(entries): raise MKUserError( "_delete", _("You are not allowed to delete this %s.") % self._mode_type.name_singular()) self._validate_deletion(ident, entries[ident]) entry = entries.pop(ident) self._add_change( "delete", entry, _("Removed the %s '%s'") % (self._mode_type.name_singular(), ident)) self._store.save(entries) return None, _( "The %s has been deleted.") % self._mode_type.name_singular()
def action(self): varname = html.request.var("_varname") if not varname: return action = html.request.var("_action") config_variable = config_variable_registry[varname]() def_value = self._default_values[varname] if action == "reset" and not is_a_checkbox( config_variable.valuespec()): c = wato_confirm( _("Resetting configuration variable"), _("Do you really want to reset the configuration variable <b>%s</b> " "back to the default value of <b><tt>%s</tt></b>?") % (varname, config_variable.valuespec().value_to_text(def_value))) else: if not html.check_transaction(): return c = True # no confirmation for direct toggle if c: if varname in self._current_settings: self._current_settings[ varname] = not self._current_settings[varname] else: self._current_settings[varname] = not def_value msg = _("Changed Configuration variable %s to %s.") % ( varname, "on" if self._current_settings[varname] else "off") watolib.save_global_settings(self._current_settings) watolib.add_change("edit-configvar", msg, domains=[config_variable.domain()], need_restart=config_variable.need_restart()) if action == "_reset": return "globalvars", msg return "globalvars" elif c is False: return ""
def action(self): if html.request.var("_reset"): if not is_a_checkbox(self._valuespec): c = wato_confirm( _("Resetting configuration variable"), _("Do you really want to reset this configuration variable " "back to its default value?")) if c is False: return "" if c is None: return None elif not html.check_transaction(): return try: del self._current_settings[self._varname] except KeyError: pass msg: Union[ HTML, str] = _("Resetted configuration variable %s to its default." ) % self._varname else: new_value = self._valuespec.from_html_vars("ve") self._valuespec.validate_value(new_value, "ve") self._current_settings[self._varname] = new_value msg = _("Changed global configuration variable %s to %s.") \ % (self._varname, self._valuespec.value_to_text(new_value)) # FIXME: THIS HTML(...) is needed because we do not know what we get from value_to_text!! msg = HTML(msg) self._save() watolib.add_change("edit-configvar", msg, sites=self._affected_sites(), domains=[self._config_variable.domain()], need_restart=self._config_variable.need_restart()) page_menu = self.parent_mode() assert page_menu is not None return page_menu.name()
def _move_to_imported_folders(self, host_names_to_move): c = wato_confirm( _("Confirm moving hosts"), _('You are going to move the selected hosts to folders ' 'representing their original folder location in the system ' 'you did the import from. Please make sure that you have ' 'done an <b>inventory</b> before moving the hosts.')) if c is False: # not yet confirmed return "" elif not c: return None # browser reload # Create groups of hosts with the same target folder target_folder_names = {} for host_name in host_names_to_move: host = self._folder.host(host_name) imported_folder_name = host.attribute('imported_folder') if imported_folder_name is None: continue target_folder_names.setdefault(imported_folder_name, []).append(host_name) # Remove target folder information, now that the hosts are # at their target position. host.remove_attribute('imported_folder') # Now handle each target folder for imported_folder, host_names in target_folder_names.items(): # Next problem: The folder path in imported_folder refers # to the Alias of the folders, not to the internal file # name. And we need to create folders not yet existing. target_folder = self._create_target_folder_from_aliaspath( imported_folder) self._folder.move_hosts(host_names, target_folder) return None, _( "Successfully moved hosts to their original folder destinations.")