def create_cell(): form = CellForm() if form.validate_on_submit(): if Cell.query.filter_by(name=form.name.data).first(): flash('A cell with this name already exists.', 'danger') return render_template('cell.html', action=url_for('nbg.create_cell'), form=form) cell = Cell(form.name.data, CellType(form.cell_type.data), form.source.data) cell.collapsed = form.collapsed.data cell.set_metadata(form.cell_metadata.data) db.session.add(cell) db.session.commit() flash('Cell created', 'success') return redirect(url_for('nbg.list_cells')) return render_template('cell.html', action=url_for('nbg.create_cell'), form=form)