def edit_category(id): title = "Edit Category" form = CategoryForm() category = Category.query.filter_by(id=id).first() if request.method == 'GET': form.title.data = category.title return render_template('categories/edit_category.html', title=title, form=form, category=category) if form.validate_on_submit(): title = request.form.get("title") category.title = title db.session.commit() flash('Votre category a été modifiée!') return redirect(url_for('category.categories')) else: return render_template('categories/edit_category.html', title=title, form=form, category=category)
def new_category(): form = CategoryForm() if form.validate_on_submit(): name = form.name.data category = Category(name=name) db.session.add(category) db.session.commit() flash('已创建分类', 'success') return redirect(url_for('.manage_category')) return render_template('admin/new_category.html', form=form)
def edit_category(category_id): form = CategoryForm() category = Category.query.get_or_404(category_id) if category.id == 1: flash('不能修改默认分类', 'warning') return redirect(url_for('web.index')) if form.validate_on_submit(): category.name = form.name.data db.session.commit() flash('已修改分类', 'success') return redirect(url_for('.manage_category')) form.name.data = category.name return render_template('admin/edit_category.html', form=form)
def system_category_add(): form = CategoryForm() if request.method == "POST": if form.validate_on_submit(): data = form.data result = Category(name=data['name'], keywords=data['keywords'], description=data['description'], image=upload_image(data['image']), smallimage=upload_image(data['smallimage'])) db.session.add(result) db.session.commit() flash("新增成功", "ok") return render_template("admin/system/category/category_add.html", form=form)
def category_add(): form = CategoryForm() if form.validate_on_submit(): new_category = CategoryModel( name=form.name.data, title=form.title.data, ) db.session.add(new_category) db.session.commit() return redirect(url_for('category')) return render_template('category_add.html', form=form)
def create(): form = CategoryForm() if form.validate_on_submit(): category = Category( title=form.title.data, description=form.description.data, created=datetime.utcnow(), created_by=current_user.id) db.session.add(category) db.session.commit() return redirect(url_for('category_blueprint.category', id=category.id)) return render_template('create-category.html', form=form)
def system_category_edit(id=None): if id is None: result = {"status": 0, "data": "没有数据"} return jsonify(result) form = CategoryForm() result = Category.query.get_or_404(id) if request.method == "POST": if form.validate_on_submit(): data = form.data result.name = data['name'] result.keywords = data['keywords'] result.description = data['description'] result.image = upload_image(data['image']) result.smallimage = upload_image(data['smallimage']) db.session.add(result) db.session.commit() flash("保存成功", "ok") return render_template("admin/system/category/category_edit.html", form=form, result=result)
def new_category(): title = "ajoutée categorie" form = CategoryForm() if request.method == 'GET': return render_template('categories/create_category.html', title=title, form=form) if form.validate_on_submit(): title = request.form.get("title") category = Category(title) db.session.add(category) db.session.commit() flash('Votre category a été ajoutée!') return redirect(url_for('category.new_category')) else: return render_template("categories/create_category.html", title=title, form=form)