Beispiel #1
0
def runTemp(request, validator=ProcedureAddForm):
    """
    临时流程执行
    """
    project_id = request.formdata.get("project_id")
    procedure = request.formdata.get("procedure")

    try:
        procedure_dict = json.loads(procedure)
    except Exception:
        return jsonify(test={"code": 1}, success=False, msg=u"表单数据格式错误")

    success, msg, procedure_checked = procedureCheck(project_id,
                                                     procedure_dict)
    if not success:
        return jsonify(test={"code": 2}, success=False, msg=msg)

    me = request.session.get("username")
    task = do_createTask(project_id, me, procedure_checked)

    ret = execute(task=task)

    return jsonify(test={
        "code": 4,
        "engine": ret,
        "id": task.get("id")
    },
                   success=True,
                   data=task.get("id"))
Beispiel #2
0
def delete(request, validator=ScriptDelForm):
    """
    删除脚本
    """
    project_id = request.formdata.get("project_id")
    scripts_id = request.formdata.get("scripts_id")

    try:
        scripts_id = list(set(json.loads(scripts_id)))
    except:
        return jsonify(code=2, success=False, msg=u"表单参数有误")

    for script_id in scripts_id:
        if not isinstance(script_id, int):
            return jsonify(code=3, success=False, msg=u"表单参数有误")

    scripts = Script.objects.filter(id__in=scripts_id, project_id=project_id)
    if not scripts.count():
        return jsonify(success=False, msg=u"脚本不存在")

    if ScriptNode.objects.filter(script__in=scripts).exists():
        return jsonify(success=False, msg=u"脚本正在被使用")
    scripts.delete()

    return jsonify(success=True)
Beispiel #3
0
def add(request, validator=ProcedureAddForm):
    """
    新建流程
    """
    project_id = request.formdata.get("project_id")
    procedure = request.formdata.get("procedure")

    try:
        procedure_dict = json.loads(procedure)
    except Exception:
        return jsonify(test={"code": 1}, success=False, msg=u"表单数据格式错误")

    success, msg, procedure_checked = procedureCheck(project_id,
                                                     procedure_dict,
                                                     check_unique=True)
    if not success:
        return jsonify(test={"code": 2}, success=False, msg=msg)

    me = request.session.get("username")
    procedure_id = do_addProcedure(me, project_id, procedure_checked)

    return jsonify(test={
        "code": 4,
        "id": procedure_id
    },
                   success=True,
                   msg=u"添加成功")
Beispiel #4
0
def delete(request, validator = ScriptDelForm):
    """
    删除脚本
    """
    project_id = request.formdata.get("project_id")
    scripts_id = request.formdata.get("scripts_id")

    try:
        scripts_id = list(set(json.loads(scripts_id)))
    except:
        return jsonify(code = 2, success = False, msg = u"表单参数有误")

    for script_id in scripts_id:
        if not isinstance(script_id, int):
            return jsonify(code = 3, success = False, msg = u"表单参数有误")

    scripts = Script.objects.filter(id__in = scripts_id, project_id = project_id)
    if not scripts.count():
        return jsonify(success = False, msg = u"脚本不存在")
        
    if ScriptNode.objects.filter(script__in = scripts).exists():
        return jsonify(success = False, msg = u"脚本正在被使用")
    scripts.delete()

    return jsonify(success = True)
Beispiel #5
0
def save(request, validator = ProcedureSaveForm):
    """
    保存流程
    """
    project_id = request.formdata.get("project_id")
    procedure_id = request.formdata.get("procedure_id")
    procedure = request.formdata.get("procedure")

    try:
        procedure_dict = json.loads(procedure)
    except Exception:
        return jsonify(test = {"code": 1}, success = False, msg = u"表单数据格式错误")

    try:
        old_procedure = Procedure.objects.get(id = procedure_id, project_id = project_id)
    except:
        return jsonify(test = {"code": 2}, success = False, msg = u"流程不存在")

    # 先删除原有数据再新建流程
    create_user = do_deleteProcedure(old_procedure)

    success, msg, procedure_checked = procedureCheck(project_id, procedure_dict, check_unique = True)
    if not success:
        return jsonify(test = {"code": 3}, success = False, msg = msg)

    me = request.session.get("username")
    do_addProcedure(me, project_id, procedure_checked, id = procedure_id, create_user = create_user)

    return jsonify(test = {"code": 4}, success = True, msg = u"保存成功")
