@ -2,6 +2,7 @@ import json
from datetime import date , datetime
from datetime import date , datetime
from braces . views import FormValidMessageMixin
from braces . views import FormValidMessageMixin
from django . contrib import messages
from django . contrib . auth . mixins import PermissionRequiredMixin
from django . contrib . auth . mixins import PermissionRequiredMixin
from django . core . exceptions import ObjectDoesNotExist
from django . core . exceptions import ObjectDoesNotExist
from django . core . urlresolvers import reverse
from django . core . urlresolvers import reverse
@ -13,6 +14,8 @@ from django.views.generic import CreateView, DetailView, FormView, ListView
from django . views . generic . base import TemplateView
from django . views . generic . base import TemplateView
from django_filters . views import FilterView
from django_filters . views import FilterView
from sapl . base . models import AppConfig
import sapl . crud . base
import sapl . crud . base
from sapl . crud . base import ( Crud , CrudBaseMixin , CrudCreateView ,
from sapl . crud . base import ( Crud , CrudBaseMixin , CrudCreateView ,
CrudDeleteView , CrudListView , CrudUpdateView ,
CrudDeleteView , CrudListView , CrudUpdateView ,
@ -206,18 +209,26 @@ class ProtocoloDocumentoView(PermissionRequiredMixin,
def form_valid ( self , form ) :
def form_valid ( self , form ) :
f = form . save ( commit = False )
f = form . save ( commit = False )
if form . cleaned_data [ ' numeracao ' ] == ' 1 ' :
try :
numeracao = Protocolo . objects . filter (
numeracao = AppConfig . objects . last ( ) . sequencia_numeracao
except AttributeError :
msg = _ ( ' É preciso definir a sequencia de ' +
' numeração na tabelas auxiliares! ' )
messages . add_message ( self . request , messages . ERROR , msg )
return self . render_to_response ( self . get_context_data ( ) )
if numeracao == ' A ' :
numero = Protocolo . objects . filter (
ano = date . today ( ) . year ) . aggregate ( Max ( ' numero ' ) )
ano = date . today ( ) . year ) . aggregate ( Max ( ' numero ' ) )
elif form . cleaned_data [ ' numeracao ' ] == ' 2 ' :
elif numeracao == ' U ' :
numeracao = Protocolo . objects . all ( ) . aggregate ( Max ( ' numero ' ) )
numero = Protocolo . objects . all ( ) . aggregate ( Max ( ' numero ' ) )
if numeracao [ ' numero__max ' ] is None :
if numero [ ' numero__max ' ] is None :
numeracao [ ' numero__max ' ] = 0
numero [ ' numero__max ' ] = 0
f . tipo_processo = ' 0 ' # TODO validar o significado
f . tipo_processo = ' 0 ' # TODO validar o significado
f . anulado = False
f . anulado = False
f . numero = numeraca o [ ' numero__max ' ] + 1
f . numero = numero [ ' numero__max ' ] + 1
f . ano = datetime . now ( ) . year
f . ano = datetime . now ( ) . year
f . data = datetime . now ( ) . strftime ( ' % Y- % m- %d ' )
f . data = datetime . now ( ) . strftime ( ' % Y- % m- %d ' )
f . hora = datetime . now ( ) . strftime ( ' % H: % M ' )
f . hora = datetime . now ( ) . strftime ( ' % H: % M ' )
@ -319,18 +330,26 @@ class ProtocoloMateriaView(PermissionRequiredMixin, CreateView):
return reverse ( ' sapl.protocoloadm:protocolo ' )
return reverse ( ' sapl.protocoloadm:protocolo ' )
def form_valid ( self , form ) :
def form_valid ( self , form ) :
if self . request . POST [ ' numeracao ' ] == ' 1 ' :
try :
numeracao = Protocolo . objects . filter (
numeracao = AppConfig . objects . last ( ) . sequencia_numeracao
except AttributeError :
msg = _ ( ' É preciso definir a sequencia de ' +
' numeração na tabelas auxiliares! ' )
messages . add_message ( self . request , messages . ERROR , msg )
return self . render_to_response ( self . get_context_data ( ) )
if numeracao == ' A ' :
numero = Protocolo . objects . filter (
ano = date . today ( ) . year ) . aggregate ( Max ( ' numero ' ) )
ano = date . today ( ) . year ) . aggregate ( Max ( ' numero ' ) )
else :
elif num eracao == ' U ' :
numeracao = Protocolo . objects . all ( ) . aggregate ( Max ( ' numero ' ) )
numero = Protocolo . objects . all ( ) . aggregate ( Max ( ' numero ' ) )
if numeracao is None :
if numeracao is None :
numeracao [ ' numero__max ' ] = 0
numero [ ' numero__max ' ] = 0
protocolo = Protocolo ( )
protocolo = Protocolo ( )
protocolo . numero = numeraca o [ ' numero__max ' ] + 1
protocolo . numero = numero [ ' numero__max ' ] + 1
protocolo . ano = datetime . now ( ) . year
protocolo . ano = datetime . now ( ) . year
protocolo . data = datetime . now ( ) . strftime ( " % Y- % m- %d " )
protocolo . data = datetime . now ( ) . strftime ( " % Y- % m- %d " )
protocolo . hora = datetime . now ( ) . strftime ( " % H: % M " )
protocolo . hora = datetime . now ( ) . strftime ( " % H: % M " )