def new_paste(): form = PasteForm(title=None, body=None, language=None, labels=None, explain=None, source=None) if form.validate_on_submit(): paste = db.Paste() paste.title = form.title.data # If a Paste with this slug already exists: paste.slug = slugify(form.title.data) pre_pastes = db.Paste.find({'slug': form.slug.data, 'deleted': False}) if pre_pastes.count(): paste.slug += '-%s' % (pre_pastes.count() + 1, ) paste.body = form.body.data paste.explanation = form.explanation.data paste.language = form.language.data paste.labels = form.labels.data paste.source = form.source.data paste.save() flash("Paste added") return redirect(url_for('pastebin.pastes')) return render_template('pastebin/new.html', form=form)
def new_paste(): form = PasteForm(title=None, body=None, language=None, labels=None, explain=None, source=None) if form.validate_on_submit(): paste = db.Paste() paste.title = form.title.data # If a Paste with this slug already exists: paste.slug = slugify(form.title.data) pre_pastes = db.Paste.find({'slug': form.slug.data, 'deleted': False}) if pre_pastes.count(): paste.slug += '-%s' % (pre_pastes.count() +1,) paste.body = form.body.data paste.explanation = form.explanation.data paste.language = form.language.data paste.labels = form.labels.data paste.source = form.source.data paste.save() flash("Paste added") return redirect(url_for('pastebin.pastes')) return render_template('pastebin/new.html', form=form)
def edit_paste(slug): paste = get_by_slug(slug) form = PasteForm(title=paste.title, slug=paste.title, body=paste.body, explanation=paste.explanation, language=paste.language, labels=paste.labels, source=paste.source) if form.validate_on_submit(): if form.title.data != paste.title: paste.slug = slugify(form.title.data) paste.title = form.title.data paste.body = form.body.data paste.explanation = form.explanation.data paste.language = form.language.data paste.labels = form.labels.data paste.source = form.source.data paste.save() flash('Paste edited') return redirect(url_for('pastebin.pastes')) return render_template('pastebin/edit.html', paste=paste, form=form)
def edit_paste(slug): paste = get_by_slug(slug) form = PasteForm(title = paste.title, slug = paste.title, body = paste.body, explanation = paste.explanation, language = paste.language, labels = paste.labels, source = paste.source) if form.validate_on_submit(): if form.title.data != paste.title: paste.slug = slugify(form.title.data) paste.title = form.title.data paste.body = form.body.data paste.explanation = form.explanation.data paste.language = form.language.data paste.labels = form.labels.data paste.source = form.source.data paste.save() flash('Paste edited') return redirect(url_for('pastebin.pastes')) return render_template('pastebin/edit.html', paste = paste, form = form)