From c7341b476f0eaa36aaae5687da15375bb49b6941 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 23 Nov 2015 13:04:58 -0200 Subject: [PATCH] Add form to Proposicao --- .../0011_proposicao_texto_original.py | 20 ++++ materia/models.py | 9 +- materia/urls.py | 18 ++-- materia/views.py | 94 ++++++++++++++++++- painel/views.py | 1 - .../migrations/0007_auto_20151123_1258.py | 19 ++++ templates/materia/proposicao.html | 6 ++ 7 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 materia/migrations/0011_proposicao_texto_original.py create mode 100644 parlamentares/migrations/0007_auto_20151123_1258.py create mode 100644 templates/materia/proposicao.html diff --git a/materia/migrations/0011_proposicao_texto_original.py b/materia/migrations/0011_proposicao_texto_original.py new file mode 100644 index 000000000..8a7a79232 --- /dev/null +++ b/materia/migrations/0011_proposicao_texto_original.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import materia.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0010_auto_20151117_1551'), + ] + + operations = [ + migrations.AddField( + model_name='proposicao', + name='texto_original', + field=models.FileField(upload_to=materia.models.texto_upload_path, verbose_name='Texto Original (PDF)', blank=True, null=True), + ), + ] diff --git a/materia/models.py b/materia/models.py index 4274222fd..292cda6f6 100644 --- a/materia/models.py +++ b/materia/models.py @@ -425,7 +425,6 @@ class TipoProposicao(models.Model): class Proposicao(models.Model): - materia = models.ForeignKey(MateriaLegislativa, blank=True, null=True) autor = models.ForeignKey(Autor) tipo = models.ForeignKey(TipoProposicao, verbose_name=_('Tipo')) # XXX data_envio was not null, but actual data said otherwise!!! @@ -443,9 +442,7 @@ class Proposicao(models.Model): verbose_name=_('Justificativa da Devolução')) numero_proposicao = models.PositiveIntegerField( blank=True, null=True, verbose_name=_('Número')) - # ind_enviado and ind_devolvido collapsed as char field (status) - status = models.CharField(blank=True, null=True, max_length=1, @@ -453,12 +450,16 @@ class Proposicao(models.Model): ('D', 'Devolvida'), ('I', 'Incorporada')), verbose_name=_('Status Proposição')) - # mutually exclusive (depend on tipo.materia_ou_documento) materia = models.ForeignKey( MateriaLegislativa, blank=True, null=True, verbose_name=_('Matéria')) documento = models.ForeignKey( DocumentoAcessorio, blank=True, null=True, verbose_name=_('Documento')) + texto_original = models.FileField( + blank=True, + null=True, + upload_to=texto_upload_path, + verbose_name=_('Texto Original (PDF)')) class Meta: verbose_name = _('Proposição') diff --git a/materia/urls.py b/materia/urls.py index ff20065cf..4deccbd68 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -5,14 +5,14 @@ from materia.views import (AutoriaEditView, AutoriaView, FormularioCadastroView, FormularioSimplificadoView, LegislacaoCitadaEditView, LegislacaoCitadaView, MateriaAnexadaEditView, MateriaAnexadaView, - NumeracaoEditView, NumeracaoView, RelatoriaEditView, - RelatoriaView, TramitacaoEditView, TramitacaoView, - autor_crud, materia_legislativa_crud, orgao_crud, - origem_crud, regime_tramitacao_crud, - status_tramitacao_crud, tipo_autor_crud, - tipo_documento_crud, tipo_fim_relatoria_crud, - tipo_materia_crud, tipo_proposicao_crud, - unidade_tramitacao_crud) + NumeracaoEditView, NumeracaoView, ProposicaoView, + RelatoriaEditView, RelatoriaView, + TramitacaoEditView, TramitacaoView, autor_crud, + materia_legislativa_crud, orgao_crud, origem_crud, + regime_tramitacao_crud, status_tramitacao_crud, + tipo_autor_crud, tipo_documento_crud, + tipo_fim_relatoria_crud, tipo_materia_crud, + tipo_proposicao_crud, unidade_tramitacao_crud) urlpatterns = [ url(r'^sistema/proposicoes/tipo/', include(tipo_proposicao_crud.urls)), @@ -71,4 +71,6 @@ urlpatterns = [ AutoriaEditView.as_view(), name='autoria_edit'), url(r'^materia/(?P\d+)/relatoria/(?P\d+)/edit$', RelatoriaEditView.as_view(), name='relatoria_edit'), + url(r'^materia/proposicao$', + ProposicaoView.as_view(), name='proposicao'), ] diff --git a/materia/views.py b/materia/views.py index 5da76396f..a51b29095 100644 --- a/materia/views.py +++ b/materia/views.py @@ -217,6 +217,12 @@ tramitacao_crud = build_crud( ]) +def get_tipos_proposicao(): + return [('', 'Selecione')] \ + + [(t.id, t.descricao) + for t in TipoProposicao.objects.all()] + + def get_tipos_materia(): return [('', 'Selecione')] \ + [(t.id, t.sigla + ' - ' + t.descricao) @@ -1246,7 +1252,8 @@ class RelatoriaEditView(FormMixin, GenericView): form = RelatoriaForm(request.POST) materia = MateriaLegislativa.objects.get(id=kwargs['pk']) relatoria = Relatoria.objects.get(id=kwargs['id']) - composicao = Composicao.objects.filter(comissao=relatoria.comissao).last() + composicao = Composicao.objects.filter( + comissao=relatoria.comissao).last() parlamentares = composicao.participacao_set.all() if form.is_valid(): @@ -1688,3 +1695,88 @@ class AutoriaEditView(GenericView): def get_success_url(self): pk = self.kwargs['pk'] return reverse('autoria', kwargs={'pk': pk}) + + +class ProposicaoForm(ModelForm): + tipo = forms.ChoiceField(required=True, + label='Tipo', + choices=get_tipos_proposicao(), + widget=forms.Select( + attrs={'class': 'selector'})) + + descricao = forms.CharField( + label='Descrição', required=True) + + tipo_materia = forms.ChoiceField(required=False, + label='Matéria Vinculada', + choices=get_tipos_materia(), + widget=forms.Select( + attrs={'class': 'selector'})) + + numero_materia = forms.CharField( + label='Número', required=False) + + ano_materia = forms.CharField( + label='Ano', required=False) + + class Meta: + model = Proposicao + fields = ['tipo', + 'descricao', + 'texto_original'] + + def __init__(self, *args, **kwargs): + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset('Incluir Proposição', + HTML( + "
    "), + HTML("
  • "), + 'tipo', + HTML("
  • "), + HTML("
