@ -1,6 +1,5 @@
from datetime import datetime
from datetime import datetime
import django_filters
from crispy_forms . bootstrap import InlineRadios
from crispy_forms . bootstrap import InlineRadios
from crispy_forms . helper import FormHelper
from crispy_forms . helper import FormHelper
from crispy_forms . layout import HTML , Button , Fieldset , Layout , Submit
from crispy_forms . layout import HTML , Button , Fieldset , Layout , Submit
@ -9,17 +8,19 @@ from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django . db import models
from django . db import models
from django . forms import ModelForm
from django . forms import ModelForm
from django . utils . translation import ugettext_lazy as _
from django . utils . translation import ugettext_lazy as _
import django_filters
from sapl . base . models import Autor
from sapl . base . models import Autor
from sapl . crispy_layout_mixin import form_actions , to_row
from sapl . crispy_layout_mixin import form_actions , to_row
from sapl . materia . models import UnidadeTramitacao
from sapl . materia . models import UnidadeTramitacao
from sapl . utils import ( RANGE_ANOS , RangeWidgetOverride , autor_label ,
from sapl . utils import ( RANGE_ANOS , RangeWidgetOverride , autor_label ,
autor_modal )
autor_modal , AnoNumeroOrderingFilter )
from . models import ( DocumentoAcessorioAdministrativo , DocumentoAdministrativo ,
from . models import ( DocumentoAcessorioAdministrativo , DocumentoAdministrativo ,
Protocolo , TipoDocumentoAdministrativo ,
Protocolo , TipoDocumentoAdministrativo ,
TramitacaoAdministrativo )
TramitacaoAdministrativo )
TIPOS_PROTOCOLO = [ ( ' 0 ' , ' Enviado ' ) , ( ' 1 ' , ' Recebido ' ) , ( ' ' , ' Ambos ' ) ]
TIPOS_PROTOCOLO = [ ( ' 0 ' , ' Enviado ' ) , ( ' 1 ' , ' Recebido ' ) , ( ' ' , ' Ambos ' ) ]
NATUREZA_PROCESSO = [ ( ' ' , ' Ambos ' ) ,
NATUREZA_PROCESSO = [ ( ' ' , ' Ambos ' ) ,
@ -68,6 +69,8 @@ class ProtocoloFilterSet(django_filters.FilterSet):
widget = forms . Select (
widget = forms . Select (
attrs = { ' class ' : ' selector ' } ) )
attrs = { ' class ' : ' selector ' } ) )
o = AnoNumeroOrderingFilter ( )
class Meta :
class Meta :
model = Protocolo
model = Protocolo
fields = [ ' numero ' ,
fields = [ ' numero ' ,
@ -76,25 +79,6 @@ class ProtocoloFilterSet(django_filters.FilterSet):
' tipo_materia ' ,
' tipo_materia ' ,
]
]
order_by = (
( ' ' , ' Selecione ' ) ,
( ' CRE ' , ' Ordem Crescente ' ) ,
( ' DEC ' , ' Ordem Decrescente ' ) ,
)
order_by_mapping = {
' ' : [ ] ,
' CRE ' : [ ' ano ' , ' numero ' ] ,
' DEC ' : [ ' -ano ' , ' -numero ' ] ,
}
def get_order_by ( self , order_value ) :
if order_value in self . order_by_mapping :
return self . order_by_mapping [ order_value ]
else :
return super ( ProtocoloFilterSet ,
self ) . get_order_by ( order_value )
def __init__ ( self , * args , * * kwargs ) :
def __init__ ( self , * args , * * kwargs ) :
super ( ProtocoloFilterSet , self ) . __init__ ( * args , * * kwargs )
super ( ProtocoloFilterSet , self ) . __init__ ( * args , * * kwargs )
@ -162,6 +146,8 @@ class DocumentoAdministrativoFilterSet(django_filters.FilterSet):
interessado = django_filters . CharFilter ( lookup_expr = ' icontains ' )
interessado = django_filters . CharFilter ( lookup_expr = ' icontains ' )
o = AnoNumeroOrderingFilter ( )
class Meta :
class Meta :
model = DocumentoAdministrativo
model = DocumentoAdministrativo
fields = [ ' tipo ' ,
fields = [ ' tipo ' ,
@ -171,25 +157,6 @@ class DocumentoAdministrativoFilterSet(django_filters.FilterSet):
' tramitacaoadministrativo__unidade_tramitacao_destino ' ,
' tramitacaoadministrativo__unidade_tramitacao_destino ' ,
' tramitacaoadministrativo__status ' ]
' tramitacaoadministrativo__status ' ]
order_by = (
( ' ' , ' Selecione ' ) ,
( ' CRE ' , ' Ordem Crescente ' ) ,
( ' DEC ' , ' Ordem Decrescente ' ) ,
)
order_by_mapping = {
' ' : [ ] ,
' CRE ' : [ ' ano ' , ' numero ' ] ,
' DEC ' : [ ' -ano ' , ' -numero ' ] ,
}
def get_order_by ( self , order_value ) :
if order_value in self . order_by_mapping :
return self . order_by_mapping [ order_value ]
else :
return super ( DocumentoAdministrativoFilterSet ,
self ) . get_order_by ( order_value )
def __init__ ( self , * args , * * kwargs ) :
def __init__ ( self , * args , * * kwargs ) :
super ( DocumentoAdministrativoFilterSet , self ) . __init__ ( * args , * * kwargs )
super ( DocumentoAdministrativoFilterSet , self ) . __init__ ( * args , * * kwargs )