Beispiel #1
0
def getGlobalTextForVarKey(request):
    textKey = request.GET.get("textKey", None)
    token = request.GET.get("token", None)

    if textKey == None:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="参数textKey 不能为空").toJson())

    if token == None:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="参数token 不能为空").toJson())

    getUser = TbUser.objects.filter(token=token, state=1)
    if len(getUser) == 0:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="参数token 查询用户错误").toJson())

    getText = TbGlobalText.objects.filter(textKey=textKey, state=1)
    if len(getText) == 0:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR,
                      message="参数varKey 查询全局变量错误").toJson())
    serviceConfList = ServiceConfService.getServiceConf()
    textData = getText.last().textValue
    retVar = {}
    if "[CONF=common]" in textData:
        retVar["common"] = substr(textData, "[CONF=common]", "[ENDCONF]")
    for serviceIndex in serviceConfList:
        if "[CONF=%s]" % serviceIndex["serviceConfKey"] not in textData:
            continue
        retVar[serviceIndex["serviceConfKey"]] = substr(
            textData, "[CONF=%s]" % serviceIndex["serviceConfKey"],
            "[ENDCONF]")

    return HttpResponse(ApiReturn(ApiReturn.CODE_OK, body=retVar).toJson())
Beispiel #2
0
def userHttpConfCheck(request):
    langDict = getLangTextDict(request)
    context = {}

    context["httpUserCenterUserHttpConfPage"] = "current-page"
    context["userName"] = request.session.get("userName")
    if not isRelease:
        context["env"] = "test"
    # 文本
    text = {}
    text["pageTitle"] = langDict["web"]["httpUserCenterUserHttpConfPageTitle"]
    text["subPageTitle"] = langDict["web"][
        "httpUserCenterUserHttpConfSubPageTitle"]
    context["text"] = text
    serviceConf = ServiceConfService.getServiceConf()
    context["services"] = serviceConf
    # context["uriServices"] = UriService.getUri(request)
    # context["dubboServices"] = dbModelListToListDict(TbConfigUri.objects.filter(state=1,protocol="DUBBO").order_by("level"))
    context["envConfList"] = HttpConfService.getAllHttpConf(request)
    # context["uri"] = UriService.getUri(request, "ALL")
    context["page"] = 1
    context["title"] = "环境配置"

    return render(request, "InterfaceTest/user_center/user_http_conf.html",
                  context)
Beispiel #3
0
def setGlobalVarForVarKey(request):
    varKey = request.POST.get("varKey", None)
    token = request.POST.get("token", None)
    varValue = request.POST.get("varValue", None)

    if varKey == None:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="参数varKey 不能为空").toJson())

    if token == None:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="参数token 不能为空").toJson())

    getUser = TbUser.objects.filter(token=token, state=1)
    if len(getUser) == 0:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR, message="参数token 查询用户错误").toJson())

    getVar = TbGlobalVars.objects.filter(varKey=varKey, state=1)
    if len(getVar) == 0:
        return HttpResponse(
            ApiReturn(ApiReturn.CODE_ERROR,
                      message="参数varKey 查询全局变量错误").toJson())
    if type(varValue) == type(""):
        if not isJson(varValue):
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_ERROR,
                          message="参数varValue不是JSON格式").toJson())
        varDict = json.loads(varValue)

    else:
        try:
            varDict = eval(varValue)
        except:
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_ERROR,
                          message="参数varValue不是JSON格式").toJson())
    serviceConfList = ServiceConfService.getServiceConf()
    serviceList = []
    for serviceIndex in serviceConfList:
        serviceList.append(serviceIndex["serviceConfKey"])

    varText = ""
    for index in varDict:
        if index != "common" and index not in serviceList:
            print(index)
            return HttpResponse(
                ApiReturn(ApiReturn.CODE_ERROR,
                          "varValue中存在Key不为HTTPConfKey").toJson())
        varText += "[CONF=%s]%s[ENDCONF]" % (index, varDict[index])
    varData = getVar.last()
    varData.varValue = varText
    varData.modBy = getUser.last().loginName
    varData.save()

    return HttpResponse(ApiReturn(ApiReturn.CODE_OK).toJson())