From 9374dff90cc18b50d06d658c51a27210aa638331 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 31 Jul 2017 14:38:29 -0300 Subject: [PATCH] Fix #1265 autoria filtrar tipo (#1272) * Fixes #1265 * WIP --- sapl/materia/forms.py | 24 +++++++++++++++++++++--- sapl/materia/views.py | 4 ++++ sapl/templates/materia/layouts.yaml | 8 ++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index f809970de..a8cf6cb66 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -13,7 +13,7 @@ from django.core.files.base import File from django.core.urlresolvers import reverse from django.db import models, transaction from django.db.models import Max -from django.forms import ModelForm, widgets +from django.forms import ModelForm, ModelChoiceField, widgets from django.forms.forms import Form from django.forms.widgets import Select from django.utils import six @@ -26,7 +26,7 @@ from django_filters.filterset import STRICTNESS import django_filters -from sapl.base.models import Autor +from sapl.base.models import Autor, TipoAutor from sapl.comissoes.models import Comissao from sapl.compilacao.models import (STATUS_TA_IMMUTABLE_PUBLIC, STATUS_TA_PRIVATE) @@ -691,9 +691,27 @@ class DespachoInicialForm(ModelForm): class AutoriaForm(ModelForm): + tipo_autor = ModelChoiceField(label=_('Tipo Autor'), + required=False, + queryset= + TipoAutor.objects.all().order_by('descricao'), + empty_label='Selecione',) + + def __init__(self, *args, **kwargs): + super(AutoriaForm, self).__init__(*args, **kwargs) + + row1 = to_row([('tipo_autor', 4), + ('autor', 4), + ('primeiro_autor', 4)]) + + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset(_('Autoria'), + row1, form_actions(save_label='Salvar'))) + class Meta: model = Autoria - fields = ['autor', 'primeiro_autor'] + fields = ['tipo_autor', 'autor', 'primeiro_autor'] def clean(self): super(AutoriaForm, self).clean() diff --git a/sapl/materia/views.py b/sapl/materia/views.py index fb5fbd216..ddb78defb 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1089,6 +1089,10 @@ class AutoriaCrud(MasterDetailCrud): class CreateView(MasterDetailCrud.CreateView): form_class = AutoriaForm + @property + def layout_key(self): + return 'AutoriaCreate' + def get_context_data(self, **kwargs): context = super(CreateView, self).get_context_data(**kwargs) autores_ativos = self.autores_ativos() diff --git a/sapl/templates/materia/layouts.yaml b/sapl/templates/materia/layouts.yaml index 6045d61d9..aac494432 100644 --- a/sapl/templates/materia/layouts.yaml +++ b/sapl/templates/materia/layouts.yaml @@ -61,6 +61,14 @@ Autoria: {% trans 'Autoria' %}: - autor primeiro_autor +AutoriaCreate: + {% trans 'Autoria' %}: + - tipo_autor autor primeiro_autor + +AutoriaUpdate: + {% trans 'Autoria' %}: + - tipo_autor autor primeiro_autor + DocumentoAcessorio: {% trans 'Documento Acessório' %}: - tipo nome data