def tag_create(): if current_user.get_role() != 'admin': return abort(401) form = TagForm(request.form) if not form.validate(): return render_template("tags/new.html", form=form) name = form.name.data.strip() newTag = Tag(name.capitalize()) newTag.description = form.description.data db.session().add(newTag) db.session().commit() return redirect(url_for("tags_index"))
def tag_edit(tag_id): # POST is not accepted if current user is not an administrator if current_user.get_role() != 'admin': return abort(401) editedTag = Tag.query.get(tag_id) form = TagForm(request.form) if not form.validate(): faultyTag = Tag(request.form['name']) faultyTag.id = tag_id faultyTag.description = Tag(request.form['description']) return render_template("tags/edit.html", form=TagForm(), tag=faultyTag) name = form.name.data.strip() editedTag.name = name.capitalize() editedTag.description = form.description.data db.session().commit() return redirect(url_for("tags_index"))