"), + HTML( + "
    "), + HTML("
  • "), + 'descricao', + HTML("
  • "), + HTML("
"), + HTML( + "
    "), + HTML("
  • "), + 'tipo_materia', + HTML("
  • "), + HTML("
  • "), + 'numero_materia', + HTML("
  • "), + HTML("
  • "), + 'ano_materia', + HTML("
  • "), + HTML("
"), + HTML( + "
    "), + HTML("
  • "), + 'texto_original', + HTML("
  • "), + HTML("
"), + ButtonHolder( + Submit('submit', 'Salvar', + css_class='button primary') + ) + ), + ) + super(ProposicaoForm, self).__init__( + *args, **kwargs) + + +class ProposicaoView(FormMixin, GenericView): + template_name = "materia/proposicao.html" + + def get_success_url(self): + return reverse('proposicao') + + def get(self, request, *args, **kwargs): + form = ProposicaoForm() + + return self.render_to_response( + {'form': form}) diff --git a/painel/views.py b/painel/views.py index b67bf28eb..9b9c8a59b 100644 --- a/painel/views.py +++ b/painel/views.py @@ -71,7 +71,6 @@ def painel_votacao_view(request): def get_dados_painel(request, pk): - # Sessão Plenária sessao_plenaria_id = pk sessao_plenaria = SessaoPlenaria.objects.get(id=sessao_plenaria_id) diff --git a/parlamentares/migrations/0007_auto_20151123_1258.py b/parlamentares/migrations/0007_auto_20151123_1258.py new file mode 100644 index 000000000..e26a752ff --- /dev/null +++ b/parlamentares/migrations/0007_auto_20151123_1258.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('parlamentares', '0006_auto_20151119_1318'), + ] + + operations = [ + migrations.AlterField( + model_name='parlamentar', + name='unidade_deliberativa', + field=models.BooleanField(), + ), + ] diff --git a/templates/materia/proposicao.html b/templates/materia/proposicao.html new file mode 100644 index 000000000..93a889772 --- /dev/null +++ b/templates/materia/proposicao.html @@ -0,0 +1,6 @@ +{% extends "crud/form.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} +{% endblock %} \ No newline at end of file