Пример #1
0
def mainproc(attributes):
    conn = ConnectionFactory.getInstance().acquire()
    try:
        stmt = conn.prepareCall(
            "{call [dbo].[regions_list_and_count](?,?,?,?,?,?,?,?,?,?)}")
        try:
            stmt.setString(1, attributes.getMainContext())
            stmt.setString(2, attributes.getAddContext())
            setSQLXMLParam(stmt, 3, attributes.getFilterinfo())
            setSQLXMLParam(stmt, 4, attributes.getSessionContext())
            stmt.setString(5, attributes.getParams())
            stmt.setString(6, attributes.getCurValue())
            stmt.setBoolean(7, attributes.getStartsWith())
            stmt.setInt(8, attributes.getFirstRecord())
            stmt.setInt(9, attributes.getRecordCount())
            stmt.registerOutParameter(10, Types.INTEGER)

            stmt.execute()

            records = getDataList(stmt.getResultSet())
            count = stmt.getInt(10)
            return ResultSelectorData(records, count)
        finally:
            stmt.close()
    finally:
        ConnectionFactory.getInstance().release(conn)

    return ResultSelectorData(None, 0)
Пример #2
0
def filtersList(context,
                main=None,
                add=None,
                filterinfo=None,
                session=None,
                params=None,
                curvalue=None,
                startswith=None,
                firstrecord=None,
                recordcount=None):
    u'''Функция для получения списка доступных фильтров по полю @key'''
    add = repair_add(add)
    recordList = ArrayList()
    for filter_dict in context.getData()[add]:
        if filter_dict['@key'] == 'unview':
            rec = DataRecord()
            rec.setId(filter_dict['@id'])
            rec.setName(filter_dict['@label'])
            rec.addParameter('type', filter_dict['@type'])
            rec.addParameter('randint', str(clock()))
            rec.addParameter('face', filter_dict['@face'])
            rec.addParameter('bound', filter_dict['@bound'])
            rec.addParameter('selector_data', filter_dict['@selector_data'])
            rec.addParameter('boolInput', filter_dict['@boolInput'])
            recordList.add(rec)
    return ResultSelectorData(recordList, 0)
Пример #3
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)
Пример #4
0
def usersCount(context,
               main=None,
               add=None,
               filterinfo=None,
               session=None,
               params=None,
               curvalue=None,
               startswith=None):
    #raise Exception(params)
    settings = Settings()
    if settings.isUseAuthServer() and settings.loginIsSubject():
        server = SecurityParamsFactory.getAuthServerUrl()
        sessionId = json.loads(session)["sessioncontext"]["sessionid"]
        users_xml = getUsersFromAuthServer(server, sessionId)
        count = 0
        for user in users_xml.getElementsByTagName("user"):
            if startswith and string.find(user.getAttribute("name"), curvalue)==0 or \
                    not startswith and string.find(user.getAttribute("name"), curvalue)>0:
                count += 1
        #count=len(users_xml.getElementsByTagName("user"))
    else:
        subject = subjectsCursor(context)
        #raise Exception(useAuthServer)
        subject.setFilter(
            'name', "@%s'%s'%%" %
            ("%" * (not startswith), curvalue.replace("'", "''")))
        count = subject.count()
    return ResultSelectorData(None, count)
Пример #5
0
def tablesCount(context,
                main=None,
                add=None,
                filterinfo=None,
                session=None,
                params=None,
                curvalue=None,
                startswith=None):
    u'''Функция count для селектора выбора таблиц. '''

    paramsXML = minidom.parseString(params)
    tables = TablesCursor(context)

    if paramsXML.getElementsByTagName('grainid')[0].childNodes:
        grainid = paramsXML.getElementsByTagName(
            'grainid')[0].childNodes[0].data
        tables.setFilter(
            'tablename', """@%s'%s'%%""" %
            ("%" * (not startswith), curvalue.replace("'", "''")))
        tables.setRange('grainid', grainid)
        count = tables.count()
    else:
        tables.setFilter(
            'tablename', """@%s'%s'%%""" %
            ("%" * (not startswith), curvalue.replace("'", "''")))
        count = tables.count()

    return ResultSelectorData(None, count)
