Пример #1
0
def platform_operate(request):
    """
    平台保存,删除,更新
    :param request:
    :return:
    """
    if request.method == "GET":
        error = "非法请求方式!"
        logger.error(error)
        return render_to_response("item/temp.html", locals(), context_instance=RequestContext(request))
    elif request.method == "POST":
        # cmd in [update, save, delete]
        # cmd in [更新, 保存, 删除]
        response = {"success": False, "error": ""}
        try:
            # 获取参数
            cmd = request.POST.get("cmd", None)
            id = request.POST.get("id", None)

            m_nId = request.POST.get("m_nId", None)
            m_nId = int(m_nId) if m_nId else None

            m_nType = request.POST.get("m_nType", None)
            m_nType = int(m_nType) if m_nType else None

            m_strName = request.POST.get("m_strName", None)
            m_strAbbrName = request.POST.get("m_strAbbrName", None)
            m_strSoName = request.POST.get("m_strSoName", None)
            m_strConfig = request.POST.get("m_strConfig", None)
            m_strLogo = request.POST.get("m_strLogo", None)
            m_strQuoterTag = request.POST.get("m_strQuoterTag", None)
            m_strBrokerTag = request.POST.get("m_strBrokerTag", None)
            m_strfastTag = request.POST.get("m_strfastTag", None)

            if cmd is None:
                response["error"] = "CMD参数不能为空!"
                return HttpResponse(json.dumps(response), mimetype="application/json")

            param_is_none = False
            if not m_nId or not m_nType:
                param_is_none = True

            if (
                (cmd == "delete" and id is None)
                or (cmd == "save" and param_is_none)
                or (cmd == "update" and (param_is_none or id is None))
            ):
                response["error"] = "必要参数为空!"
                return HttpResponse(json.dumps(response), mimetype="application/json")

            # 创建
            if cmd == "save":
                # 判断是否已有
                param_exist = Platform.objects(m_strName=m_strName, m_nType=m_nType)

                if len(param_exist) > 0:
                    response["error"] = "已存在相同平台!请在原基础修改!"
                    return HttpResponse(json.dumps(response), mimetype="application/json")

                platform = Platform()
                platform.m_nId = m_nId
                platform.m_nType = m_nType
                platform.m_strName = m_strName
                platform.m_strAbbrName = m_strAbbrName
                platform.m_strSoName = m_strSoName
                platform.m_strConfig = m_strConfig
                platform.m_strLogo = m_strLogo
                platform.m_strQuoterTag = m_strQuoterTag
                platform.m_strBrokerTag = m_strBrokerTag
                platform.m_strfastTag = m_strfastTag
                platform.save()
                response["id"] = str(platform.id)

            # 更新
            elif cmd == "update":
                # 查找对象
                platform = Platform.objects(pk=id)
                if len(platform) == 0:
                    response["error"] = "未找到可更新对象!"
                    return HttpResponse(json.dumps(response), mimetype="application/json")
                platform = platform[0]
                platform.m_nId = m_nId
                platform.m_nType = m_nType
                platform.m_strName = m_strName
                platform.m_strAbbrName = m_strAbbrName
                platform.m_strSoName = m_strSoName
                platform.m_strConfig = m_strConfig
                platform.m_strLogo = m_strLogo
                platform.m_strQuoterTag = m_strQuoterTag
                platform.m_strBrokerTag = m_strBrokerTag
                platform.m_strfastTag = m_strfastTag
                platform.save()

            # 删除
            elif cmd == "delete":
                # 查找对象
                platform = Platform.objects(pk=id)
                if len(platform) == 0:
                    response["error"] = "未找到可删除对象!"
                    return HttpResponse(json.dumps(response), mimetype="application/json")

                platform = platform[0]
                path = request.path
                is_sys = None
                if path == "/customer/system/list/":
                    is_sys = True
                elif path == "/customer/list/":
                    is_sys = False
                else:
                    is_sys = False

                customers = Customer.objects(is_sys=is_sys).order_by("+tag")
                for customer in customers:
                    cus_modules = customer.modules
                    for module in cus_modules:
                        if module.group == "Broker实盘" or module.group == "Broker模拟":
                            name_list = module.name.split("_")
                            if len(name_list) >= 3:
                                if str(platform.m_nId) == name_list[2]:
                                    response["error"] = "该平台被客户[%s]使用,不能删除!" % str(customer.name)
                                    return HttpResponse(json.dumps(response), mimetype="application/json")

                platform.delete()

            else:
                response["error"] = "CMD指令异常!"
                return HttpResponse(json.dumps(response), mimetype="application/json")

            response["success"] = True
            response["error"] = "执行成功!"
            return HttpResponse(json.dumps(response), mimetype="application/json")
        except Exception as e:
            response["error"] = "系统异常![%s]" % str(e)
            logger.error(response["error"] + getTraceBack())
            return HttpResponse(json.dumps(response), mimetype="application/json")
