From 02cd850613b88dcba22f65e422aca346275b6bc2 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 18 Mar 2016 14:32:03 -0300 Subject: [PATCH] Adiciona busca de autor ao documento acessorio #241 --- materia/forms.py | 24 ++++++++++++++++++++++-- materia/views.py | 4 ++-- sapl/utils.py | 6 +++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index e2ccb7e19..3bb7c0619 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -100,6 +100,7 @@ class AcompanhamentoMateriaForm(ModelForm): class DocumentoAcessorioForm(ModelForm): + autor = forms.CharField(widget=forms.HiddenInput(), required=False) class Meta: model = DocumentoAcessorio @@ -112,13 +113,29 @@ class DocumentoAcessorioForm(ModelForm): 'data': forms.DateInput(attrs={'class': 'dateinput'}) } + def clean_autor(self): + autor_field = self.cleaned_data['autor'] + try: + int(autor_field) + except ValueError: + return autor_field + else: + if autor_field: + return str(Autor.objects.get(id=autor_field)) + def __init__(self, excluir=False, *args, **kwargs): row1 = crispy_layout_mixin.to_row( [('tipo', 4), ('nome', 4), ('data', 4)]) row2 = crispy_layout_mixin.to_row( - [('autor', 12)]) + [('autor', 0), + (Button('pesquisar', + 'Pesquisar Autor', + css_class='btn btn-primary btn-sm'), 2), + (Button('limpar', + 'Limpar Autor', + css_class='btn btn-primary btn-sm'), 10)]) row3 = crispy_layout_mixin.to_row( [('ementa', 12)]) @@ -131,7 +148,10 @@ class DocumentoAcessorioForm(ModelForm): self.helper.layout = Layout( Fieldset( _('Incluir Documento Acessório'), - row1, row2, row3, + row1, + HTML(sapl.utils.autor_label), + HTML(sapl.utils.autor_modal), + row2, row3, form_actions(more=more) ) ) diff --git a/materia/views.py b/materia/views.py index f68fdacc6..a4e954ece 100644 --- a/materia/views.py +++ b/materia/views.py @@ -507,7 +507,8 @@ class DocumentoAcessorioView(CreateView): def get(self, request, *args, **kwargs): materia = MateriaLegislativa.objects.get(id=kwargs['pk']) - docs = DocumentoAcessorio.objects.filter(materia_id=kwargs['pk']) + docs = DocumentoAcessorio.objects.filter( + materia_id=kwargs['pk']).order_by('data') form = DocumentoAcessorioForm() return self.render_to_response( @@ -579,7 +580,6 @@ class DocumentoAcessorioEditView(CreateView): materia = MateriaLegislativa.objects.get(id=kwargs['pk']) documento = DocumentoAcessorio.objects.get(id=kwargs['id']) form = DocumentoAcessorioForm(instance=documento, excluir=True) - return self.render_to_response({'object': materia, 'form': form}) def post(self, request, *args, **kwargs): diff --git a/sapl/utils.py b/sapl/utils.py index f5707d197..77840dd76 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -8,7 +8,11 @@ from django.utils.translation import ugettext_lazy as _ autor_label = '''
- Autor: + Autor: + {% if form.autor.value %} + {{form.autor.value}} + {% endif %} +
'''