Exemplo n.º 1
0
def userRoles(request):
    accId = request.GET.get('id')
    userRole = sqlConn.getObjBywhere(models.UserRole, {'accId': accId})
    roleList = []
    for obj in userRole:
        role = sqlConn.getObjBywhere(models.Role, {'roleId': obj.roleId})[0]
        roleList.append(role)
    userjoin = ','.join([str(x.__repr__()) for x in roleList])
    return HttpResponse('[' + userjoin + ']')
Exemplo n.º 2
0
def getRolePerm(request):
    roleId = request.GET.get('roleId')
    rolePerm = sqlConn.getObjBywhere(models.RolePermission, {
        'roleId': roleId
    }).all()
    list = []
    for x in rolePerm:
        perm = sqlConn.getObjBywhere(models.Permission, {
            'pId': x.pId
        }).scalar()
        list.append(perm.pCode)
    return HttpResponse(json.dumps(list))
Exemplo n.º 3
0
def getPermTree(request):
    parentId = request.POST.get('id')
    if parentId != None:
        data = sqlConn.getObjBywhere(models.Permission, {'parentId': parentId})
    else:
        data = sqlConn.getObjBywhere(models.Permission, {'parentId': '00'})
    list = []
    for x in data:
        ptree = models.PermTree(id=x.pCode,
                                text=x.pName,
                                checked='',
                                children='')
        list.append(ptree)
    jsonList = ','.join([str(x) for x in list])
    return HttpResponse('[' + jsonList + ']')
Exemplo n.º 4
0
def allRoles(request):
    accId = request.GET.get('accId')
    userRoles = sqlConn.getObjBywhere(models.UserRole, {'accId': accId})
    roleList = sqlConn.getqueryAll(models.Role).all()
    uR = ','.join([str(x) for x in userRoles])
    rolejoin = ','.join([str(x) for x in roleList])
    return HttpResponse(
        json.dumps({
            'roles': '[' + rolejoin + ']',
            'userRole': '[' + uR + ']'
        }))
Exemplo n.º 5
0
def saveRole(request):
    roleId = request.POST.get('roleId')
    roleName = request.POST.get('roleName')
    roleDescribe = request.POST.get('roleDescribe')
    role = None
    if roleId != None:
        role = sqlConn.getObjBywhere(models.Role, {'roleId': roleId}).scalar()
    if role == None:
        role = models.Role(roleId=roleId,
                           roleName=roleName,
                           roleDescribe=roleDescribe)
        sqlConn.save(role)
        return HttpResponse(json.dumps({'status': 'OK', 'msg': '保存成功'}))
    else:
        return HttpResponse(json.dumps({'status': 'error', 'msg': '已经存在的账号'}))
Exemplo n.º 6
0
def rolePermSave(request):
    try:
        roleId = request.POST.get('roleId')
        pCodes = request.POST.get('pCodes')
        split = pCodes.split(',')
        if roleId:
            sqlConn.deletebyWhere(models.RolePermission, {'roleId': roleId})
            for pCode in split:
                if pCode != '':
                    perm = sqlConn.getObjBywhere(models.Permission, {
                        'pCode': pCode
                    }).scalar()
                    rp = models.RolePermission(roleId=roleId, pId=perm.pId)
                    sqlConn.save(rp)
        return HttpResponse(json.dumps({'status': 'OK', 'msg': '保存成功~'}))
    except:
        return HttpResponse(json.dumps({'status': 'error', 'msg': '保存失败~'}))
Exemplo n.º 7
0
def saveUser(request):
    acct = request.POST.get('acct')
    name = request.POST.get('name')
    sts = request.POST.get('sts')
    user = None
    if acct != None:
        user = sqlConn.getObjBywhere(models.User, {'acct': acct}).scalar()
    if user == None:
        user = models.User(id=uuid.uuid1().__str__().replace('-', ''),
                           name=name,
                           sts=sts,
                           acct=acct,
                           pwd='123456',
                           ctime=localtime)
        sqlConn.save(user)
        return HttpResponse(json.dumps({'status': 'OK', 'msg': '保存成功'}))
    else:
        return HttpResponse(json.dumps({'status': 'error', 'msg': '已经存在的账号'}))
Exemplo n.º 8
0
def savePerm(request):
    pId = request.POST.get('pId')
    pName = request.POST.get('pName')
    pCode = request.POST.get('pCode')
    parentId = request.POST.get('parentId')
    perm = None
    if pCode != None:
        perm = sqlConn.getObjBywhere(models.Permission, {
            'pCode': pCode
        }).scalar()
    if perm == None:
        perm = models.Permission(pId=uuid.uuid1().__str__().replace('-', ''),
                                 pCode=pCode,
                                 pName=pName,
                                 parentId=parentId)
        sqlConn.save(perm)
        return HttpResponse(json.dumps({'status': 'OK', 'msg': '保存成功'}))
    else:
        return HttpResponse(json.dumps({'status': 'error', 'msg': '已经存在的账号'}))
Exemplo n.º 9
0
def savePermPage(request):
    perm = None
    pId = request.GET.get('pId')
    if pId != None:
        perm = sqlConn.getObjBywhere(models.Permission, {'pId': pId}).scalar()
    return render(request, 'savePermPage.html', {'perm': perm})
Exemplo n.º 10
0
def saveRolePage(request):
    role = None
    roleId = request.GET.get('roleId')
    if roleId != None:
        role = sqlConn.getObjBywhere(models.Role, {'roleId': roleId}).scalar()
    return render(request, 'saveRolePage.html', {'role': role})
Exemplo n.º 11
0
def toSetPermPage(request):
    role = None
    id = request.GET.get('id')
    if id != None:
        role = sqlConn.getObjBywhere(models.Role, {'roleId': id})[0]
    return render(request, 'setRolePermPage.html', {'role': role})