Пример #1
0
def GetEntity(request):
    try:
        key = request.POST['key']
    except:
        key = None
    entity = OrganizeService.GetEntity(None, key)
    response = HttpResponse()
    response.content = entity.toJSON()
    return response
Пример #2
0
def SubmitForm(request):
    try:

        IsOk = '1'
        try:
            key = request.GET['key']
        except:
            key = None

        try:
            Manager = request.GET['Manager']
        except:
            Manager = None

        try:
            AssistantManager = request.GET['AssistantManager']
        except:
            AssistantManager = None

        if not key:
            Message = "新增成功。"
        else:
            Message = "修改成功。"

        response = HttpResponse()
        curUser = CommonUtils.Current(response, request)



        if not key:
            org = Piorganize()
            org = org.loadJson(request)

            if org.managerid:
                org.manager = UserSerivce.GetEntity(CommonUtils.Current(response, request), org.managerid).realname
            if org.assistantmanagerid:
                org.assistantmanager = UserSerivce.GetEntity(CommonUtils.Current(response, request), org.assistantmanagerid).realname

            org.id = uuid.uuid4()
            org.deletemark = 0
            org.createuserid = curUser.Id
            org.createon = datetime.datetime.now()
            org.createby = curUser.RealName
            org.modifiedon = org.createon
            org.modifiedby = org.createby
            org.modifieduserid = curUser.Id

            returnCode, returnMessage, returnValue = OrganizeService.Add(None, org)

            if returnCode == StatusCode.statusCodeDic['OKAdd']:
                response.content = json.dumps({'Success': True, 'Data': IsOk, 'Message': returnMessage})
                return response
            else:
                response.content = json.dumps({'Success': False, 'Data': '0', 'Message': returnMessage})
                return response
        else:
            org = OrganizeService.GetEntity(None, key)
            if org:
                org = org.loadJson(request)

            if curUser:
                org.modifiedby = curUser.RealName
                org.modifieduserid = curUser.Id
                returnCode, returnMessage = OrganizeService.Update(None, org)
                if returnCode == StatusCode.statusCodeDic['OKUpdate']:
                    response.content = json.dumps({'Success': True, 'Data': IsOk, 'Message': returnMessage})
                    return response
                else:
                    response.content = json.dumps({'Success': False, 'Data': '0', 'Message': returnMessage})
                    return response
    except Exception as e:
        print(e)
        response = HttpResponse()
        response.content = json.dumps({'Success': False, 'Data': '0', 'Message': FrameworkMessage.MSG3020})
        return response