def add_tag(): form = TagForm(request.form) if not form.validate(): flash('Tag name not valid') else: item = Tag(request.form['tag']) db.session.add(item) db.session.commit() flash('New tag created') return redirect(url_for('edit_tags'))
def add_tag(): # Called using AJAX if (g.user.role == ROLE_ADMIN): form = TagForm(request.form) if request.method == 'POST' and form.validate(): tag = Tag() form.populate_obj(tag) db.session.add(tag) db.session.commit() return jsonify(id=tag.id, name=tag.name) flash("Not valid tag") return jsonify(error="Not valid Tag") return jsonify(error="Not allowed")
def rename_tag(id): item = Tag.query.get(id) if item is None: flash('Tag was not found') else: form = TagForm(request.form) if not form.validate(): flash('Tag name not valid') else: item.name = request.form['tag'] db.session.commit() flash('Tag was updated') return redirect(url_for('edit_tags'))
def edit_tag(tag_id): tag = Tag.query.filter_by(id=tag_id).first() if (g.user.role == ROLE_ADMIN): form = TagForm(request.form, obj=tag) if request.method == 'POST' and form.validate(): form.populate_obj(tag) db.session.add(tag) db.session.commit() return redirect(url_for('show_tag', tag_id=tag.id)) return render_template('content_edit_tag.html', title=tag.name, form=form, user=g.user) return redirect(url_for('index'))