|
@ -7,7 +7,7 @@ from crispy_forms.layout import Button, Column, Fieldset, HTML, Layout, Submit |
|
|
from crispy_layout_mixin import form_actions |
|
|
from crispy_layout_mixin import form_actions |
|
|
|
|
|
|
|
|
from django import forms |
|
|
from django import forms |
|
|
from django.core.exceptions import ValidationError |
|
|
from django.core.exceptions import ValidationError, ObjectDoesNotExist |
|
|
from django.db.models import Max |
|
|
from django.db.models import Max |
|
|
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 _ |
|
@ -30,11 +30,6 @@ def em_tramitacao(): |
|
|
(False, 'Não')] |
|
|
(False, 'Não')] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ordenacao(): |
|
|
|
|
|
return [('data, tipo, ano, numero', 'Data, Tipo, Ano, Numero'), |
|
|
|
|
|
('tipo, ano, numero, data', 'Tipo, Ano, Numero, Data')] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProposicaoForm(ModelForm): |
|
|
class ProposicaoForm(ModelForm): |
|
|
|
|
|
|
|
|
tipo_materia = forms.ModelChoiceField( |
|
|
tipo_materia = forms.ModelChoiceField( |
|
@ -558,11 +553,26 @@ class AutoriaForm(ModelForm): |
|
|
choices=[(True, _('Sim')), (False, _('Não'))], |
|
|
choices=[(True, _('Sim')), (False, _('Não'))], |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
materia_id = forms.CharField(widget=forms.HiddenInput(), required=False) |
|
|
|
|
|
|
|
|
class Meta: |
|
|
class Meta: |
|
|
model = Autoria |
|
|
model = Autoria |
|
|
fields = ['autor', |
|
|
fields = ['autor', |
|
|
'primeiro_autor', |
|
|
'primeiro_autor', |
|
|
'partido'] |
|
|
'partido', |
|
|
|
|
|
'materia_id'] |
|
|
|
|
|
|
|
|
|
|
|
def clean(self): |
|
|
|
|
|
if self.data['materia_id'] and self.data['autor']: |
|
|
|
|
|
try: |
|
|
|
|
|
materia = MateriaLegislativa.objects.get( |
|
|
|
|
|
id=self.data['materia_id']) |
|
|
|
|
|
Autoria.objects.get(autor=self.data['autor'], |
|
|
|
|
|
materia=materia) |
|
|
|
|
|
raise forms.ValidationError( |
|
|
|
|
|
_('Essa autoria já foi adicionada!')) |
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
def __init__(self, excluir=False, *args, **kwargs): |
|
|
def __init__(self, excluir=False, *args, **kwargs): |
|
|
|
|
|
|
|
|