Пример #6
0
def procList(context, main, add, filterinfo, session, params, curValue,
             startsWith, firstRecord, recordCount):
    print 'Get data of selector from Celesta Python procedure.'
    print 'User %s' % context.userId
    print 'main "%s".' % main
    print 'add "%s".' % add
    print 'filterinfo "%s".' % filterinfo
    print 'session "%s".' % session
    print 'params "%s".' % params
    print 'curValue "%s".' % curValue
    print 'startsWith "%s".' % startsWith
    print 'firstRecord "%s".' % firstRecord
    print 'recordCount "%s".' % recordCount

    recordList = ArrayList()
    for i in range(3):
        rec = DataRecord()
        rec.setId("item" + str(i))
        rec.setName("Item " + str(i))
        recordList.add(rec)

#    context.warning('dd2');
#    context.message('dd1', u'Заголовок4', u"solutions/default/resources/group_icon_default.png");

#    context.error('dd4', u'Заголовок4', u"solutions/default/resources/group_icon_default.png");

#    recordList = ArrayList()

    return ResultSelectorData(recordList, 0)
Пример #7
0
def customPermissionsTypesList(context,
                               main=None,
                               add=None,
                               filterinfo=None,
                               session=None,
                               params=None,
                               curvalue=None,
                               startswith=None,
                               firstrecord=None,
                               recordcount=None):
    u'''Функция list для селектора выбора ролей. '''

    customPermissionsTypes = customPermsTypesCursor(context)
    customPermissionsTypes.setFilter(
        'name', """@%s'%s'%%""" %
        ("%" * (not startswith), curvalue.replace("'", "''")))
    customPermissionsTypes.orderBy('name')
    customPermissionsTypes.limit(firstrecord, recordcount)

    recordList = ArrayList()
    for customPermissionsTypes in customPermissionsTypes.iterate():
        rec = DataRecord()
        rec.setId(unicode(customPermissionsTypes.name))
        rec.setName(customPermissionsTypes.name)
        recordList.add(rec)

    return ResultSelectorData(recordList, 0)
Пример #8
0
def usersList(context, main=None, add=None, filterinfo=None, session=None, params=None,
                curvalue=None, startswith=None, firstrecord=None, recordcount=None):
    u'''Функция list селектора типа элемента. '''
    settings=Settings()      
    recordList = ArrayList()
    #raise Exception(startswith, curvalue)
    if settings.isUseAuthServer() and settings.loginIsSubject():        
        sessionId=json.loads(session)["sessioncontext"]["sessionid"]
        server=SecurityParamsFactory.getAuthServerUrl()
        users_xml=getUsersFromAuthServer(server, sessionId)
        for user in users_xml.getElementsByTagName("user"):
            if startswith and string.find(user.getAttribute("name"), curvalue)==0 or \
                    not startswith and string.find(user.getAttribute("name"), curvalue)>0:
                rec = DataRecord()
                rec.setId(user.getAttribute("SID"))
                rec.setName(user.getAttribute("login"))
                recordList.add(rec)        
    else:
        subject = subjectsCursor(context)        
        subject.setFilter('name', "@%s'%s'%%" % ("%"*(not startswith), curvalue.replace("'","''")))        
        subject.orderBy('name')        
        subject.limit(firstrecord, recordcount)
        for subject in subject.iterate():
            rec = DataRecord()
            rec.setId(subject.sid)
            if subject.name is not None or subject.name!='':
                rec.setName(subject.name)
            else:
                rec.setName(u'[Имя не назначено!]')
            recordList.add(rec)        
    return ResultSelectorData(recordList, 0)
Пример #9
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)
Пример #10
0
def employeesList(context,
                  main=None,
                  add=None,
                  filterinfo=None,
                  session=None,
                  params=None,
                  curvalue="",
                  startswith=False,
                  firstrecord=0,
                  recordcount=None):
    u'''Функция list селектора типа элемента. '''
    settings = Settings()

    # raise Exception(curvalue)
    recordList = ArrayList()
    employeesGrain = settings.getEmployeesParam("employeesGrain")
    employeesTable = settings.getEmployeesParam("employeesTable")
    employeesId = settings.getEmployeesParam("employeesId")
    employeesName = settings.getEmployeesParam("employeesName")

    employeesCursor = tableCursorImport(employeesGrain, employeesTable)
    employees = employeesCursor(context)
    employees.setFilter(
        employeesName,
        "@%s'%s'%%" % ("%" * (not startswith), curvalue.replace("'", "''")))
    employees.orderBy(employeesName)
    employees.limit(firstrecord, recordcount)
    for employees in employees.iterate():
        rec = DataRecord()
        rec.setId(getattr(employees, employeesId))
        rec.setName(getattr(employees, employeesName))
        recordList.add(rec)
    return ResultSelectorData(recordList, 0)
