def enable(self, id): """Enable a module .. :quickref: Module; Enable a module Requires the `manage_modules` permission. If successful, will return the module in ``module``. Otherwise, errors will be available in ``errors``. :param id: id of the module to enable. """ module = ModuleInfo(get_or_404(ModuleInfo.get_collection(), _id=id)) if 'error' in module: flash( "Cannot enable '{}' because of errors installing dependencies." .format(module['name']), 'danger') return validation_error(url_for('ModulesView:index')) # See if module is properly configured module_class = get_class(module['path'], module['class']) module_class.info = module try: module_class() except MissingConfiguration as e: if e.name: flash( "You must configure '{}' before trying to enable '{}'". format(e.name, module['name']), 'warning') return validation_error( url_for('ModulesView:configuration', id=e.id)) else: flash( "You must configure '{}' before trying to enable it.". format(module['name']), 'warning') return validation_error( url_for('ModulesView:configure', id=module['_id'])) module.update_value('enabled', True) dispatcher.reload() readme = module.get_readme() if readme: flash(readme, 'persistent') return redirect({'module': clean_modules(module)}, url_for('ModulesView:index'))
def disable(self, id): """Disable a module .. :quickref: Module; Disable a module Requires the `manage_modules` permission. :param id: id of the module to disable. :>json Module module: resulting module. """ module = ModuleInfo(get_or_404(ModuleInfo.get_collection(), _id=id)) module.update_value('enabled', False) dispatcher.reload() return redirect({'module': clean_modules(module)}, url_for('ModulesView:index'))