def note_create(): user = g.user error = "" if request.method == "POST": title = request.form.get("title", "") content = request.form.get("content", "") fmt = request.form.get("fmt", consts.NOTE_FMT_PLAIN) privacy = request.form.get("privacy", consts.STATUS_PRIVACY_PUBLIC) if request.form.get("cancel"): return redirect("/i") # submit error = check_note(title, content) if not error: note = Note.add(g.user.id, title, content, fmt, privacy) if note: flash(u"日记写好了,看看吧", "tip") return redirect("/note/%s" % note.id) else: error = "添加日记的时候失败了,真不走运,再试试吧^^" if error: flash(error.decode("utf8"), "error") return render_template("v2/note_create.html", consts=consts, **locals()) elif request.method == "GET": return render_template("v2/note_create.html", consts=consts, **locals()) else: abort("wrong_http_method")
def note_create(): error = "" if request.method == "POST": title = request.form.get("title", "") content = request.form.get("content", "") fmt = request.form.get("fmt", consts.NOTE_FMT_PLAIN) privacy = request.form.get("privacy", consts.STATUS_PRIVACY_PUBLIC) if request.form.get("cancel"): return redirect("/i") # submit error = check_note(title, content) if not error: note = Note.add(g.user.id, title, content, fmt, privacy) if note: flash(u"日记写好了,看看吧", "tip") return redirect("/note/%s" % note.id) else: error = "添加日记的时候失败了,真不走运,再试试吧^^" if error: flash(error.decode("utf8"), "error") return render_template("note_create.html", consts=consts, **locals()) elif request.method == "GET": return render_template("note_create.html", consts=consts, **locals()) else: abort("wrong_http_method")
def note(nid): note = Note.get(nid) if not note: abort(404, "no such note") title = note.title content = note.content fmt = note.fmt if fmt == consts.NOTE_FMT_MARKDOWN: content = markdown2.markdown(note.content) create_time = note.create_time return render_template("note.html", consts=consts, **locals())
def note(nid): note = Note.get(nid) if not note: abort(404, "no such note") r = check_access_note(note) if r: flash(r[1].decode("utf8"), "tip") return redirect(url_for("home")) title = note.title content = note.content fmt = note.fmt if fmt == consts.NOTE_FMT_MARKDOWN: content = markdown2.markdown(note.content, extras=["wiki-tables", "code-friendly"]) create_time = note.create_time user = User.get(note.user_id) return render_template("note.html", consts=consts, **locals())
def note(nid): note = Note.get(nid) if not note: abort(404, "no such note") r = check_access_note(note) if r: flash(r[1].decode("utf8"), "tip") return redirect(url_for("home")) title = note.title content = note.content fmt = note.fmt if fmt == consts.NOTE_FMT_MARKDOWN: content = markdown2.markdown(note.content, extras=["wiki-tables", "code-friendly"]) create_time = note.create_time user = User.get(note.user_id) return render_template("v2/note.html", consts=consts, **locals())
def note_edit(nid): note = Note.get(nid) if not note: abort(404, "no such note") if g.user.id != note.user_id: abort(403, "not edit privileges") error = "" if request.method == "GET": title = note.title content = note.content fmt = note.fmt privacy = note.privacy return render_template("note_edit.html", consts=consts, **locals()) elif request.method == "POST": # edit title = request.form.get("title", "") content = request.form.get("content", "") fmt = request.form.get("fmt", consts.NOTE_FMT_PLAIN) privacy = request.form.get("privacy", consts.STATUS_PRIVACY_PUBLIC) if request.form.get("cancel"): return redirect("/note/%s" % note.id) if request.form.get("submit"): error = check_note(title, content) if not error: note.update(title, content, fmt, privacy) flash(u"日记修改成功", "tip") return redirect("/note/%s" % note.id) else: flash(error.decode("utf8"), "error") return render_template("note_edit.html", consts=consts, **locals()) else: return redirect("/note/%s" % note.id)