Beispiel #6
0
def delete(request, validator=UserDelForm):
    """
    删除用户
    """
    project_id = request.formdata.get("project_id")
    users_id = request.formdata.get("users_id")

    try:
        users_id = list(set(json.loads(users_id)))
    except:
        return jsonify(success=False, msg=u"表单参数有误")

    for user_id in users_id:
        if not isinstance(user_id, int):
            return jsonify(success=False, msg=u"表单参数有误")

    users = User.objects.filter(id__in=users_id, project_id=project_id)
    if not users.count():
        return jsonify(success=False, msg=u"用户不存在")

    if ScriptNode.objects.filter(user__in=users).exists():
        return jsonify(success=False, msg=u"用户正在被使用")
    users.delete()

    return jsonify(success=True)
Beispiel #7
0
def add(request, validator = ProcedureAddForm):
    """
    新建流程
    """
    project_id = request.formdata.get("project_id")
    procedure = request.formdata.get("procedure")

    try:
        procedure_dict = json.loads(procedure)
    except Exception:
        return jsonify(test = {"code": 1}, success = False, msg = u"表单数据格式错误")

    success, msg, procedure_checked = procedureCheck(project_id, procedure_dict, check_unique = True)
    if not success:
        return jsonify(test = {"code": 2}, success = False, msg = msg)

    me = request.session.get("username")
    procedure_id = do_addProcedure(me, project_id, procedure_checked)

    return jsonify(test = {"code": 4, "id": procedure_id}, success = True, msg = u"添加成功")
Beispiel #8
0
def runTemp(request, validator = ProcedureAddForm):
    """
    临时流程执行
    """
    project_id = request.formdata.get("project_id")
    procedure = request.formdata.get("procedure")

    try:
        procedure_dict = json.loads(procedure)
    except Exception:
        return jsonify(test = {"code": 1}, success = False, msg = u"表单数据格式错误")

    success, msg, procedure_checked = procedureCheck(project_id, procedure_dict)
    if not success:
        return jsonify(test = {"code": 2}, success = False, msg = msg)

    me = request.session.get("username")
    task = do_createTask(project_id, me, procedure_checked)

    ret = execute(task = task)

    return jsonify(test = {"code": 4, "engine": ret, "id": task.get("id")}, success = True, data = task.get("id"))
Beispiel #9
0
def save(request, validator=ProcedureSaveForm):
    """
    保存流程
    """
    project_id = request.formdata.get("project_id")
    procedure_id = request.formdata.get("procedure_id")
    procedure = request.formdata.get("procedure")

    try:
        procedure_dict = json.loads(procedure)
    except Exception:
        return jsonify(test={"code": 1}, success=False, msg=u"表单数据格式错误")

    try:
        old_procedure = Procedure.objects.get(id=procedure_id,
                                              project_id=project_id)
    except:
        return jsonify(test={"code": 2}, success=False, msg=u"流程不存在")

    # 先删除原有数据再新建流程
    create_user = do_deleteProcedure(old_procedure)

    success, msg, procedure_checked = procedureCheck(project_id,
                                                     procedure_dict,
                                                     check_unique=True)
    if not success:
        return jsonify(test={"code": 3}, success=False, msg=msg)

    me = request.session.get("username")
    do_addProcedure(me,
                    project_id,
                    procedure_checked,
                    id=procedure_id,
                    create_user=create_user)

    return jsonify(test={"code": 4}, success=True, msg=u"保存成功")