diff --git a/materia/forms.py b/materia/forms.py index 7a2556d79..bb49c677c 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -40,39 +40,27 @@ class ProposicaoForm(ModelForm): class Meta: model = Proposicao - fields = ['tipo', - 'descricao', - 'texto_original'] - exclude = ['autor', - 'data_envio', - 'data_recebimento', - 'data_devolucao', - 'justificativa_devolucao', - 'numero_proposicao', - 'status', - 'materia', - 'documento'] + fields = ['tipo', 'data_envio', 'descricao', 'texto_original'] - def __init__(self, *args, **kwargs): + def __init__(self, excluir=False, *args, **kwargs): + more = [] + if excluir: + more = [Submit('Excluir', 'Excluir')] row1 = crispy_layout_mixin.to_row( - [('tipo', 12)]) + [('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)]) + [('tipo_materia', 4), ('numero_materia', 4), ('ano_materia', 4)]) row4 = crispy_layout_mixin.to_row( - [('texto_original', 10)]) - - row4.append( - Column(form_actions(), css_class='col-md-2')) + [('texto_original', 12)]) self.helper = FormHelper() self.helper.layout = Layout( Fieldset(_('Incluir Proposição'), - row1, row2, row3, row4) + row1, row2, row3, row4, + form_actions(more=more)) ) super(ProposicaoForm, self).__init__( *args, **kwargs) diff --git a/materia/migrations/0025_auto_20160311_1613.py b/materia/migrations/0025_auto_20160311_1613.py new file mode 100644 index 000000000..3223ea78c --- /dev/null +++ b/materia/migrations/0025_auto_20160311_1613.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-11 19:13 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0024_auto_20160311_1501'), + ] + + operations = [ + migrations.AlterField( + model_name='proposicao', + name='data_envio', + field=models.DateTimeField(blank=True, null=True, verbose_name='Data de Envio'), + ), + ] diff --git a/materia/models.py b/materia/models.py index adaeddce9..1d6f96d5c 100644 --- a/materia/models.py +++ b/materia/models.py @@ -429,7 +429,7 @@ class Proposicao(models.Model): tipo = models.ForeignKey(TipoProposicao, verbose_name=_('Tipo')) # XXX data_envio was not null, but actual data said otherwise!!! data_envio = models.DateTimeField( - null=True, verbose_name=_('Data de Envio')) + null=True, blank=True, verbose_name=_('Data de Envio')) data_recebimento = models.DateTimeField( blank=True, null=True, verbose_name=_('Data de Incorporação')) descricao = models.TextField(max_length=100, verbose_name=_('Descrição')) diff --git a/materia/urls.py b/materia/urls.py index 3475189c0..fd195051c 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -19,7 +19,7 @@ from materia.views import (AcompanhamentoConfirmarView, status_tramitacao_crud, tipo_autor_crud, tipo_documento_crud, tipo_fim_relatoria_crud, tipo_materia_crud, tipo_proposicao_crud, - unidade_tramitacao_crud) + unidade_tramitacao_crud, ProposicaoEditView) materia_legislativa_patterns = materia_legislativa_crud.urlpatterns @@ -95,6 +95,8 @@ urlpatterns = [ 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/pesquisar-materia-list$', diff --git a/materia/views.py b/materia/views.py index 9207c9aa6..7ea84ae23 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1188,12 +1188,14 @@ class AutoriaEditView(CreateView): class ProposicaoListView(ListView): - template_name = "materia/proposicao_list.html" + template_name = "materia/proposicao/proposicao_list.html" paginate_by = 10 model = Proposicao def get_queryset(self): - return Proposicao.objects.all().order_by('-data_envio') + return Proposicao.objects.all().order_by('data_envio', + 'tipo', + 'descricao') def get_context_data(self, **kwargs): context = super(ProposicaoListView, self).get_context_data(**kwargs) @@ -1387,27 +1389,22 @@ class PesquisaMateriaListView(ListView): return context -class ProposicaoView(FormView): - template_name = "materia/proposicao.html" +class ProposicaoView(CreateView): + template_name = "materia/proposicao/proposicao.html" + form_class = ProposicaoForm def get_success_url(self): return reverse('list_proposicao') def get(self, request, *args, **kwargs): - form = ProposicaoForm() - return self.render_to_response({'form': form}) + return self.render_to_response({'form': self.get_form()}) def post(self, request, *args, **kwargs): - form = ProposicaoForm(request.POST) + form = self.get_form() if form.is_valid(): proposicao = form.save(commit=False) - if 'texto_original' in request.FILES: - proposicao.texto_original = request.FILES['texto_original'] - - tipo = TipoProposicao.objects.get( - id=int(request.POST['tipo'])) - + tipo = TipoProposicao.objects.get(id=form.data['tipo']) if tipo.descricao == 'Parecer': try: materia = MateriaLegislativa.objects.get( @@ -1421,17 +1418,56 @@ class ProposicaoView(FormView): else: proposicao.autor = materia.autoria_set.first().autor proposicao.materia = materia - - proposicao.descricao = sub(' ', - ' ', - strip_tags(form.data['descricao'])) - # proposicao.data_envio = datetime.now() proposicao.save() - return self.form_valid(form) + 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('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: + proposicao.delete() + elif 'salvar' in request.POST: + if 'texto_original' in request.FILES: + 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 + proposicao.data_envio = datetime.now() + 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/materia/proposicao.html b/templates/materia/proposicao/proposicao.html similarity index 58% rename from templates/materia/proposicao.html rename to templates/materia/proposicao/proposicao.html index 22fb44591..961c80ad1 100644 --- a/templates/materia/proposicao.html +++ b/templates/materia/proposicao/proposicao.html @@ -1,13 +1,6 @@ -{% extends "crud/detail.html" %} +{% extends "crud/form.html" %} {% load i18n %} {% load crispy_forms_tags %} - -{% block actions %}{% endblock %} - -{% block detail_content %} - {% crispy form %} -{% endblock %} - {% block extra_js %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/templates/materia/proposicao_list.html b/templates/materia/proposicao/proposicao_list.html similarity index 63% rename from templates/materia/proposicao_list.html rename to templates/materia/proposicao/proposicao_list.html index 7aa17bd35..d666badbe 100644 --- a/templates/materia/proposicao_list.html +++ b/templates/materia/proposicao/proposicao_list.html @@ -13,20 +13,22 @@ {% endblock %} {% block detail_content %} - - - - - - - +
Enviada emTipoDescriçãoIncorporada?
+ + + + + + + + {% for proposicao in page_obj %} {% if proposicao.data_envio %} - + {% else %} - + {% endif %} @@ -35,4 +37,4 @@ {% endfor %}
Enviada emTipoDescriçãoIncorporada?
{{ proposicao.data_envio|date:'d/m/Y H:i:s' }}{{ proposicao.data_envio|date:'d/m/Y H:i' }}Em elaboração...Em elaboração...{{ proposicao.tipo }} {{ proposicao.descricao|safe }}
{% include "paginacao.html" %} -{% endblock %} \ No newline at end of file +{% endblock %}