예제 #1
0
def read_per_page(offset, limit, order_by, order, search_params, per_page,
                  page):
    ''' Reads a page of users '''

    # Some validations
    offset = int(offset)
    if offset < 0:
        raise Exception("Value of param 'offset' should be >= 0")

    limit = int(limit)
    if limit < 1:
        raise Exception("Value of param 'limit' should be >= 1")

    order_by_values = ('id', 'username', 'orgchart_role_id', 'division_id',
                       'disabled')
    if order_by not in order_by_values:
        raise Exception(
            "Value of param 'order_by' should be one of the following: " +
            str(order_by_values))

    order_values = ('ASC', 'DESC', 'asc', 'desc')
    if order not in order_values:
        raise Exception(
            "Value of param 'order' should be one of the folowing: " +
            str(order_values))

    per_page = int(per_page)
    page = int(page)
    if per_page < 1 or page < 1:
        raise Exception("Value of params 'per_page' and 'page' should be >= 1")

    # Counting total number of items and fetching target page
    total_items = count_entities('users', search_params, True)
    if total_items > limit:
        total_items = limit

    total_pages = math.ceil(total_items / per_page)

    whole_pages_offset = per_page * (page - 1)
    if whole_pages_offset >= total_items:
        return [], total_items, total_pages

    target_items = total_items - whole_pages_offset
    if target_items > per_page:
        target_items = per_page

    entities = page_entities('users', offset + whole_pages_offset,
                             target_items, order_by, order, search_params,
                             True)

    for e in entities:
        del e['passwd']

    return (entities, total_items, total_pages)
예제 #2
0
def read_per_page(offset, limit, order_by, order, search_params, per_page,
                  page):
    ''' Reads a page of observations '''

    # Some validations
    offset = int(offset)
    if offset < 0:
        raise Exception("Value of param 'offset' should be >= 0")

    limit = int(limit)
    if limit < 1:
        raise Exception("Value of param 'limit' should be >= 1")

    order_by_values = ('id', 'observation_type_id', 'social_program_id',
                       'audit_id', 'fiscal_id', 'title', 'observation_code_id',
                       'observation_bis_code_id', 'doc_a', 'doc_b', 'doc_c',
                       'division_id', 'hdr_doc', 'hdr_reception_date',
                       'hdr_expiration1_date', 'hdr_expiration2_date')
    if order_by not in order_by_values:
        raise Exception(
            "Value of param 'order_by' should be one of the following: " +
            str(order_by_values))

    order_values = ('ASC', 'DESC', 'asc', 'desc')
    if order not in order_values:
        raise Exception(
            "Value of param 'order' should be one of the folowing: " +
            str(order_values))

    per_page = int(per_page)
    page = int(page)
    if per_page < 1 or page < 1:
        raise Exception("Value of params 'per_page' and 'page' should be >= 1")

    # Counting total number of items and fetching target page
    total_items = count_entities('observations', search_params)
    if total_items > limit:
        total_items = limit

    total_pages = math.ceil(total_items / per_page)

    whole_pages_offset = per_page * (page - 1)
    if whole_pages_offset >= total_items:
        return [], total_items, total_pages

    target_items = total_items - whole_pages_offset
    if target_items > per_page:
        target_items = per_page

    return (page_entities('observations', offset + whole_pages_offset,
                          target_items, order_by, order,
                          search_params), total_items, total_pages)
예제 #3
0
def read_per_page(offset, limit, order_by, order, search_params, per_page,
                  page):
    ''' Recuperar una página de entidades Clasificación interna de CyTG '''

    # Some validations
    offset = int(offset)
    if offset < 0:
        raise Exception("Value of param 'offset' should be >= 0")

    limit = int(limit)
    if limit < 1:
        raise Exception("Value of param 'limit' should be >= 1")

    order_by_values = ('sorting_val', 'org_fiscal_id', 'direccion_id', 'title')
    if order_by not in order_by_values:
        raise Exception(
            "Value of param 'order_by' should be one of the following: " +
            str(order_by_values))

    order_values = ('ASC', 'DESC', 'asc', 'desc')
    if order not in order_values:
        raise Exception(
            "Value of param 'order' should be one of the folowing: " +
            str(order_values))

    per_page = int(per_page)
    page = int(page)
    if per_page < 1 or page < 1:
        raise Exception("Value of params 'per_page' and 'page' should be >= 1")

    # Counting total number of items and fetching target page
    table = 'clasifs_internas_cytg'
    total_items = count_entities(table, search_params, True, 'sorting_val')
    if total_items > limit:
        total_items = limit

    total_pages = math.ceil(total_items / per_page)

    whole_pages_offset = per_page * (page - 1)
    if whole_pages_offset >= total_items:
        return [], total_items, total_pages

    target_items = total_items - whole_pages_offset
    if target_items > per_page:
        target_items = per_page

    entities = page_entities(table, offset + whole_pages_offset, target_items,
                             order_by, order, search_params, True)

    return (entities, total_items, total_pages)