Пример #2
0
def platform_operate(request):
    """
    平台保存,删除,更新
    :param request:
    :return:
    """
    if request.method == 'GET':
        error = "非法请求方式!"
        logger.error(error)
        return render_to_response('item/temp.html',
                                  locals(),
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        # cmd in [update, save, delete]
        # cmd in [更新, 保存, 删除]
        response = {'success': False, 'error': ''}
        try:
            # 获取参数
            cmd = request.POST.get('cmd', None)
            id = request.POST.get('id', None)

            m_nId = request.POST.get('m_nId', None)
            m_nId = int(m_nId) if m_nId else None

            m_nType = request.POST.get('m_nType', None)
            m_nType = int(m_nType) if m_nType else None

            m_strName = request.POST.get('m_strName', None)
            m_strAbbrName = request.POST.get('m_strAbbrName', None)
            m_strSoName = request.POST.get('m_strSoName', None)
            m_strConfig = request.POST.get('m_strConfig', None)
            m_strLogo = request.POST.get('m_strLogo', None)
            m_strQuoterTag = request.POST.get('m_strQuoterTag', None)
            m_strBrokerTag = request.POST.get('m_strBrokerTag', None)
            m_strfastTag = request.POST.get('m_strfastTag', None)

            if cmd is None:
                response["error"] = "CMD参数不能为空!"
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            param_is_none = False
            if not m_nId or not m_nType:
                param_is_none = True

            if (cmd == 'delete' and id is None) or \
                    (cmd == 'save' and param_is_none) or \
                    (cmd == 'update' and (param_is_none or id is None)):
                response["error"] = "必要参数为空!"
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            # 创建
            if cmd == 'save':
                # 判断是否已有
                param_exist = Platform.objects(m_strName=m_strName,
                                               m_nType=m_nType)

                if len(param_exist) > 0:
                    response["error"] = "已存在相同平台!请在原基础修改!"
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")

                platform = Platform()
                platform.m_nId = m_nId
                platform.m_nType = m_nType
                platform.m_strName = m_strName
                platform.m_strAbbrName = m_strAbbrName
                platform.m_strSoName = m_strSoName
                platform.m_strConfig = m_strConfig
                platform.m_strLogo = m_strLogo
                platform.m_strQuoterTag = m_strQuoterTag
                platform.m_strBrokerTag = m_strBrokerTag
                platform.m_strfastTag = m_strfastTag
                platform.save()
                response["id"] = str(platform.id)

            # 更新
            elif cmd == 'update':
                # 查找对象
                platform = Platform.objects(pk=id)
                if len(platform) == 0:
                    response["error"] = "未找到可更新对象!"
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")
                platform = platform[0]
                platform.m_nId = m_nId
                platform.m_nType = m_nType
                platform.m_strName = m_strName
                platform.m_strAbbrName = m_strAbbrName
                platform.m_strSoName = m_strSoName
                platform.m_strConfig = m_strConfig
                platform.m_strLogo = m_strLogo
                platform.m_strQuoterTag = m_strQuoterTag
                platform.m_strBrokerTag = m_strBrokerTag
                platform.m_strfastTag = m_strfastTag
                platform.save()

            # 删除
            elif cmd == 'delete':
                # 查找对象
                platform = Platform.objects(pk=id)
                if len(platform) == 0:
                    response["error"] = "未找到可删除对象!"
                    return HttpResponse(json.dumps(response),
                                        mimetype="application/json")

                platform = platform[0]
                path = request.path
                is_sys = None
                if path == '/customer/system/list/':
                    is_sys = True
                elif path == '/customer/list/':
                    is_sys = False
                else:
                    is_sys = False

                customers = Customer.objects(is_sys=is_sys).order_by('+tag')
                for customer in customers:
                    cus_modules = customer.modules
                    for module in cus_modules:
                        if module.group == "Broker实盘" or module.group == "Broker模拟":
                            name_list = module.name.split('_')
                            if len(name_list) >= 3:
                                if str(platform.m_nId) == name_list[2]:
                                    response[
                                        "error"] = "该平台被客户[%s]使用,不能删除!" % str(
                                            customer.name)
                                    return HttpResponse(
                                        json.dumps(response),
                                        mimetype="application/json")

                platform.delete()

            else:
                response["error"] = "CMD指令异常!"
                return HttpResponse(json.dumps(response),
                                    mimetype="application/json")

            response["success"] = True
            response["error"] = "执行成功!"
            return HttpResponse(json.dumps(response),
                                mimetype="application/json")
        except Exception as e:
            response["error"] = "系统异常![%s]" % str(e)
            logger.error(response["error"] + getTraceBack())
            return HttpResponse(json.dumps(response),
                                mimetype="application/json")