Пример #11
0
def tablesList(context,
               main=None,
               add=None,
               filterinfo=None,
               session=None,
               params=None,
               curvalue=None,
               startswith=None,
               firstrecord=None,
               recordcount=None):
    u'''Функция list для селектора выбора таблиц. '''
    tables = TablesCursor(context)
    recordList = ArrayList()
    paramsXML = minidom.parseString(params)
    if paramsXML.getElementsByTagName('grainid')[0].childNodes:
        grainid = paramsXML.getElementsByTagName(
            'grainid')[0].childNodes[0].data
        tables.setRange('grainid', grainid)
    tables.setFilter(
        'tablename',
        "@%s'%s'%%" % ("%" * (not startswith), curvalue.replace("'", "''")))
    tables.orderBy('tablename')
    tables.limit(firstrecord, recordcount)

    if tables.tryFindSet():
        while True:
            rec = DataRecord()
            rec.setId(tables.tablename)
            rec.setName(tables.tablename)
            recordList.add(rec)
            if not tables.nextInSet():
                break

    return ResultSelectorData(recordList, 0)
Пример #12
0
def grainsList(context,
               main=None,
               add=None,
               filterinfo=None,
               session=None,
               params=None,
               curvalue=None,
               startswith=None,
               firstrecord=None,
               recordcount=None):
    u'''Функция list для селектора выбора гранул. '''

    grains = GrainsCursor(context)
    grains.setFilter(
        'id',
        "@%s'%s'%%" % ("%" * (not startswith), curvalue.replace("'", "''")))
    grains.orderBy('id')
    grains.limit(firstrecord, recordcount)

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

    return ResultSelectorData(recordList, 0)
Пример #13
0
def itemsListAndCount(context, main=None, add=None, filterinfo=None, session=None, params=None,
                      curvalue=None, startswith=None, firstrecord=None, recordcount=None):
    """Функция для получения списка элементов в пределе одного фильтра типа itemset"""
    all_fields, current = (x['filter'] for x in json.loads(XMLJSONConverter.xmlToJson(params))['schema']['filter'])
    add = repair_add(add)

    grain, table = context.getData()[add][0]["@tableName"].split('.')
    field_name = current["@id"]

    for necessary_field in context.getData()[add]:
        if field_name == necessary_field['@id']:
            current_field = necessary_field
            break

    selector_path = current_field['@selector_data']
    # if bound_status != 'bound':
    if selector_path:
        selector_path = selector_path.split('.')
        selector_module, selector_function_name = '.'.join(selector_path[:-1]), selector_path[-1]
        selector_module = import_module(selector_module)
        selector = getattr(selector_module, selector_function_name)

        return selector(context, main, add, filterinfo, session, params, curvalue, startswith, firstrecord, recordcount)
    cursor_instance = tableCursorImport(grain, table)
    cursor = cursor_instance(context)

    # Булевый флаг для определения, является ли поле числовым
    is_quotes = current_field['@type'] != 'float'

    curvalue = curvalue.strip()
    cursor.orderBy(field_name)
    recordList = ArrayList()
    # набираем список значений
    i = 0
    #     if curvalue:
    #         cursor.setRange(field_name, curvalue)
    while cursor.tryFirst() and i < (firstrecord + recordcount):
        current_name = getattr(cursor, field_name)
        if is_quotes:
            current_name = current_name.replace("'", "''")
        if (i >= firstrecord and not curvalue) or (i > firstrecord and curvalue):
            rec = DataRecord()
            rec.setId("rec%i" % i)
            rec.setName(
                unicode(current_name.replace('""', '"').replace("''", "'")) if is_quotes else unicode(current_name))
            recordList.add(rec)
        # Определение формы выведения в setFilter для разных типов значений
        current_filter = ">%s" % ("'%s'" % current_name if is_quotes else int(current_name))
        if curvalue:
            current_filter = """%s&@%s'%s'%%""" % (current_filter,
                                                   "%" * (not startswith),
                                                   curvalue.replace("'", "''"))
        # filtered_function(all_fields, add, cursor)
        cursor.setFilter(field_name, current_filter)
        i += 1
    return ResultSelectorData(recordList, i)
Пример #14
0
def rolesCount(context,
               main=None,
               add=None,
               filterinfo=None,
               session=None,
               params=None,
               curvalue="",
               startswith=False):
    roles = RolesCursor(context)
    roles.setFilter(
        'description',
        "@%s'%s'%%" % ("%" * (not startswith), curvalue.replace("'", "''")))
    count = roles.count()
    # raise Exception(count)
    return ResultSelectorData(None, count)
