def area_edit(id=None): """ 地区编辑 """ form = AreaForm() form.submit.label.text = "修改" area = Area.query.get_or_404(id) if request.method == "GET": form.name.data = area.name form.is_recommended.data = area.is_recommended form.introduction.data = area.introduction if form.validate_on_submit(): data = form.data area_count = Area.query.filter_by(name=data["name"]).count() if area.name != data["name"] and area_count == 1: flash("地区已存在", "err") return redirect(url_for("admin.area_edit", id=area.id)) area.name = data["name"] area.is_recommended = int(data["is_recommended"]) area.introduction = data["introduction"] db.session.add(area) db.session.commit() flash("地区修改成功", "ok") return redirect(url_for("admin.area_edit", id=area.id)) return render_template("admin/area_edit.html", form=form, area=area)
def area_add(): form = AreaForm() if form.validate_on_submit(): data = form.data area = Area.query.filter_by(name=data["name"]).count() if area == 1: flash("地区已存在", "error") return redirect(url_for("admin.area_add")) area = Area(name=data["name"], is_recommended=data["is_recommended"], introduction=data["introduction"]) db.session.add(area) db.session.commit() addOplog("添加地区" + data["name"]) flash("地区添加成功", "ok") return redirect(url_for("admin.area_add")) return render_template("admin/area_add.html", form=form)
def area_add(): """ 添加Chapter """ form = AreaForm() if form.validate_on_submit(): data = form.data # 接收数据 area = Area.query.filter_by(name=data["name"]).count() # 说明已经有这个Chapter了 if area == 1: flash("Chapters already exist", "err") return redirect(url_for("admin.area_add")) area = Area(name=data["name"], is_recommended=data['is_recommended'], introduction=data['introduction']) db.session.add(area) db.session.commit() addOplog("Add chapter " + data["name"]) # 添加日志 flash("Successful addition of chapter", "ok") return redirect(url_for("admin.area_add")) return render_template("admin/chapter_add.html", form=form)