From b52fbb3fc2863a4d65fd0500499fa6da93fa0f97 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 3 May 2016 11:48:05 -0300 Subject: [PATCH 01/22] Init crud relatoria --- materia/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/materia/views.py b/materia/views.py index 93c322221..87e62e0e8 100644 --- a/materia/views.py +++ b/materia/views.py @@ -57,6 +57,8 @@ ProposicaoCrud = Crud.build(Proposicao, '') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao') +RelatoriaCrud = MasterDetailCrud.build(Relatoria, 'materia', '') + class RelatoriaCrud(MasterDetailCrud): model = Relatoria From f5d43d653decb4b793b8ed409014b9d45a4b57d4 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 4 May 2016 10:29:39 -0300 Subject: [PATCH 02/22] =?UTF-8?q?Disabilita=20localiza=C3=A7=C3=A3o=20atua?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/forms.py | 7 +++++++ materia/views.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/materia/forms.py b/materia/forms.py index 186c6ba09..ff932b4ee 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -176,6 +176,13 @@ class RelatoriaForm(ModelForm): return cleaned_data + class Meta: + model = Relatoria + model = Relatoria + fields = ['data_designacao_relator', 'comissao', 'parlamentar', + 'data_destituicao_relator', 'tipo_fim_relatoria'] + widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})} + class TramitacaoForm(ModelForm): diff --git a/materia/views.py b/materia/views.py index 87e62e0e8..4dd09b160 100644 --- a/materia/views.py +++ b/materia/views.py @@ -57,7 +57,21 @@ ProposicaoCrud = Crud.build(Proposicao, '') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao') -RelatoriaCrud = MasterDetailCrud.build(Relatoria, 'materia', '') + +class RelatoriaCrud(MasterDetailCrud): + model = Relatoria + parent_field = 'materia' + help_path = '' + + class CreateView(MasterDetailCrud.CreateView): + form_class = RelatoriaForm + + def get_initial(self): + self.initial['comissao'] = 8 + return self.initial + + class UpdateView(MasterDetailCrud.UpdateView): + form_class = RelatoriaForm class RelatoriaCrud(MasterDetailCrud): From 49ec90eb3db50043cb12bd497b6e0317f57351c2 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 5 May 2016 08:59:13 -0300 Subject: [PATCH 03/22] =?UTF-8?q?Valida=20localiza=C3=A7=C3=A3o=20atual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/forms.py | 15 +++++++++++++- materia/views.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index ff932b4ee..5d02f70ef 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -177,12 +177,25 @@ class RelatoriaForm(ModelForm): return cleaned_data class Meta: - model = Relatoria model = Relatoria fields = ['data_designacao_relator', 'comissao', 'parlamentar', 'data_destituicao_relator', 'tipo_fim_relatoria'] + widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})} + def clean(self): + cleaned_data = self.cleaned_data + + try: + comissao = Comissao.objects.get(id=self.initial['comissao']) + except ObjectDoesNotExist: + msg = _('A localização atual deve ser uma comissão.') + raise ValidationError(msg) + else: + cleaned_data['comissao'] = comissao + + return cleaned_data + class TramitacaoForm(ModelForm): diff --git a/materia/views.py b/materia/views.py index 4dd09b160..0d9178c2f 100644 --- a/materia/views.py +++ b/materia/views.py @@ -67,8 +67,21 @@ class RelatoriaCrud(MasterDetailCrud): form_class = RelatoriaForm def get_initial(self): - self.initial['comissao'] = 8 - return self.initial + materia = MateriaLegislativa.objects.get(id=self.kwargs['pk']) + + loc_atual = Tramitacao.objects.filter( + materia=materia).last() + + if loc_atual is None: + localizacao = 0 + else: + comissao = loc_atual.unidade_tramitacao_destino.comissao + if comissao: + localizacao = comissao.pk + else: + localizacao = 0 + + return {'comissao': localizacao} class UpdateView(MasterDetailCrud.UpdateView): form_class = RelatoriaForm @@ -376,6 +389,42 @@ class AcompanhamentoExcluirView(TemplateView): return HttpResponseRedirect(self.get_redirect_url()) +class DocumentoAcessorioEditView(CreateView): + template_name = "materia/documento_acessorio_edit.html" + form_class = DocumentoAcessorioForm + + def get(self, request, *args, **kwargs): + 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): + form = self.get_form() + materia = MateriaLegislativa.objects.get(id=kwargs['pk']) + documento = DocumentoAcessorio.objects.get(id=kwargs['id']) + if form.is_valid(): + if 'Excluir' in request.POST: + documento.delete() + elif 'salvar' in request.POST: + documento.materia = materia + documento.tipo = form.cleaned_data['tipo'] + documento.data = form.cleaned_data['data'] + documento.nome = form.cleaned_data['nome'] + documento.autor = form.cleaned_data['autor'] + documento.ementa = form.cleaned_data['ementa'] + documento.save() + return redirect(self.get_success_url()) + else: + return self.render_to_response({'form': form, + 'object': materia, + 'doc': documento}) + + def get_success_url(self): + pk = self.kwargs['pk'] + return reverse('materia:documento_acessorio', kwargs={'pk': pk}) + + def load_email_templates(templates, context={}): emails = [] From 3e54b174f23aa29f17af9d1e433e22c058a24589 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 5 May 2016 09:22:51 -0300 Subject: [PATCH 04/22] =?UTF-8?q?Init=20crud=20documento=20acess=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/forms.py | 2 -- materia/layouts.yaml | 3 +++ materia/views.py | 36 ------------------------------------ 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index 5d02f70ef..81dc4a778 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -121,8 +121,6 @@ class DocumentoAcessorioForm(ModelForm): fields = ['tipo', 'nome', 'data', 'autor', 'ementa', 'arquivo'] widgets = {'autor': forms.HiddenInput()} - widgets = {'autor': forms.HiddenInput()} - def clean_autor(self): autor_field = self.cleaned_data['autor'] try: diff --git a/materia/layouts.yaml b/materia/layouts.yaml index 272cb006e..740530c86 100644 --- a/materia/layouts.yaml +++ b/materia/layouts.yaml @@ -65,7 +65,10 @@ DocumentoAcessorio: - tipo nome data - autor - ementa +<<<<<<< 17f3a6f60978fa9227d01d199824271efa5fcdf7 - arquivo +======= +>>>>>>> Init crud documento acessório Numeracao: Numeração: diff --git a/materia/views.py b/materia/views.py index 0d9178c2f..d402fe322 100644 --- a/materia/views.py +++ b/materia/views.py @@ -389,42 +389,6 @@ class AcompanhamentoExcluirView(TemplateView): return HttpResponseRedirect(self.get_redirect_url()) -class DocumentoAcessorioEditView(CreateView): - template_name = "materia/documento_acessorio_edit.html" - form_class = DocumentoAcessorioForm - - def get(self, request, *args, **kwargs): - 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): - form = self.get_form() - materia = MateriaLegislativa.objects.get(id=kwargs['pk']) - documento = DocumentoAcessorio.objects.get(id=kwargs['id']) - if form.is_valid(): - if 'Excluir' in request.POST: - documento.delete() - elif 'salvar' in request.POST: - documento.materia = materia - documento.tipo = form.cleaned_data['tipo'] - documento.data = form.cleaned_data['data'] - documento.nome = form.cleaned_data['nome'] - documento.autor = form.cleaned_data['autor'] - documento.ementa = form.cleaned_data['ementa'] - documento.save() - return redirect(self.get_success_url()) - else: - return self.render_to_response({'form': form, - 'object': materia, - 'doc': documento}) - - def get_success_url(self): - pk = self.kwargs['pk'] - return reverse('materia:documento_acessorio', kwargs={'pk': pk}) - - def load_email_templates(templates, context={}): emails = [] From 9575d90c46678aca3ab211f7741a3fc17bc5d76a Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 5 May 2016 12:06:35 -0300 Subject: [PATCH 05/22] Monta layout para autor --- materia/forms.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/materia/forms.py b/materia/forms.py index 81dc4a778..f2997292e 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -131,6 +131,10 @@ class DocumentoAcessorioForm(ModelForm): if autor_field: return str(Autor.objects.get(id=autor_field)) + def __init__(self, *args, **kwargs): + super(DocumentoAcessorioForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + class RelatoriaForm(ModelForm): From 5ee097f9235208ab8103522d71a09b8a37420943 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 9 May 2016 10:37:21 -0300 Subject: [PATCH 06/22] =?UTF-8?q?Adicona=20busca=20de=20autor=20na=20cria?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20documento=20acess=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/forms.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/materia/forms.py b/materia/forms.py index f2997292e..81dc4a778 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -131,10 +131,6 @@ class DocumentoAcessorioForm(ModelForm): if autor_field: return str(Autor.objects.get(id=autor_field)) - def __init__(self, *args, **kwargs): - super(DocumentoAcessorioForm, self).__init__(*args, **kwargs) - self.helper = FormHelper() - class RelatoriaForm(ModelForm): From d68991598fe1bf4f7a9a227a77ac28ec013142f5 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 9 May 2016 12:14:33 -0300 Subject: [PATCH 07/22] =?UTF-8?q?Define=20layout=20documento=20acess=C3=B3?= =?UTF-8?q?rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/materia/views.py b/materia/views.py index d402fe322..e4642410b 100644 --- a/materia/views.py +++ b/materia/views.py @@ -2,6 +2,7 @@ import os from datetime import datetime from random import choice from string import ascii_letters, digits +from crispy_layout_mixin import form_actions from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button From d914b7a5088cffe43d9e7a928434b0f8f5b08347 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 28 Apr 2016 12:14:36 -0300 Subject: [PATCH 08/22] =?UTF-8?q?Init=20crud=20legisla=C3=A7=C3=A3o=20cita?= =?UTF-8?q?da?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/urls.py | 2 +- materia/views.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/materia/urls.py b/materia/urls.py index 332623881..b04161fb6 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -29,7 +29,7 @@ urlpatterns = [ LegislacaoCitadaCrud.get_urls() + TramitacaoCrud.get_urls() + RelatoriaCrud.get_urls() + - DocumentoAcessorioCrud.get_urls())), + DocumentoAcessorioCrud.get_urls())) # Integração com Compilação url(r'^materia/(?P[0-9]+)/ta$', diff --git a/materia/views.py b/materia/views.py index e4642410b..95f8f852e 100644 --- a/materia/views.py +++ b/materia/views.py @@ -355,6 +355,43 @@ class MateriaLegislativaCrud(Crud): list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao'] +class DocumentoAcessorioView(CreateView): + template_name = "materia/documento_acessorio.html" + form_class = DocumentoAcessorioForm + + def get(self, request, *args, **kwargs): + materia = MateriaLegislativa.objects.get(id=kwargs['pk']) + docs = DocumentoAcessorio.objects.filter( + materia_id=kwargs['pk']).order_by('data') + form = DocumentoAcessorioForm() + + return self.render_to_response( + {'object': materia, + 'form': form, + 'docs': docs}) + + def post(self, request, *args, **kwargs): + form = self.get_form() + materia = MateriaLegislativa.objects.get(id=kwargs['pk']) + docs_list = DocumentoAcessorio.objects.filter( + materia_id=kwargs['pk']) + + if form.is_valid(): + documento_acessorio = form.save(commit=False) + documento_acessorio.materia = materia + documento_acessorio.save() + return self.form_valid(form) + else: + return self.render_to_response({'form': form, + 'object': materia, + 'docs': docs_list}) + + def get_success_url(self): + pk = self.kwargs['pk'] + return reverse('materia:documento_acessorio', kwargs={'pk': pk}) + + +>>>>>>> Init crud legislação citada class AcompanhamentoConfirmarView(TemplateView): def get_redirect_url(self): From bcd6af7bc2a7ca37fa8a057b639fa985043a56dd Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 2 May 2016 11:22:56 -0300 Subject: [PATCH 09/22] =?UTF-8?q?Init=20Crud=20Tramita=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/materia/views.py b/materia/views.py index 95f8f852e..fbed5a484 100644 --- a/materia/views.py +++ b/materia/views.py @@ -391,7 +391,6 @@ class DocumentoAcessorioView(CreateView): return reverse('materia:documento_acessorio', kwargs={'pk': pk}) ->>>>>>> Init crud legislação citada class AcompanhamentoConfirmarView(TemplateView): def get_redirect_url(self): From c8db81c4472c354c560964bc3d2e13f61650f043 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 3 May 2016 11:48:05 -0300 Subject: [PATCH 10/22] Init crud relatoria --- materia/urls.py | 7 +++++++ materia/views.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/materia/urls.py b/materia/urls.py index b04161fb6..3d197d21b 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -55,6 +55,13 @@ urlpatterns = [ url(r'^sistema/materia/status-tramitacao/', include(StatusTramitacaoCrud.get_urls())), url(r'^sistema/materia/orgao/', include(OrgaoCrud.get_urls())), +<<<<<<< 87cd7406270bf42bacab49bf32b87b7c838c72d0 +======= + url(r'^materia/(?P\d+)/documento-acessorio$', + DocumentoAcessorioView.as_view(), name='documento_acessorio'), + url(r'^materia/(?P\d+)/documento-acessorio/(?P\d+)/edit', + DocumentoAcessorioEditView.as_view(), name='documento_acessorio_edit'), +>>>>>>> Init crud relatoria url(r'^materia/proposicao$', ProposicaoView.as_view(), name='adicionar_proposicao'), url(r'^materia/proposicao_list$', diff --git a/materia/views.py b/materia/views.py index fbed5a484..6a3606ef1 100644 --- a/materia/views.py +++ b/materia/views.py @@ -58,6 +58,8 @@ ProposicaoCrud = Crud.build(Proposicao, '') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao') +RelatoriaCrud = MasterDetailCrud.build(Relatoria, 'materia', '') + class RelatoriaCrud(MasterDetailCrud): model = Relatoria From 98501296f73afa49a87344e391cad1d7de4130c4 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 5 May 2016 09:03:26 -0300 Subject: [PATCH 11/22] Fix qa e testes --- materia/urls.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/materia/urls.py b/materia/urls.py index 3d197d21b..b04161fb6 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -55,13 +55,6 @@ urlpatterns = [ url(r'^sistema/materia/status-tramitacao/', include(StatusTramitacaoCrud.get_urls())), url(r'^sistema/materia/orgao/', include(OrgaoCrud.get_urls())), -<<<<<<< 87cd7406270bf42bacab49bf32b87b7c838c72d0 -======= - url(r'^materia/(?P\d+)/documento-acessorio$', - DocumentoAcessorioView.as_view(), name='documento_acessorio'), - url(r'^materia/(?P\d+)/documento-acessorio/(?P\d+)/edit', - DocumentoAcessorioEditView.as_view(), name='documento_acessorio_edit'), ->>>>>>> Init crud relatoria url(r'^materia/proposicao$', ProposicaoView.as_view(), name='adicionar_proposicao'), url(r'^materia/proposicao_list$', From b5a81d13a899af6d5bcfaa301b7a6b9026f7082a Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 10 May 2016 09:35:11 -0300 Subject: [PATCH 12/22] Fix url --- materia/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/materia/urls.py b/materia/urls.py index b04161fb6..332623881 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -29,7 +29,7 @@ urlpatterns = [ LegislacaoCitadaCrud.get_urls() + TramitacaoCrud.get_urls() + RelatoriaCrud.get_urls() + - DocumentoAcessorioCrud.get_urls())) + DocumentoAcessorioCrud.get_urls())), # Integração com Compilação url(r'^materia/(?P[0-9]+)/ta$', From 92d57c97780d24aa6e4909577ce03637d6f0a764 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 10 May 2016 09:51:36 -0300 Subject: [PATCH 13/22] =?UTF-8?q?Adiciona=20campo=20de=20arquivo=20em=20Do?= =?UTF-8?q?cumento=20Acess=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/layouts.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/materia/layouts.yaml b/materia/layouts.yaml index 740530c86..272cb006e 100644 --- a/materia/layouts.yaml +++ b/materia/layouts.yaml @@ -65,10 +65,7 @@ DocumentoAcessorio: - tipo nome data - autor - ementa -<<<<<<< 17f3a6f60978fa9227d01d199824271efa5fcdf7 - arquivo -======= ->>>>>>> Init crud documento acessório Numeracao: Numeração: From ff490a54cddb7f00b0ab54ef655ff2bf47814901 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 10 May 2016 10:46:06 -0300 Subject: [PATCH 14/22] Init crud proposicao --- materia/forms.py | 34 ----- materia/layouts.yaml | 10 +- materia/urls.py | 12 +- materia/views.py | 129 ++---------------- templates/base.html | 2 +- .../materia/proposicao/proposicao_list.html | 40 ------ .../proposicao.html => proposicao_form.html} | 0 7 files changed, 23 insertions(+), 204 deletions(-) delete mode 100644 templates/materia/proposicao/proposicao_list.html rename templates/materia/{proposicao/proposicao.html => proposicao_form.html} (100%) diff --git a/materia/forms.py b/materia/forms.py index 81dc4a778..889af33a2 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -56,40 +56,6 @@ class ProposicaoForm(ModelForm): model = Proposicao fields = ['tipo', 'data_envio', 'descricao', 'texto_original'] - def __init__(self, excluir=False, *args, **kwargs): - more = [] - if excluir: - more = [Submit('Excluir', 'Excluir')] - - row1 = crispy_layout_mixin.to_row( - [('tipo', 8), ('data_envio', 4)]) - row2 = crispy_layout_mixin.to_row( - [('descricao', 12)]) - row3 = crispy_layout_mixin.to_row( - [('tipo_materia', 4), ('numero_materia', 4), ('ano_materia', 4)]) - row4 = crispy_layout_mixin.to_row( - [('texto_original', 12)]) - - self.helper = FormHelper() - self.helper.layout = Layout( - Fieldset(_('Incluir Proposição'), - row1, row2, row3, row4, - HTML(""" -
-

