def delete(root, name): if root in manager.config and name in manager.config[root]: log.info('Deleting %s %s' % (root, name)) del manager.config[root][name] manager.save_config() flash('Deleted %s.' % name, 'delete') return redirect(url_for('index'))
def edit_text(root, name): config_type = root.rstrip('s') context = {'name': name, 'root': root, 'config_type': config_type} if request.method == 'POST': context['config'] = request.form['config'] try: config = yaml.load(request.form['config']) except yaml.scanner.ScannerError as e: flash('Invalid YAML document: %s' % e, 'error') log.exception(e) else: # valid yaml, now run validator errors = Task.validate_config(config) if errors: for error in errors: flash(error, 'error') context['config'] = request.form['config'] else: manager.config[root][name] = config manager.save_config() context['config'] = yaml.dump(config, default_flow_style=False) if request.form.get('name') != name: # Renaming new_name = request.form.get('name') if new_name in manager.config[root]: flash( '%s with name %s already exists' % (config_type.capitalize(), new_name), 'error') else: # Do the rename manager.config[root][new_name] = manager.config[root][ name] del manager.config[root][name] manager.save_config() flash( '%s %s renamed to %s.' % (config_type.capitalize(), name, new_name), 'success') return redirect( url_for('.edit_text', root=root, name=new_name)) else: flash('Configuration saved', 'success') else: config = manager.config[root][name] if config: context['config'] = yaml.dump(config, default_flow_style=False) else: context['config'] = '' context['related'] = get_related(root, name) return render_template('configure/edit_text.html', **context)
def edit_text(root, name): config_type = root.rstrip('s') context = { 'name': name, 'root': root, 'config_type': config_type} if request.method == 'POST': context['config'] = request.form['config'] try: config = yaml.load(request.form['config']) except yaml.scanner.ScannerError as e: flash('Invalid YAML document: %s' % e, 'error') log.exception(e) else: # valid yaml, now run validator errors = Task.validate_config(config) if errors: for error in errors: flash(error, 'error') context['config'] = request.form['config'] else: manager.config[root][name] = config manager.save_config() context['config'] = yaml.dump(config, default_flow_style=False) if request.form.get('name') != name: # Renaming new_name = request.form.get('name') if new_name in manager.config[root]: flash('%s with name %s already exists' % (config_type.capitalize(), new_name), 'error') else: # Do the rename manager.config[root][new_name] = manager.config[root][name] del manager.config[root][name] manager.save_config() flash('%s %s renamed to %s.' % (config_type.capitalize(), name, new_name), 'success') return redirect(url_for('edit_text', root=root, name=new_name)) else: flash('Configuration saved', 'success') else: config = manager.config[root][name] if config: context['config'] = yaml.dump(config, default_flow_style=False) else: context['config'] = '' context['related'] = get_related(root, name) return render_template('configure/edit_text.html', **context)