def read_per_page(offset, limit, order_by, order, search_params, per_page, page):
    ''' Reads a page of social program entities '''

    # Some validations
    offset = int(offset)
    if offset < 0:
        raise Exception("Value of param 'offset' should be >= 0")
    
    limit = int(limit)
    if limit < 1:
        raise Exception("Value of param 'limit' should be >= 1")

    order_by_values = (
        'id', 'title', 'description', 'central', 'paraestatal', 'obra_pub'
    )
    if order_by not in order_by_values:
        raise Exception("Value of param 'order_by' should be one of the following: " + str(order_by_values))
    
    order_values = ('ASC', 'DESC', 'asc', 'desc')
    if order not in order_values:
        raise Exception("Value of param 'order' should be one of the folowing: " + str(order_values))

    per_page = int(per_page)
    page = int(page)
    if per_page < 1 or page < 1:
        raise Exception("Value of params 'per_page' and 'page' should be >= 1")

    # Counting total number of items and fetching target page
    table = 'social_programs'
    total_items = count_entities(table, search_params, False)
    if total_items > limit:
        total_items = limit
    
    total_pages = math.ceil(total_items / per_page)

    whole_pages_offset = per_page * (page - 1)
    if whole_pages_offset >= total_items:
        return [], total_items, total_pages
    
    target_items = total_items - whole_pages_offset
    if target_items > per_page:
        target_items = per_page

    entities = page_entities(table, offset + whole_pages_offset, target_items, order_by, order, search_params, False)

    return (entities, total_items, total_pages)
예제 #5
0
def read_per_page(offset, limit, order_by, order, search_params, per_page,
                  page):
    ''' Reads a page of audits '''

    # Some validations
    offset = int(offset)
    if offset < 0:
        raise Exception("Value of param 'offset' should be >= 0")

    limit = int(limit)
    if limit < 1:
        raise Exception("Value of param 'limit' should be >= 1")

    order_by_values = ('id', 'title')
    if order_by not in order_by_values:
        raise Exception(
            "Value of param 'order_by' should be one of the following: " +
            str(order_by_values))

    order_values = ('ASC', 'DESC', 'asc', 'desc')
    if order not in order_values:
        raise Exception(
            "Value of param 'order' should be one of the folowing: " +
            str(order_values))

    per_page = int(per_page)
    page = int(page)
    if per_page < 1 or page < 1:
        raise Exception("Value of params 'per_page' and 'page' should be >= 1")

    if search_params and 'direccion_id' in search_params and search_params[
            'direccion_id'] == '0':
        del search_params['direccion_id']
        if not search_params:
            search_params = None

    # Counting total number of items and fetching target page
    total_items = count_entities('audits', search_params, True)
    if total_items > limit:
        total_items = limit

    total_pages = math.ceil(total_items / per_page)

    whole_pages_offset = per_page * (page - 1)
    if whole_pages_offset >= total_items:
        return [], total_items, total_pages

    target_items = total_items - whole_pages_offset
    if target_items > per_page:
        target_items = per_page

    entities = page_entities('audits', offset + whole_pages_offset,
                             target_items, order_by, order, search_params,
                             True)

    # Adding dependency and year (public account) data
    deps_por_audit = get_dependencias_por_auditoria()
    anios_por_audit = get_anios_por_auditoria()
    for e in entities:
        e['dependency_ids'] = deps_por_audit[e['id']] if deps_por_audit else []
        e['years'] = anios_por_audit[e['id']] if anios_por_audit else []

    return (entities, total_items, total_pages)
예제 #6
0
def read_page(offset, limit, order_by, order, search_params):
    ''' Reads a page of observations '''
    return page_entities('observations', offset, limit, order_by, order,
                         search_params)