def user_edit(): def edit_model(form, model): setattr(model, "update_at", datetime.now()) setattr(model, "permissions", [ Permission.query.filter(Permission.id == permission).first() for permission in form['permissions'] ]) setattr(model, "roles", [ Role.query.filter(Role.id == role).first() for role in form['roles'] ]) if not model.create_at: # 新增用户 setattr(model, "create_at", datetime.now()) model.password = "******" if form['head_img']: setattr(model, "head_img", form['head_img'].encode()) else: setattr(model, "head_img", None) query = common_edit(User, edit_model=edit_model) if query: return jsonify(common.trueReturn('', 'success to alert data')) else: return jsonify(common.falseReturn('', 'fail to alert data'))
def register(): data = request.json register_user = User() form_to_model(data, register_user) register_user.status = True register_user.create_at = datetime.now() register_user.update_at = datetime.now() if register_user.save(): return jsonify(common.trueReturn(request.form, '用户注册成功')) else: return jsonify(common.falseReturn(request.form, '用户注册失败'))
def role_edit(): def edit_model(form, model): setattr(model, "permissions", [ Permission.query.filter(Permission.id == permission).first() for permission in form['permissions'] ]) query = common_edit(Role, edit_model=edit_model) if query: return jsonify(common.trueReturn('', 'success to alert data')) else: return jsonify(common.falseReturn('', 'fail to alert data'))
def role_delete(): query = common_delete(Role) if query: return jsonify(common.trueReturn('', 'success to delete data')) else: return jsonify(common.falseReturn('', 'fail to delete data'))
def internal_server_error(e): return jsonify(common.falseReturn('', "internal_server_error"))
def page_not_found(e): return jsonify(common.falseReturn('', "page_not_found"))
def page_not_found(e): return jsonify(common.falseReturn('', 'power is\'t enough'))
def group_delete(): query = common_delete(Group) if query: return jsonify(common.trueReturn('', 'success to delete data')) else: return jsonify(common.falseReturn('', 'fail to delete data'))