|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
|
|
|
import django_filters |
|
|
|
import logging |
|
|
|
from crispy_forms.bootstrap import InlineRadios |
|
|
|
from crispy_forms.helper import FormHelper |
|
|
|
from crispy_forms.layout import HTML, Button, Fieldset, Layout |
|
|
|
@ -220,6 +221,8 @@ class AnularProcoloAdmForm(ModelForm): |
|
|
|
def clean(self): |
|
|
|
super(AnularProcoloAdmForm, self).clean() |
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
cleaned_data = self.cleaned_data |
|
|
|
|
|
|
|
if not self.is_valid(): |
|
|
|
@ -229,12 +232,15 @@ class AnularProcoloAdmForm(ModelForm): |
|
|
|
ano = cleaned_data['ano'] |
|
|
|
|
|
|
|
try: |
|
|
|
logger.info("- Tentando obter Protocolo correspondente.") |
|
|
|
protocolo = Protocolo.objects.get(numero=numero, ano=ano) |
|
|
|
if protocolo.anulado: |
|
|
|
logger.error("- Protocolo %s/%s já encontra-se anulado" % (numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("Protocolo %s/%s já encontra-se anulado") |
|
|
|
% (numero, ano)) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
logger.error("- Protocolo %s/%s não existe" % (numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("Protocolo %s/%s não existe" % (numero, ano))) |
|
|
|
|
|
|
|
@ -247,6 +253,8 @@ class AnularProcoloAdmForm(ModelForm): |
|
|
|
).order_by('-ano', '-numero').exists() |
|
|
|
|
|
|
|
if exists: |
|
|
|
logger.error("- Protocolo %s/%s não pode ser removido pois existem " |
|
|
|
"documentos vinculados a ele." % (numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("Protocolo %s/%s não pode ser removido pois existem " |
|
|
|
"documentos vinculados a ele." % (numero, ano))) |
|
|
|
@ -416,18 +424,24 @@ class ProtocoloMateriaForm(ModelForm): |
|
|
|
] |
|
|
|
|
|
|
|
def clean_autor(self): |
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
autor_field = self.cleaned_data['autor'] |
|
|
|
try: |
|
|
|
logger.info("- Tentando obter Autor correspondente.") |
|
|
|
autor = Autor.objects.get(id=autor_field.id) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
logger.error("- Autor não encontrado. Definido como None.") |
|
|
|
autor_field = None |
|
|
|
else: |
|
|
|
logger.info("- Autor encontrado com sucesso.") |
|
|
|
autor_field = autor |
|
|
|
return autor_field |
|
|
|
|
|
|
|
def clean(self): |
|
|
|
super(ProtocoloMateriaForm, self).clean() |
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
if not self.is_valid(): |
|
|
|
return self.cleaned_data |
|
|
|
|
|
|
|
@ -435,16 +449,21 @@ class ProtocoloMateriaForm(ModelForm): |
|
|
|
if self.is_valid(): |
|
|
|
if data['vincular_materia'] == 'True': |
|
|
|
try: |
|
|
|
logger.info("- Tentando obter MateriaLegislativa correspondente.") |
|
|
|
if not data['ano_materia'] or not data['numero_materia']: |
|
|
|
logger.error("- Favor informar o número e ano da matéria a ser vinculada") |
|
|
|
raise ValidationError( |
|
|
|
'Favor informar o número e ano da matéria a ser vinculada') |
|
|
|
self.materia = MateriaLegislativa.objects.get(ano=data['ano_materia'], |
|
|
|
numero=data['numero_materia'], |
|
|
|
tipo=data['tipo_materia']) |
|
|
|
if self.materia.numero_protocolo: |
|
|
|
logger.error("- Matéria Legislativa informada já possui o protocolo {}/{} vinculado." |
|
|
|
.format(self.materia.numero_protocolo, self.materia.ano)) |
|
|
|
raise ValidationError(_('Matéria Legislativa informada já possui o protocolo {}/{} vinculado.' |
|
|
|
.format(self.materia.numero_protocolo, self.materia.ano))) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
logger.error("- Matéria Legislativa informada não existente.") |
|
|
|
raise ValidationError(_('Matéria Legislativa informada não existente.')) |
|
|
|
|
|
|
|
return data |
|
|
|
@ -666,6 +685,8 @@ class DocumentoAdministrativoForm(ModelForm): |
|
|
|
def clean(self): |
|
|
|
super(DocumentoAdministrativoForm, self).clean() |
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
cleaned_data = self.cleaned_data |
|
|
|
|
|
|
|
if not self.is_valid(): |
|
|
|
@ -693,14 +714,19 @@ class DocumentoAdministrativoForm(ModelForm): |
|
|
|
# campos opcionais, mas que se informados devem ser válidos |
|
|
|
if numero_protocolo and ano_protocolo: |
|
|
|
try: |
|
|
|
logger.info("- Tentando obter Protoclo correspondente.") |
|
|
|
self.fields['protocolo'].initial = Protocolo.objects.get( |
|
|
|
numero=numero_protocolo, |
|
|
|
ano=ano_protocolo).pk |
|
|
|
except ObjectDoesNotExist: |
|
|
|
logger.error("- Protocolo %s/%s inexistente." % ( |
|
|
|
numero_protocolo, ano_protocolo)) |
|
|
|
msg = _('Protocolo %s/%s inexistente.' % ( |
|
|
|
numero_protocolo, ano_protocolo)) |
|
|
|
raise ValidationError(msg) |
|
|
|
except MultipleObjectsReturned: |
|
|
|
logger.error("- Existe mais de um Protocolo com este ano e número." % ( |
|
|
|
numero_protocolo, ano_protocolo)) |
|
|
|
msg = _( |
|
|
|
'Existe mais de um Protocolo com este ano e número.' % ( |
|
|
|
numero_protocolo, ano_protocolo)) |
|
|
|
@ -782,6 +808,8 @@ class DesvincularDocumentoForm(ModelForm): |
|
|
|
def clean(self): |
|
|
|
super(DesvincularDocumentoForm, self).clean() |
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
cleaned_data = self.cleaned_data |
|
|
|
|
|
|
|
if not self.is_valid(): |
|
|
|
@ -792,11 +820,14 @@ class DesvincularDocumentoForm(ModelForm): |
|
|
|
tipo = cleaned_data['tipo'] |
|
|
|
|
|
|
|
try: |
|
|
|
logger.info("- Tentando obter DocumentoAdministrativo correspondente.") |
|
|
|
documento = DocumentoAdministrativo.objects.get(numero=numero, ano=ano, tipo=tipo) |
|
|
|
if not documento.protocolo: |
|
|
|
logger.error("- %s %s/%s não se encontra vinculado a nenhum protocolo" % (tipo, numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("%s %s/%s não se encontra vinculado a nenhum protocolo" % (tipo, numero, ano))) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
logger.error("- %s %s/%s não existe" % (tipo, numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("%s %s/%s não existe" % (tipo, numero, ano))) |
|
|
|
|
|
|
|
@ -844,6 +875,8 @@ class DesvincularMateriaForm(forms.Form): |
|
|
|
def clean(self): |
|
|
|
super(DesvincularMateriaForm, self).clean() |
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
cleaned_data = self.cleaned_data |
|
|
|
|
|
|
|
if not self.is_valid(): |
|
|
|
@ -854,11 +887,14 @@ class DesvincularMateriaForm(forms.Form): |
|
|
|
tipo = cleaned_data['tipo'] |
|
|
|
|
|
|
|
try: |
|
|
|
logger.info("- Tentando obter MateriaLegislativa correspondente.") |
|
|
|
materia = MateriaLegislativa.objects.get(numero=numero, ano=ano, tipo=tipo) |
|
|
|
if not materia.numero_protocolo: |
|
|
|
logger.error("- %s %s/%s não se encontra vinculada a nenhum protocolo" % (tipo, numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("%s %s/%s não se encontra vinculada a nenhum protocolo" % (tipo, numero, ano))) |
|
|
|
except ObjectDoesNotExist: |
|
|
|
logger.error("- %s %s/%s não existe" % (tipo, numero, ano)) |
|
|
|
raise forms.ValidationError( |
|
|
|
_("%s %s/%s não existe" % (tipo, numero, ano))) |
|
|
|
|
|
|
|
|