Example #1
0
def article_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(Article, getdata["id"])
        article_data = object_to_dict(data)
        #替换掉产品数据里面的TAGS
        tags = Crud.search_data(TagRelation,and_(TagRelation.relation_id==getdata["id"] , TagRelation.tag_type == 2),'create_time')
        if tags:
            article_data['tags'] = [v.tag_id for v in tags]
        return {"code": 1, "data": article_data}
    elif request.method == "PUT":
        data = request.form
        form = ArticleForm(data)
        if form.validate():
            #移除已保存的tag
            tags = Crud.search_data(TagRelation,and_(TagRelation.relation_id==data["id"] , TagRelation.tag_type == 2),'create_time')
            if tags:
                del_tags = Crud.clean_all(tags)
            #保存修改后的信息
            result = Crud.update(Article,data)
            # 如果有标签信息,根据产品的id和标签ID保存关联的标签数据
            if data['tags']:
                tags = data['tags'].split(',') 
                tag_data = [TagRelation(
                    tag_type = 2,
                    relation_id = data["id"],
                    tag_id =v
                ) for v in tags]
                Crud.add_all(tag_data)
            if result:
                op_log("修改文章 #%s" %  data["id"])
                return {"code": 1, "msg": '修改成功'}
            return {"code": 0, "msg": '修改失败,系统错误'} 
        return {"code": 0, "msg": form.get_errors()}
Example #2
0
def menu_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(Menu, getdata['id'])
        return jsonify({"code": 1, "data": object_to_dict(data)})
    elif request.method == "PUT":
        data = request.form
        form = MenuForm(data)
        if form.validate():
            result = Crud.update(Menu, data, 'name')
            if result:
                op_log("修改菜单#%s" % data["id"])
                return {"code": 1, "msg": "修改成功!"}
            return {"code": 0, "msg": "修改失败,系统错误或菜单已存在"}
        return {"code": 0, "msg": form.get_errors()}
Example #3
0
def auth_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(Auth, getdata["id"])
        return {"code": 1, "data": object_to_dict(data)}
    elif request.method == "PUT":
        data = request.form
        form = AuthForm(data)
        if form.validate():
            result = Crud.update(Auth, data, 'name')
            if result:
                op_log("修改权限 #%s" % data["id"])
                return {"code": 1, "msg": '修改成功'}
            return {"code": 0, "msg": '修改失败,系统错误或名称重复'}
        return {"code": 0, "msg": form.get_errors()}
Example #4
0
def adspace_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(Adspace, getdata['id'])
        return  {"code": 1, "data": object_to_dict(data)}
    elif request.method == "PUT":
        data = request.form
        form = AdspaceForm(data)
        if form.validate():
            result = Crud.update(Adspace,data,"name")
            if result:
                op_log("修改广告位#%s" %  data["id"])
                return {"code": 1, "msg": '修改成功'}
            return {"code": 0, "msg": '修改失败,系统错误或名称已存在'}    
        return {"code": 0, "msg": form.get_errors()}
Example #5
0
def reptile_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(ReptileRequest, getdata['id'])
        return jsonify({"code": 1, "data": object_to_dict(data)})
    elif request.method == "PUT":
        data = request.form
        form = ReptileForm(data)
        if form.validate():
            result = Crud.update(ReptileRequest, data, "name")
            if result:
                op_log("修改爬虫任务#%s" % data["id"])
                return {"code": 1, "msg": '修改成功'}
            return {"code": 0, "msg": '修改失败,系统错误或名称已存在'}
        return {"code": 0, "msg": form.get_errors()}
Example #6
0
def conf_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(Conf, getdata['id'])
        conf_data = object_to_dict(data)
        return jsonify({"code": 1, "data":conf_data})
    elif request.method == "PUT":
        data = request.form
        form = ConfForm(data)
        if form.validate():
            result = Crud.update(Conf,data,"ename")
            if result:
                op_log("修改配置项#%s" %  data["id"])
                return {"code":1, "msg": '修改成功'}
            return {"code":0, "msg": '修改失败,系统错误或调用名已存在'}
        return {"code": 0, "msg": form.get_errors()}
Example #7
0
def admin_edit():
    if request.method == 'GET':
        getdata = request.args
        data = Crud.get_data_by_id(Admin, getdata['id'])
        return {
            "code": 1,
            "id": data.id,
            "role_id": data.role_id,
            "username": data.username
        }
    elif request.method == "PUT":
        data = request.form
        result = Crud.update(Admin, data)
        if result:
            op_log("修改管理员角色#%s" % data["id"])
            return {"code": 1, "msg": '修改成功'}
        return {"code": 0, "msg": '修改失败,系统错误或管理员已存在'}
Example #8
0
def role_edit():
    if request.method == 'GET':
        getdata = request.args
        if int(getdata["id"]) == 1:
            return {"code": 0, "msg": "超级管理员不能修改!"}
        data = Crud.get_data_by_id(Role, getdata["id"])
        # auth_list = list(map(lambda v:int(v),(data.auths).split(",")))
        auth_list = (data.auths).split(",")
        role_data = {"name": data.name,"id":data.id, "auths": auth_list}
        return {"code": 1, "data": role_data}
    elif request.method == "PUT":
        data = request.form
        form = RoleForm(data)
        if form.validate():
            result = Crud.update(Role,data,'name')
            if result:
                op_log("修改角色 #%s" %  data["id"])
                return {"code": 1, "msg": '修改成功'}
            return {"code": 0, "msg": '修改失败,系统错误或名称已存在'}
        return {"code": 0, "msg": form.get_errors()}