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 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'))
def edit_tag(tagid): if g.user.is_admin() != 1: flash('This user cannot edit tags!') return redirect(url_for('tags')) page_title = 'Edit tag' tag = Tag.query.get(int(tagid)) form = TagForm(request.form, obj=tag) if request.method == 'POST' and form.validate_on_submit(): # save new data in tag here form.populate_obj(tag) db.session.add(tag) db.session.commit() return redirect(url_for('tags')) return render_template('tag_editor.html', form_action = 'edit_tag', form = form, page_title = page_title)
def edit_tag(tagid): if g.user.is_admin() != 1: flash('This user cannot edit tags!') return redirect(url_for('tags')) page_title = 'Edit tag' tag = Tag.query.get(int(tagid)) form = TagForm(request.form, obj=tag) if request.method == 'POST' and form.validate_on_submit(): # save new data in tag here form.populate_obj(tag) db.session.add(tag) db.session.commit() return redirect(url_for('tags')) return render_template('tag_editor.html', form_action='edit_tag', form=form, page_title=page_title)
def add_tag(): if g.user.is_admin() != 1: flash('This user cannot add tags!') return redirect(url_for('tags')) form = TagForm(request.form) page_title = 'Add new tag' if request.method == 'POST' and form.validate_on_submit(): tag = Tag() form.populate_obj(tag) try: db.session.add(tag) db.session.commit() except IntegrityError, exc: reason = exc.message if reason.find('unique constraint'): flash('Tag name already found in the database') db.session.rollback() return redirect(url_for('add_tag')) flash('Tag saved successfully') return redirect(url_for('tags'))
def add_tag(): if g.user.is_admin() != 1: flash('This user cannot add tags!') return redirect(url_for('tags')) form = TagForm(request.form) page_title = 'Add new tag' if request.method == 'POST' and form.validate_on_submit(): tag = Tag() form.populate_obj(tag) try: db.session.add(tag) db.session.commit() except IntegrityError, exc: reason = exc.message if reason.find('unique constraint'): flash('Tag name already found in the database') db.session.rollback() return redirect(url_for('add_tag')) flash('Tag saved successfully') return redirect(url_for('tags'))