def user_del(id): user = User.query.get_or_404(id) with db.auto_commit(): Oplog('删除用户:' + user.name + ',id:' + str(user.id)) db.session.delete(user) flash('会员删除成功~', 'ok') return redirect(url_for('admin.user_list', page=1))
def moviecol_del(id): moviecol = MovieCol.query.get_or_404(id) with db.auto_commit(): Oplog('删除动画收藏:' + moviecol.movie.title + ',id:' + str(moviecol.id)) db.session.delete(moviecol) flash('动画收藏删除成功~', 'ok') return redirect(url_for('admin.moviecol_list', page=1))
def preview_del(id): preview = Preview.query.get_or_404(id) with db.auto_commit(): Oplog('删除预告:' + preview.title + ',id:' + str(preview.id)) db.session.delete(preview) flash('预告删除成功~', 'ok') return redirect(url_for('admin.preview_list', page=1))
def movie_edit(id): movie = Movie.query.get_or_404(id) # 将file跟form表单内容整合 values = CombinedMultiDict([request.files, request.form]) # 强行加入id,让方便验证器验证唯一性 id_dict = MultiDict([('id', id)]) values = CombinedMultiDict([id_dict, values]) form = MovieEditForm(values) if request.method == 'POST' and form.validate(): if form.url.data != "": upload = Upload_file() movie.url = upload.video(form.url.data) if form.logo.data != "": upload = Upload_file() movie.logo = upload.video(form.logo.data) data = form.data # 存入url地址 data['url'] = movie.url data['logo'] = movie.logo # 将不是手动录入字段先保存修改 data['playnum'] = movie.playnum data['commentnum'] = movie.commentnum with db.auto_commit(): # 一键修改属性 movie.set_attr(data) db.session.add(movie) Oplog('修改电影:' + movie.title + ',id:' + str(movie.id)) flash('电影修改成功~', 'ok') return redirect(url_for('admin.movie_edit', id=id)) tags = Tag.query.all() return render_template('admin/movie_edit.html', movie=movie, tags=tags, form=form)
def auth_del(id): auth = Auth.query.get_or_404(id) with db.auto_commit(): Oplog('删除权限:' + auth.name + ',id:' + str(auth.id)) db.session.delete(auth) flash('删除权限成功~', 'ok') return redirect(url_for('admin.auth_list', page=1))
def movie_del(id): movie = Movie.query.get_or_404(id) with db.auto_commit(): Oplog('删除电影:' + movie.title + ',id:' + str(movie.id)) db.session.delete(movie) flash('电影成功删除~', 'ok') return redirect(url_for('admin.movie_list', page=1))
def tag_del(id): tag = Tag.query.get_or_404(id) with db.auto_commit(): Oplog('删除标签:' + tag.name + ',id:' + str(tag.id)) db.session.delete(tag) flash('标签删除成功~', 'ok') return redirect(url_for('admin.tag_list', page=1))
def comment_del(id): comment = Comment.query.get_or_404(id) with db.auto_commit(): Oplog('删除评论:' + comment.content + ',id:' + str(comment.id)) db.session.delete(comment) flash('评论删除成功~', 'ok') return redirect(url_for('admin.comment_list', page=1))
def role_del(id): role = Role.query.get_or_404(id) with db.auto_commit(): Oplog('删除角色:' + role.name + ',id:' + str(role.id)) db.session.delete(role) flash('删除角色成功~', 'ok') return redirect(url_for('admin.role_list', page=1))
def tag_add(): form = TagForm(request.form) if request.method == 'POST' and form.validate(): with db.auto_commit(): tag = Tag() tag.name = form.name.data db.session.add(tag) Oplog('添加标签:' + tag.name) flash('添加标签成功~', 'ok') return redirect(url_for('admin.tag_add')) return render_template('admin/tag_add.html', form=form)
def auth_add(): form = AuthAddForm(request.form) if request.method == 'POST' and form.validate(): with db.auto_commit(): auth = Auth() auth.set_attr(form.data) db.session.add(auth) Oplog('添加权限:' + auth.name) flash('添加权限成功~', 'ok') return redirect(url_for('admin.auth_add')) return render_template('admin/auth_add.html', form=form)
def pwd(): form = PwdForm(request.form) if request.method == 'POST' and form.validate(): admin = Admin.query.filter_by(name=session['admin']).first() with db.auto_commit(): admin.pwd = form.newpwd.data db.session.add(admin) Oplog('修改密码:' + admin.name + ',id:' + str(admin.id)) flash('密码修改成功,请重新登陆', 'ok') return redirect(url_for('admin.logout')) return render_template('admin/pwd.html', form=form)
def tag_edit(id): tag = Tag.query.get_or_404(id) form = TagForm(request.form) if request.method == 'POST' and form.validate(): with db.auto_commit(): tag.name = form.name.data db.session.add(tag) Oplog('修改标签:' + tag.name + ',id:' + str(tag.id)) flash('标签修改成功~', 'ok') return redirect(url_for('admin.tag_edit'), id=id) return render_template('admin/tag_edit.html', form=form, tag=tag, id=id)
def admin_add(): form = AdminAddForm(request.form) roles = Role.query.all() if request.method == 'POST' and form.validate(): with db.auto_commit(): admin = Admin() admin.set_attr(form.data) admin.is_super = AdminTypeEnum.NO_SUPER db.session.add(admin) Oplog('添加管理员:' + admin.name) flash('添加管理员成功~', 'ok') return redirect(url_for('admin.admin_add')) return render_template('admin/admin_add.html', form=form, roles=roles)
def auth_edit(id): id_dict = MultiDict([('id', id)]) values = CombinedMultiDict([id_dict, request.form]) auth = Auth.query.get_or_404(id) form = AuthEditForm(values) if request.method == 'POST' and form.validate(): with db.auto_commit(): auth.set_attr(form.data) db.session.add(auth) Oplog('修改权限:' + auth.name + ',id:' + str(auth.id)) flash('修改权限成功~', 'ok') return redirect(url_for('admin.auth_edit', id=id)) return render_template('admin/auth_edit.html', form=form, auth=auth)
def role_add(): auth_list = request.values.getlist("auths") auth_list = list_to_str(auth_list) id_dict = MultiDict([('auths', auth_list)]) values = CombinedMultiDict([id_dict, request.form]) form = RoleAddForm(values) auths = Auth.query.all() if request.method == 'POST' and form.validate(): with db.auto_commit(): role = Role() role.set_attr(form.data) db.session.add(role) Oplog('添加角色:' + role.name) flash('添加角色成功~', 'ok') return redirect(url_for('admin.role_add')) return render_template('admin/role_add.html', auths=auths, form=form)
def preview_add(): values = CombinedMultiDict([request.files, request.form]) form = PreviewAddForm(values) if request.method == 'POST' and form.validate(): upload = Upload_file() logo = upload.image(form.logo.data) data = form.data data['logo'] = logo with db.auto_commit(): preview = Preview() preview.set_attr(data) db.session.add(preview) Oplog('添加预告:' + preview.title) flash('预告添加成功~', 'ok') return redirect(url_for('admin.preview_add')) return render_template('admin/preview_add.html', form=form)
def role_edit(id): role = Role.query.get_or_404(id) auth_list = request.values.getlist("auths") auth_list = list_to_str(auth_list) auth_dict = MultiDict([('auths', auth_list)]) id_dict = MultiDict([('id', int(id))]) values = CombinedMultiDict([auth_dict, request.form, id_dict]) form = RoleEditForm(values) auths = Auth.query.all() if request.method == 'POST' and form.validate(): with db.auto_commit(): role.set_attr(form.data) db.session.add(role) Oplog('修改角色:' + role.name + ',id:' + str(role.id)) flash('修改角色成功~', 'ok') return redirect(url_for('admin.role_edit', id=id)) # 修改ORM需要放在最后,否则其他数据库操作都不能执行,系统报错 unprintable InternalError object role.auths = str_to_list(role.auths) return render_template('admin/role_edit.html', form=form, auths=auths, role=role)
def preview_edit(id): preview = Preview.query.get_or_404(id) values = CombinedMultiDict([request.files, request.form]) id_dict = MultiDict([('id', id)]) values = CombinedMultiDict([values, id_dict]) form = PreviewEditForm(values) if request.method == 'POST' and form.validate(): if form.logo.data != '': upload = Upload_file() preview.logo = upload.image(form.logo.data) data = form.data data['logo'] = preview.logo with db.auto_commit(): preview.set_attr(data) db.session.add(preview) Oplog('修改预告:' + preview.title + ',id:' + str(preview.id)) flash('预告修改成功~', 'ok') return redirect(url_for('admin.preview_edit', id=id)) return render_template('admin/preview_edit.html', preview=preview, form=form)
def movie_add(): # 将file跟form表单内容整合 values = CombinedMultiDict([request.files, request.form]) # id_dict=MultiDict([('id',10)]) # values=CombinedMultiDict([id_dict,values]) form = MovieAddForm(values) tags = Tag.query.all() if request.method == 'POST' and form.validate(): upload = Upload_file() file_url = upload.video(form.url.data) file_logo = upload.image(form.logo.data) values = form.data values['url'] = file_url values['logo'] = file_logo values['playnum'] = 0 values['commentnum'] = 0 with db.auto_commit(): movie = Movie() movie.set_attr(values) db.session.add(movie) Oplog('添加电影:' + movie.title) flash('电影添加成功~', 'ok') return redirect(url_for('admin.movie_add')) return render_template('admin/movie_add.html', tags=tags, form=form)