- -

- """, ), - form_actions(more=more)) - ) - super(ProposicaoForm, self).__init__( - *args, **kwargs) - class AcompanhamentoMateriaForm(ModelForm): diff --git a/materia/layouts.yaml b/materia/layouts.yaml index 272cb006e..dee64a9d5 100644 --- a/materia/layouts.yaml +++ b/materia/layouts.yaml @@ -89,10 +89,12 @@ TipoProposicao: Proposicao: Proposição: - - tipo dat_criacao_FIXME data_recebimento - - descricao_FIXME - - tip_id_basica_FIXME num_ident_basica_FIXME ano_ident_basica_FIXME - - nom_arquivo_FIXME modelo_FIXME + - tipo data_envio + - descricao + Materia: + - tipo_materia numero_materia ano_materia + Texto: + - texto_original StatusTramitacao: Status Tramitação: diff --git a/materia/urls.py b/materia/urls.py index 332623881..31ee3db9c 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -8,8 +8,7 @@ from materia.views import (AcompanhamentoConfirmarView, MateriaLegislativaCrud, MateriaLegislativaPesquisaView, MateriaTaView, NumeracaoCrud, OrgaoCrud, OrigemCrud, - ProposicaoEditView, ProposicaoListView, - ProposicaoTaView, ProposicaoView, + ProposicaoCrud, ProposicaoTaView, RegimeTramitacaoCrud, RelatoriaCrud, StatusTramitacaoCrud, TipoAutorCrud, TipoDocumentoCrud, TipoFimRelatoriaCrud, @@ -29,7 +28,8 @@ urlpatterns = [ LegislacaoCitadaCrud.get_urls() + TramitacaoCrud.get_urls() + RelatoriaCrud.get_urls() + - DocumentoAcessorioCrud.get_urls())), + DocumentoAcessorioCrud.get_urls() + + ProposicaoCrud.get_urls())), # Integração com Compilação url(r'^materia/(?P[0-9]+)/ta$', @@ -55,12 +55,6 @@ urlpatterns = [ url(r'^sistema/materia/status-tramitacao/', include(StatusTramitacaoCrud.get_urls())), url(r'^sistema/materia/orgao/', include(OrgaoCrud.get_urls())), - url(r'^materia/proposicao$', - ProposicaoView.as_view(), name='adicionar_proposicao'), - url(r'^materia/proposicao_list$', - ProposicaoListView.as_view(), name='list_proposicao'), - url(r'^materia/proposicao/(?P[0-9]+)/edit$', - ProposicaoEditView.as_view(), name='editar_proposicao'), url(r'^materia/pesquisar-materia$', MateriaLegislativaPesquisaView.as_view(), name='pesquisar_materia'), url(r'^materia/(?P\d+)/acompanhar-materia/$', diff --git a/materia/views.py b/materia/views.py index 6a3606ef1..8166ff407 100644 --- a/materia/views.py +++ b/materia/views.py @@ -54,11 +54,22 @@ TipoAutorCrud = Crud.build(TipoAutor, 'tipo_autor') AutorCrud = Crud.build(Autor, 'autor') OrgaoCrud = Crud.build(Orgao, 'orgao') TipoProposicaoCrud = Crud.build(TipoProposicao, 'tipo_proposicao') -ProposicaoCrud = Crud.build(Proposicao, '') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') UnidadeTramitacaoCrud = Crud.build(UnidadeTramitacao, 'unidade_tramitacao') -RelatoriaCrud = MasterDetailCrud.build(Relatoria, 'materia', '') + +class ProposicaoCrud(Crud): + model = Proposicao + help_path = '' + + class BaseMixin(crud.base.CrudBaseMixin): + list_field_names = ['data_envio', 'tipo', 'descricao'] + + class CreateView(crud.base.CrudCreateView): + form_class = ProposicaoForm + + class UpdateView(crud.base.CrudUpdateView): + form_class = ProposicaoForm class RelatoriaCrud(MasterDetailCrud): @@ -624,27 +635,6 @@ def do_envia_email_tramitacao(request, materia): return None -class ProposicaoListView(ListView): - template_name = "materia/proposicao/proposicao_list.html" - paginate_by = 10 - model = Proposicao - - def get_queryset(self): - return Proposicao.objects.all().order_by('data_envio', - 'tipo', - 'descricao') - - def get_context_data(self, **kwargs): - context = super(ProposicaoListView, self).get_context_data(**kwargs) - - paginator = context['paginator'] - page_obj = context['page_obj'] - - context['page_range'] = make_pagination( - page_obj.number, paginator.num_pages) - return context - - class MateriaLegislativaPesquisaView(FilterView): model = MateriaLegislativa filterset_class = MateriaLegislativaFilterSet @@ -719,99 +709,6 @@ class MateriaLegislativaPesquisaView(FilterView): return self.render_to_response(context) -class ProposicaoView(CreateView): - template_name = "materia/proposicao/proposicao.html" - form_class = ProposicaoForm - - def get_success_url(self): - return reverse('materia:list_proposicao') - - def get(self, request, *args, **kwargs): - return self.render_to_response({'form': self.get_form()}) - - def post(self, request, *args, **kwargs): - form = self.get_form() - - if form.is_valid(): - proposicao = form.save(commit=False) - tipo = TipoProposicao.objects.get(id=form.data['tipo']) - if tipo.descricao == 'Parecer': - try: - materia = MateriaLegislativa.objects.get( - tipo_id=int(form.data['tipo_materia']), - ano=int(form.data['ano_materia']), - numero=int(form.data['numero_materia'])) - except ObjectDoesNotExist: - msg = _('Matéria adicionada não existe!') - messages.add_message(request, messages.INFO, msg) - return self.render_to_response({'form': form}) - else: - proposicao.autor = materia.autoria_set.first().autor - proposicao.materia = materia - proposicao.save() - return redirect(self.get_success_url()) - else: - return self.render_to_response({'form': form}) - - -class ProposicaoEditView(CreateView): - template_name = "materia/proposicao/proposicao.html" - form_class = ProposicaoForm - - def get_success_url(self): - return reverse('materia:list_proposicao') - - def get(self, request, *args, **kwargs): - proposicao = Proposicao.objects.get(id=kwargs['pk']) - return self.render_to_response({'form': ProposicaoForm( - excluir=True, - instance=proposicao)}) - - def post(self, request, *args, **kwargs): - form = self.get_form() - proposicao = Proposicao.objects.get(id=kwargs['pk']) - if form.is_valid(): - if 'Excluir' in request.POST: - if proposicao.data_envio: - proposicao.data_envio = None - proposicao.save() - else: - proposicao.delete() - if 'salvar' or "remover-foto" in request.POST: - if 'texto_original' in request.FILES: - # if os.unlink(proposicao.texto_original.path): - # proposicao.texto_original = None - proposicao.texto_original = request.FILES['texto_original'] - tipo = TipoProposicao.objects.get(id=form.data['tipo']) - proposicao.tipo = tipo - proposicao.descricao = form.data['descricao'] - if tipo.descricao == 'Parecer': - try: - materia = MateriaLegislativa.objects.get( - tipo_id=int(form.data['tipo_materia']), - ano=int(form.data['ano_materia']), - numero=int(form.data['numero_materia'])) - except ObjectDoesNotExist: - msg = _('Matéria adicionada não existe!') - messages.add_message(request, messages.INFO, msg) - return self.render_to_response({'form': form}) - else: - proposicao.autor = materia.autoria_set.first().autor - proposicao.materia = materia - if not proposicao.data_envio: - proposicao.data_envio = datetime.now() - if "remover-texto" in request.POST: - try: - os.unlink(proposicao.texto_original.path) - except OSError: - pass # Should log this error!!!!! - proposicao.texto_original = None - proposicao.save() - return redirect(self.get_success_url()) - else: - return self.render_to_response({'form': form}) - - class MateriaTaView(IntegracaoTaView): model = MateriaLegislativa model_type_foreignkey = TipoMateriaLegislativa diff --git a/templates/base.html b/templates/base.html index a2eacf6dc..4822ebc2d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -67,7 +67,7 @@