コード例 #1
0
def rolesList(context,
              main=None,
              add=None,
              filterinfo=None,
              session=None,
              params=None,
              curvalue=None,
              startswith=None,
              firstrecord=None,
              recordcount=None):
    u'''Функция list для селектора выбора ролей. '''

    roles = RolesCursor(context)
    roles.setFilter(
        'id', """!'editor'&!'reader'&@%s'%s'%%""" %
        ("%" * (not startswith), curvalue.replace("'", "''")))
    roles.orderBy('id')
    roles.limit(firstrecord, recordcount)

    recordList = ArrayList()
    if roles.tryFindSet():
        while True:
            rec = DataRecord()
            rec.setId(unicode(roles.id))
            rec.setName(roles.id)
            recordList.add(rec)
            if not roles.nextInSet():
                break

    return ResultSelectorData(recordList, 0)
コード例 #2
0
def rolesList(context,
              main=None,
              add=None,
              filterinfo=None,
              session=None,
              params=None,
              curvalue="",
              startswith=False,
              firstrecord=0,
              recordcount=None):
    u'''Функция list селектора типа элемента. '''
    # raise Exception(curvalue)
    recordList = ArrayList()
    roles = RolesCursor(context)
    roles.setFilter(
        'description',
        "@%s'%s'%%" % ("%" * (not startswith), curvalue.replace("'", "''")))
    roles.orderBy('id')
    roles.limit(firstrecord, recordcount)
    if roles.tryFindSet():
        while True:
            rec = DataRecord()
            rec.setId(roles.id)
            rec.setName(
                '%s - %s' %
                (roles.id, roles.description if roles.description else ''))
            recordList.add(rec)
            if not roles.nextInSet():
                break
    return ResultSelectorData(recordList, 0)
コード例 #3
0
def gridData(context, main=None, add=None, filterinfo=None,
             session=None, elementId=None, sortColumnList=None, firstrecord=None, pagesize=None):
    u'''Функция получения данных для грида. '''

    # Создание экземпляра курсора разрешения
    roles = RolesCursor(context)
    # Определяем переменную для JSON данных
    data = {"records":{"rec":[]}}
    # Проходим по таблице и заполняем data
    specialRoles = ["!'editor'", "!'reader'"]

    roles.setFilter("id", '&'.join(specialRoles))
    if sortColumnList:
        sortName = toHexForXml(sortColumnList[0].id)
        sortType = unicode(sortColumnList[0].sorting).lower()
    else:
        sortName = None

    _header = {"roleId": ["~~id"],
               "id": [u"Роль"],
               "description": [u"Описание"],

               "properties": [u"properties"]
               }
    for column in _header:
        _header[column].append(toHexForXml(_header[column][0]))
        if sortName == _header[column][1]:
            roles.orderBy("%s %s" % (column, sortType))

    roles.limit(firstrecord - 1, pagesize)
    if roles.tryFindSet():
        while True:
            rolesDict = {}
            rolesDict[_header["roleId"][1]] = roles.id
            for column in [x for x in _header.keys() if x not in ("roleId", "properties")]:
                rolesDict[_header[column][1]] = getattr(roles, column) or ''

            rolesDict['properties'] = {"event": {"@name":"row_single_click",
                                                 "action": {"#sorted": [{"main_context": 'current'},
                                                                        {"datapanel":{'@type':"current",
                                                                                      '@tab':"current",
                                                                                      "element":{"@id":"id_perm_roles_grid"}
                                                                                      }
                                                                         }]
                                                            }
                                                 }
                                       }
            data["records"]["rec"].append(rolesDict)
            if not roles.nextInSet():
                break

    res = XMLJSONConverter.jsonToXml(json.dumps(data))
    return JythonDTO(res, None)
コード例 #4
0
def gridData(context,
             main=None,
             add=None,
             filterinfo=None,
             session=None,
             elementId=None,
             sortColumnList=None,
             firstrecord=None,
             pagesize=None):
    u'''Функция получения данных для грида. '''

    # Создание экземпляра курсора разрешения
    roles = RolesCursor(context)
    rolesPermissions = rolesCustomPermsCursor(context)
    if 'currentRecordId' in session:
        currId = json.loads(session)['sessioncontext']['related'][
            'gridContext']['currentRecordId']
        rolesPermissions.setRange("permissionId", currId)

    roles.orderBy("id")
    # Определяем переменную для JSON данных

    data = {"records": {"rec": []}}
    _header = {
        "id": ["~~id"],
        "roleId": [u"Роль"],
        "description": [u"Описание"],
        "exists": [u" "],
        "properties": [u"properties"]
    }

    for column in _header:
        _header[column].append(toHexForXml(_header[column][0]))

    # Считываем параметры сортировки
    if sortColumnList:
        sortName = sortColumnList[0].id
        sortType = unicode(sortColumnList[0].sorting).lower()
    else:
        sortName = None
    # Проходим по таблице и заполняем data
    if roles.tryFindSet():
        while True:
            permDict = {}
            permDict[_header["id"][1]] = json.dumps({
                "permission": currId,
                "role": roles.id
            })
            permDict[_header["roleId"][1]] = roles.id
            permDict[_header["description"][1]] = roles.description
            rolesPermissions.setRange("roleid", roles.id)
            permDict[_header["exists"][1]] = rolesPermissions.count(
            ) > 0 if rolesPermissions.count() else ''
            permDict[_header["properties"][1]] = {
                "event": {
                    "@name": "row_single_click",
                    "action": {
                        "#sorted": [{
                            "main_context": 'current'
                        }, {
                            "datapanel": {
                                '@type': "current",
                                '@tab': "current"
                            }
                        }]
                    }
                }
            }

            data["records"]["rec"].append(permDict)
            if not roles.nextInSet():
                break

    for column in _header:
        if sortName == _header[column][0]:
            keyField = column if sortName else 'exists'
            data["records"]["rec"].sort(key=lambda x:
                                        (x[_header["%s" % keyField][1]]),
                                        reverse=(sortType == 'desc'))
            data["records"]["rec"] = data["records"]["rec"][firstrecord -
                                                            1:firstrecord - 1 +
                                                            pagesize]
    res = XMLJSONConverter.jsonToXml(json.dumps(data))
    return JythonDTO(res, None)