Exemple #1
0
def new_bin():
    form = BinForm()

    if form.validate_on_submit():
        pastebin = form.save(current_user)
        flash(_("Your paste-bin has been saved!"), "success")
        return redirect(url_for("paste.view_bin", bin_id=pastebin.id, slug=pastebin.slug))

    return render_template("paste/bin_form.html", form=form, mode="new")
Exemple #2
0
def edit_bin(bin_id, slug=None):
    pastebin = Bin.query.filter_by(id=bin_id).first()

    if not pastebin:
        abort(404)

    # Edit is more or less the same as creating a new one
    # You can not actually overwrite the existing one
    # You can just generate a new edited copy of it
    # Every user can edit a pastebin because you do not override the original one

    # Default Language is the one of the original (current/to edit) post
    form = BinForm(lang=pastebin.lang)
    if form.validate_on_submit():
        pastebin = form.save(current_user)
        flash(_("Your paste-bin has been saved!"), "success")
        return redirect(url_for("paste.view_bin", bin_id=pastebin.id, slug=pastebin.slug))
    else:
        form.description.data = "{}*".format(pastebin.description)
        form.content.data = pastebin.content

    return render_template("paste/bin_form.html", pastebin=pastebin, form=form, mode="edit")