From 402dd92a7fdf4390a67581328429ad793f5218ab Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 25 Aug 2016 13:04:29 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20detail/update=20proposi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/forms.py | 5 ----- sapl/materia/views.py | 28 ++++++++++++---------------- sapl/templates/materia/layouts.yaml | 3 ++- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 8f18e23a5..8351cac05 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -111,8 +111,6 @@ class ProposicaoForm(ModelForm): if cleaned_data['tipo'].descricao == 'Parecer': if self.instance.materia: cleaned_data['materia'] = self.instance.materia - cleaned_data['autor'] = ( - self.instance.materia.autoria_set.first().autor) else: try: materia = MateriaLegislativa.objects.get( @@ -124,9 +122,6 @@ class ProposicaoForm(ModelForm): raise ValidationError(msg) else: cleaned_data['materia'] = materia - cleaned_data['autor'] = materia.autoria_set.first( - ).autor - return cleaned_data def save(self, commit=False): diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 3deff9217..0800a56c2 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -404,10 +404,13 @@ class ProposicaoCrud(Crud): messages.add_message(self.request, messages.ERROR, msg) return redirect(self.get_success_url()) except ObjectDoesNotExist: + # FIXME: Pensar em uma melhor forma + tipo = TipoAutor.objects.get(name='Externo') + autor_id = Autor.objects.create( user=self.request.user, nome=str(self.request.user), - tipo_id=4).id + tipo=tipo).id return {'autor': autor_id} else: return {'autor': autor_id} @@ -416,6 +419,14 @@ class ProposicaoCrud(Crud): form_class = ProposicaoForm permission_required = permissoes_autor() + def get_initial(self): + initial = self.initial.copy() + if self.object.materia: + initial['tipo_materia'] = self.object.materia.tipo.id + initial['numero_materia'] = self.object.materia.numero + initial['ano_materia'] = self.object.materia.ano + return initial + @property def layout_key(self): return 'ProposicaoCreate' @@ -442,21 +453,6 @@ class ProposicaoCrud(Crud): class DetailView(PermissionRequiredMixin, CrudDetailView): permission_required = permissoes_autor() - def get_context_data(self, **kwargs): - context = super(DetailView, self).get_context_data(**kwargs) - if self.object.materia: - context['form'].fields['tipo_materia'].initial = ( - self.object.materia.tipo.id) - context['form'].fields['numero_materia'].initial = ( - self.object.materia.numero) - context['form'].fields['ano_materia'].initial = ( - self.object.materia.ano) - return context - - @property - def layout_key(self): - return 'ProposicaoCreate' - def has_permission(self): perms = self.get_permission_required() if self.request.user.has_perms(perms): diff --git a/sapl/templates/materia/layouts.yaml b/sapl/templates/materia/layouts.yaml index 49e201711..19c5fcdbd 100644 --- a/sapl/templates/materia/layouts.yaml +++ b/sapl/templates/materia/layouts.yaml @@ -98,7 +98,8 @@ ProposicaoCreate: {% trans 'Proposição' %}: - tipo data_envio - descricao - + {% trans 'Materia' %}: + - tipo_materia numero_materia ano_materia {% trans 'Complemento' %}: - texto_original