Browse Source

Adiciona busca de autor ao documento acessorio #241

pull/285/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
02cd850613
  1. 24
      materia/forms.py
  2. 4
      materia/views.py
  3. 6
      sapl/utils.py

24
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)
)
)

4
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):

6
sapl/utils.py

@ -8,7 +8,11 @@ from django.utils.translation import ugettext_lazy as _
autor_label = '''
<div class="col-xs-12">
Autor: <span id="nome_autor"></span>
Autor: <span id="nome_autor" name="nome_autor">
{% if form.autor.value %}
{{form.autor.value}}
{% endif %}
</span>
</div>
'''

Loading…
Cancel
Save