Пример #15
0
def filtersCount(context,
                 main=None,
                 add=None,
                 filterinfo=None,
                 session=None,
                 params=None,
                 curvalue=None,
                 startswith=None,
                 firstrecord=None,
                 recordcount=None):
    u'''Функция для получения числа доступных фильтров'''
    add = repair_add(add)
    displayed_filters_list = [
        x for x in context.getData()[add] if x['@key'] == 'unview'
    ]
    return ResultSelectorData(None, len(displayed_filters_list))
Пример #16
0
def procCount(context, main, add, filterinfo, session, params, curValue,
              startsWith):
    print 'Get count of selector from Celesta Python procedure.'
    print 'User %s' % context.userId
    print 'main "%s".' % main
    print 'add "%s".' % add
    print 'filterinfo "%s".' % filterinfo
    print 'session "%s".' % session
    print 'params "%s".' % params
    print 'curValue "%s".' % curValue
    print 'startsWith "%s".' % startsWith

    context.warning('dd1')
    #    context.error('dd1');

    return ResultSelectorData(None, 3)
Пример #17
0
def grainsCount(context,
                main=None,
                add=None,
                filterinfo=None,
                session=None,
                params=None,
                curvalue=None,
                startswith=None):
    u'''Функция count для селектора выбора гранул. '''

    grains = GrainsCursor(context)
    grains.setFilter(
        'id', """@%s'%s'%%""" %
        ("%" * (not startswith), curvalue.replace("'", "''")))
    count = grains.count()

    return ResultSelectorData(None, count)
Пример #18
0
def customPermissionsTypesCount(context,
                                main=None,
                                add=None,
                                filterinfo=None,
                                session=None,
                                params=None,
                                curvalue=None,
                                startswith=None):
    u'''Функция count для селектора выбора ролей. '''

    customPermissionsTypes = customPermsTypesCursor(context)
    customPermissionsTypes.setFilter(
        'name', """@%s'%s'%%""" %
        ("%" * (not startswith), curvalue.replace("'", "''")))
    count = customPermissionsTypes.count()

    return ResultSelectorData(None, count)
Пример #19
0
def procListAndCount(context, main, add, filterinfo, session, params, curValue,
                     startsWith, firstRecord, recordCount):
    print 'Get data and count of selector from Celesta Python procedure.'
    print 'User %s' % context.userId
    print 'main "%s".' % main
    print 'add "%s".' % add
    print 'filterinfo "%s".' % filterinfo
    print 'session "%s".' % session
    print 'params "%s".' % params
    print 'curValue "%s".' % curValue
    print 'startsWith "%s".' % startsWith
    print 'firstRecord "%s".' % firstRecord
    print 'recordCount "%s".' % recordCount

    data = procList(context, main, add, filterinfo, session, params, curValue,
                    startsWith, firstRecord, recordCount)
    count = procCount(context, main, add, filterinfo, session, params,
                      curValue, startsWith)
    return ResultSelectorData(data.getDataRecordList(), count.getCount())
Пример #20
0
def rolesCount(context,
               main=None,
               add=None,
               filterinfo=None,
               session=None,
               params=None,
               curvalue=None,
               startswith=None):
    u'''Функция count для селектора выбора ролей. '''

    #specialRoles = ["!'editor'", "!'reader'"]
    roles = RolesCursor(context)
    roles.setFilter(
        'id', """!'editor'&!'reader'&@%s'%s'%%""" %
        ("%" * (not startswith), curvalue.replace("'", "''")))

    count = roles.count()

    return ResultSelectorData(None, count)
Пример #21
0
def employeesCount(context,
                   main=None,
                   add=None,
                   filterinfo=None,
                   session=None,
                   params=None,
                   curvalue="",
                   startswith=False):
    settings = Settings()

    employeesGrain = settings.getEmployeesParam("employeesGrain")
    employeesTable = settings.getEmployeesParam("employeesTable")
    #    employeesId=getEmployeesParam("employeesId")
    employeesName = settings.getEmployeesParam("employeesName")

    employeesCursor = tableCursorImport(employeesGrain, employeesTable)
    employees = employeesCursor(context)
    employees.setFilter(
        employeesName,
        "@%s'%s'%%" % ("%" * (not startswith), curvalue.replace("'", "''")))
    count = employees.count()
    # raise Exception(count)
    return ResultSelectorData(None, count)