Exemple #1
0
def index(request):
    if request.method == 'GET':
        form_filter = SolicitudFormFilters(request.GET)
    else:
        form_filter = SolicitudFormFilters()
    q = build_query(form_filter, 1, request)

    try:
        if request.GET['export'] == '1':
            return reporte_solicitudes(request, q)
    except KeyError:
        pass


    ambito = request.get_perfil().ambito
    perfil_jurisdiccional = ambito.tipo.nombre == Ambito.TIPO_JURISDICCION
    perfil_establecimiento = ambito.tipo.nombre == Ambito.TIPO_ESTABLECIMIENTO
    perfil_anexo = ambito.tipo.nombre == Ambito.TIPO_ANEXO


    if perfil_jurisdiccional or perfil_establecimiento or perfil_anexo:
        form_filter.fields['jurisdiccion'].queryset = form_filter.fields['jurisdiccion'].queryset.filter(id=request.get_perfil().jurisdiccion().id)
        if perfil_jurisdiccional:
            q = q.filter(jurisdiccion__id=request.get_perfil().jurisdiccion().id)
        elif perfil_establecimiento:
            establecimiento = Establecimiento.objects.get(ambito__path=ambito.path)
            q = q.filter(establecimientos__establecimiento__id=establecimiento.id)
        elif perfil_anexo:
            anexo = Anexo.objects.get(ambito__path=ambito.path)
            q = q.filter(anexos__anexo__id=anexo.id)
    
    paginator = Paginator(q, ITEMS_PER_PAGE)
    try:
        page_number = int(request.GET['page'])
    except (KeyError, ValueError):
        page_number = 1
    # chequear los límites
    if page_number < 1:
        page_number = 1
    elif page_number > paginator.num_pages:
        page_number = paginator.num_pages

    page = paginator.page(page_number)
    objects = page.object_list

    return my_render(request, 'validez_nacional/solicitud/index.html', {
        'form_filters': form_filter,
        'objects': objects,
        'paginator': paginator,
        'page': page,
        'page_number': page_number,
        'pages_range': range(1, paginator.num_pages + 1),
        'next_page': page_number + 1,
        'prev_page': page_number - 1,
        'export_url': Reporte.build_export_url(request.build_absolute_uri()),
        've_acciones': ambito.tipo.nombre not in [Ambito.TIPO_ESTABLECIMIENTO, Ambito.TIPO_ANEXO]
    })
Exemple #2
0
def index(request):
    
    if request.method == 'GET':
        form_filter = SolicitudFormFilters(request.GET)
    else:
        form_filter = SolicitudFormFilters()
    q = build_query(form_filter, 1, request)

    try:
        if request.GET['export'] == '1':
            return reporte_solicitudes(request, q)
    except KeyError:
        pass
        
    if request.get_perfil().jurisdiccion():
        q = q.filter(jurisdiccion__id=request.get_perfil().jurisdiccion().id)
    paginator = Paginator(q, ITEMS_PER_PAGE)
    try:
        page_number = int(request.GET['page'])
    except (KeyError, ValueError):
        page_number = 1
    # chequear los límites
    if page_number < 1:
        page_number = 1
    elif page_number > paginator.num_pages:
        page_number = paginator.num_pages
    
    page = paginator.page(page_number)
    objects = page.object_list

    return my_render(request, 'postitulos/solicitud/index.html', {
        'form_filters': form_filter,
        'objects': objects,
        'paginator': paginator,
        'page': page,
        'page_number': page_number,
        'pages_range': range(1, paginator.num_pages + 1),
        'next_page': page_number + 1,
        'prev_page': page_number - 1,
        'export_url': Reporte.build_export_url(request.build_absolute_uri()),
    })