|
|
@ -3,17 +3,31 @@ from django.core.exceptions import ValidationError |
|
|
from django.db import transaction |
|
|
from django.db import transaction |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica |
|
|
from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica |
|
|
from sapl.materia.models import MateriaLegislativa |
|
|
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa |
|
|
|
|
|
from sapl.utils import timezone |
|
|
|
|
|
|
|
|
class AudienciaForm(forms.ModelForm): |
|
|
class AudienciaForm(forms.ModelForm): |
|
|
|
|
|
|
|
|
materia = forms.ModelChoiceField(required=False, |
|
|
data_atual = timezone.now() |
|
|
queryset=MateriaLegislativa.objects.all().select_related( |
|
|
|
|
|
"tipo").order_by('tipo', '-ano', 'numero')) |
|
|
|
|
|
|
|
|
|
|
|
tipo = forms.ModelChoiceField(required=True, |
|
|
tipo = forms.ModelChoiceField(required=True, |
|
|
|
|
|
label='Tipo de Audiência Pública', |
|
|
queryset=TipoAudienciaPublica.objects.all().order_by('nome')) |
|
|
queryset=TipoAudienciaPublica.objects.all().order_by('nome')) |
|
|
|
|
|
|
|
|
|
|
|
tipo_materia = forms.ModelChoiceField( |
|
|
|
|
|
label=_('Tipo Matéria'), |
|
|
|
|
|
required=True, |
|
|
|
|
|
queryset=TipoMateriaLegislativa.objects.all(), |
|
|
|
|
|
empty_label='Selecione', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
numero_materia = forms.CharField( |
|
|
|
|
|
label='Número Matéria', required=True) |
|
|
|
|
|
|
|
|
|
|
|
ano_materia = forms.CharField( |
|
|
|
|
|
label='Ano Matéria', |
|
|
|
|
|
initial=int(data_atual.year), |
|
|
|
|
|
required=True) |
|
|
|
|
|
|
|
|
class Meta: |
|
|
class Meta: |
|
|
model = AudienciaPublica |
|
|
model = AudienciaPublica |
|
|
@ -37,6 +51,19 @@ class AudienciaForm(forms.ModelForm): |
|
|
|
|
|
|
|
|
def clean(self): |
|
|
def clean(self): |
|
|
super(AudienciaForm, self).clean() |
|
|
super(AudienciaForm, self).clean() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
materia = MateriaLegislativa.objects.get( |
|
|
|
|
|
numero=self.cleaned_data['numero_materia'], |
|
|
|
|
|
ano=self.cleaned_data['ano_materia'], |
|
|
|
|
|
tipo=self.cleaned_data['tipo_materia']) |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
msg = _('A matéria a ser inclusa não existe no cadastro' |
|
|
|
|
|
' de matérias legislativas.') |
|
|
|
|
|
raise ValidationError(msg) |
|
|
|
|
|
else: |
|
|
|
|
|
cleaned_data['materia'] = materia |
|
|
|
|
|
|
|
|
if self.cleaned_data['hora_inicio'] and self.cleaned_data['hora_fim']: |
|
|
if self.cleaned_data['hora_inicio'] and self.cleaned_data['hora_fim']: |
|
|
if (self.cleaned_data['hora_fim'] < |
|
|
if (self.cleaned_data['hora_fim'] < |
|
|
self.cleaned_data['hora_inicio']): |
|
|
self.cleaned_data['hora_inicio']): |
|
|
|