Browse Source

Add form to relatoria in materia

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
decd74a366
  1. 17
      materia/urls.py
  2. 147
      materia/views.py
  3. 19
      parlamentares/migrations/0006_auto_20151119_1318.py
  4. 52
      templates/materia/relatoria.html
  5. 65
      templates/materia/relatoria_edit.html

17
materia/urls.py

@ -5,13 +5,14 @@ from materia.views import (AutoriaEditView, AutoriaView,
FormularioCadastroView, FormularioSimplificadoView, FormularioCadastroView, FormularioSimplificadoView,
LegislacaoCitadaEditView, LegislacaoCitadaView, LegislacaoCitadaEditView, LegislacaoCitadaView,
MateriaAnexadaEditView, MateriaAnexadaView, MateriaAnexadaEditView, MateriaAnexadaView,
NumeracaoEditView, NumeracaoView, RelatoriaView, NumeracaoEditView, NumeracaoView, RelatoriaEditView,
TramitacaoEditView, TramitacaoView, autor_crud, RelatoriaView, TramitacaoEditView, TramitacaoView,
materia_legislativa_crud, orgao_crud, origem_crud, autor_crud, materia_legislativa_crud, orgao_crud,
regime_tramitacao_crud, status_tramitacao_crud, origem_crud, regime_tramitacao_crud,
tipo_autor_crud, tipo_documento_crud, status_tramitacao_crud, tipo_autor_crud,
tipo_fim_relatoria_crud, tipo_materia_crud, tipo_documento_crud, tipo_fim_relatoria_crud,
tipo_proposicao_crud, unidade_tramitacao_crud) tipo_materia_crud, tipo_proposicao_crud,
unidade_tramitacao_crud)
urlpatterns = [ urlpatterns = [
url(r'^sistema/proposicoes/tipo/', include(tipo_proposicao_crud.urls)), url(r'^sistema/proposicoes/tipo/', include(tipo_proposicao_crud.urls)),
@ -68,4 +69,6 @@ urlpatterns = [
AutoriaView.as_view(), name='autoria'), AutoriaView.as_view(), name='autoria'),
url(r'^materia/(?P<pk>\d+)/autoria/(?P<id>\d+)/edit$', url(r'^materia/(?P<pk>\d+)/autoria/(?P<id>\d+)/edit$',
AutoriaEditView.as_view(), name='autoria_edit'), AutoriaEditView.as_view(), name='autoria_edit'),
url(r'^materia/(?P<pk>\d+)/relatoria/(?P<id>\d+)/edit$',
RelatoriaEditView.as_view(), name='relatoria_edit'),
] ]

147
materia/views.py

@ -7,11 +7,11 @@ from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.forms import ModelForm from django.forms import ModelForm
from django.shortcuts import render
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica
from comissoes.models import Composicao
from sapl.crud import build_crud from sapl.crud import build_crud
from vanilla import GenericView from vanilla import GenericView
@ -1192,18 +1192,151 @@ class DocumentoAcessorioEditView(FormMixin, GenericView):
return reverse('documento_acessorio', kwargs={'pk': pk}) return reverse('documento_acessorio', kwargs={'pk': pk})
class RelatoriaView(FormMixin, GenericView): class RelatoriaForm(ModelForm):
template_name = "materia/relatoria.html" data_designacao_relator = forms.DateField(
label=u'Data Designação',
input_formats=['%d/%m/%Y'],
required=False,
widget=forms.DateInput(
format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
data_destituicao_relator = forms.DateField(
label=u'Data Destituição',
input_formats=['%d/%m/%Y'],
required=False,
widget=forms.DateInput(
format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
class Meta:
model = Relatoria
fields = ['data_designacao_relator',
'comissao',
'parlamentar',
'data_destituicao_relator',
'tipo_fim_relatoria'
]
class RelatoriaEditView(FormMixin, GenericView):
template_name = "materia/relatoria_edit.html"
def get_success_url(self):
pk = self.kwargs['pk']
return reverse('relatoria', kwargs={'pk': pk})
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
form = RelatoriaForm()
materia = MateriaLegislativa.objects.get(id=kwargs['pk']) materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
relatorias = Relatoria.objects.filter(materia_id=kwargs['pk']) relatoria = Relatoria.objects.get(
form = None id=kwargs['id'])
composicao = Composicao.objects.get(comissao=relatoria.comissao)
parlamentares = composicao.participacao_set.all()
return self.render_to_response( return self.render_to_response(
{'materialegislativa': materia, {'materialegislativa': materia,
'form': form, 'form': form,
'relatorias': relatorias}) 'relatoria': relatoria,
'tipo_fim_relatorias': TipoFimRelatoria.objects.all(),
'parlamentares': parlamentares})
def post(self, request, *args, **kwargs):
form = RelatoriaForm(request.POST)
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
relatoria = Relatoria.objects.get(id=kwargs['id'])
composicao = Composicao.objects.get(comissao=relatoria.comissao)
parlamentares = composicao.participacao_set.all()
if form.is_valid():
if 'excluir' in request.POST:
relatoria.delete()
return self.form_valid(form)
elif 'salvar' in request.POST:
relatoria.materia = materia
relatoria.comissao = relatoria.comissao
relatoria.data_designacao_relator = form.cleaned_data[
'data_designacao_relator']
relatoria.data_destituicao_relator = form.cleaned_data[
'data_destituicao_relator']
relatoria.parlamentar = form.cleaned_data['parlamentar']
relatoria.tipo_fim_relatoria = form.cleaned_data[
'tipo_fim_relatoria']
relatoria.save()
return self.form_valid(form)
else:
return self.render_to_response(
{'materialegislativa': materia,
'form': form,
'relatoria': relatoria,
'tipo_fim_relatorias': TipoFimRelatoria.objects.all(),
'parlamentares': parlamentares})
class RelatoriaView(FormMixin, GenericView):
template_name = "materia/relatoria.html"
def get_success_url(self):
pk = self.kwargs['pk']
return reverse('relatoria', kwargs={'pk': pk})
def post(self, request, *args, **kwargs):
form = RelatoriaForm(request.POST)
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
relatorias = Relatoria.objects.filter(
materia_id=kwargs['pk']).order_by('-data_designacao_relator')
localizacao = Tramitacao.objects.filter(
materia=materia).last()
comissao = Comissao.objects.get(
id=localizacao.unidade_tramitacao_destino_id)
if form.is_valid():
relatoria = form.save(commit=False)
relatoria.materia = materia
relatoria.comissao = comissao
relatoria.save()
return self.form_valid(form)
else:
composicao = Composicao.objects.get(comissao=comissao)
parlamentares = composicao.participacao_set.all()
return self.render_to_response(
{'materialegislativa': materia,
'form': form,
'relatorias': relatorias,
'comissao': comissao,
'tipo_fim_relatoria': TipoFimRelatoria.objects.all(),
'parlamentares': parlamentares})
def get(self, request, *args, **kwargs):
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
relatorias = Relatoria.objects.filter(
materia_id=kwargs['pk']).order_by('-data_designacao_relator')
form = RelatoriaForm()
localizacao = Tramitacao.objects.filter(
materia=materia).last()
try:
comissao = Comissao.objects.get(
id=localizacao.unidade_tramitacao_destino_id)
except ObjectDoesNotExist:
return self.render_to_response(
{'materialegislativa': materia,
'form': form,
'relatorias': relatorias,
'error_localizacao': 'O local atual deve ser uma Comissão!'})
else:
composicao = Composicao.objects.get(comissao=comissao)
parlamentares = composicao.participacao_set.all()
return self.render_to_response(
{'materialegislativa': materia,
'form': form,
'relatorias': relatorias,
'comissao': comissao,
'tipo_fim_relatoria': TipoFimRelatoria.objects.all(),
'parlamentares': parlamentares})
class TramitacaoForm(ModelForm): class TramitacaoForm(ModelForm):
@ -1320,7 +1453,7 @@ class TramitacaoView(FormMixin, GenericView):
form = TramitacaoForm(request.POST) form = TramitacaoForm(request.POST)
materia = MateriaLegislativa.objects.get(id=kwargs['pk']) materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
tramitacoes_list = Tramitacao.objects.filter( tramitacoes_list = Tramitacao.objects.filter(
materia_id=kwargs['pk']) materia_id=kwargs['pk']).order_by('-data_tramitacao')
if form.is_valid(): if form.is_valid():
ultima_tramitacao = Tramitacao.objects.filter( ultima_tramitacao = Tramitacao.objects.filter(

19
parlamentares/migrations/0006_auto_20151119_1318.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', '0005_parlamentar_fotografia'),
]
operations = [
migrations.AlterField(
model_name='parlamentar',
name='unidade_deliberativa',
field=models.BooleanField(verbose_name='Unidade'),
),
]

52
templates/materia/relatoria.html

@ -22,13 +22,61 @@
</tr> </tr>
{% for r in relatorias %} {% for r in relatorias %}
<tr> <tr>
<td><a href="">{{r.data_designacao_relator|date:'d/m/Y'}}</a></td> <td><a href="{% url 'relatoria_edit' materialegislativa.id r.id %}">{{r.data_designacao_relator|date:'d/m/Y'}}</a></td>
<td>{{r.comissao}}</td> <td>{{r.comissao}}</td>
<td>{{r.parlamentar}}</td> <td>{{r.parlamentar}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
</fieldset> </fieldset>
<!-- {% crispy form %} -->
<fieldset>
<legend>Adicionar Relator</legend>
{% if error_localizacao %}
<h5 align="center"><font color="#FF0000">{{ error_localizacao }}</font></h5>
{% else %}
<form method="POST">
{% csrf_token %}
<ul class='small-block-grid-1 medium-block-grid-1 large-block-grid-1'>
<li>
Localização Atual
<input type="text" name="comissao" disabled value="{{comissao.nome}}" />
</li>
</ul>
<ul class='small-block-grid-2 medium-block-grid-2 large-block-grid-2'>
<li>
Data Designação*
<input type="text" name="data_designacao_relator" class ="dateinput" />
</li>
<li>
Data Destituição
<input type="text" name="data_destituicao_relator" class ="dateinput" />
</li>
</ul>
<ul class='small-block-grid-2 medium-block-grid-2 large-block-grid-2'>
<li>
Parlamentar*
<select name="parlamentar">
<option value=""> ---------- </option>
{% for p in parlamentares %}
<option value="{{p.parlamentar_id}}"> {{p.parlamentar}} </option>
{% endfor %}
</select>
</li>
<li>
Motivo Fim Relatoria
<select name="tipo_fim_relatoria">
<option value=""> ---------- </option>
{% for t in tipo_fim_relatoria %}
<option value="{{t.id}}"> {{t.descricao}} </option>
{% endfor %}
</select>
</li>
</ul>
<input type="submit" name="salvar" value="Salvar" class="primary button"/>
</form>
{% endif %}
</fieldset>
</fieldset> </fieldset>
{% endblock %} {% endblock %}

65
templates/materia/relatoria_edit.html

@ -0,0 +1,65 @@
{% extends "materia/materialegislativa_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
<fieldset>
<legend>Matéria Legislativa</legend>
<ul class="small-block-grid-3 medium-block-grid-3 large-block-grid-3">
<li>Tipo: <b>{{materialegislativa.tipo.sigla}}</b></li>
<li>Número: <b>{{materialegislativa.numero}}</b></li>
<li>Ano: <b>{{materialegislativa.ano}}</b></li>
</ul>
Ementa: <b>{{materialegislativa.ementa}}</b>
<fieldset>
<legend>Editar Relator</legend>
<form method="POST">
{% csrf_token %}
<ul class='small-block-grid-1 medium-block-grid-1 large-block-grid-1'>
<li>
Localização Atual
<input type="text" name="comissao" disabled value="{{relatoria.comissao.nome}}" />
</li>
</ul>
<ul class='small-block-grid-2 medium-block-grid-2 large-block-grid-2'>
<li>
Data Designação*
<input type="text" name="data_designacao_relator" class ="dateinput" value="{{relatoria.data_designacao_relator}}" />
</li>
<li>
Data Destituição
<input type="text" name="data_destituicao_relator" class ="dateinput" value="{{relatoria.data_destituicao_relator}}" />
</li>
</ul>
<ul class='small-block-grid-2 medium-block-grid-2 large-block-grid-2'>
<li>
Parlamentar*
<select name="parlamentar">
<option value=""> ---------- </option>
{% for p in parlamentares %}
<option value="{{p.parlamentar_id}}" {% if relatoria.parlamentar_id == p.parlamentar_id %} selected {% endif %}>
{{p.parlamentar}}
</option>
{% endfor %}
</select>
</li>
<li>
Motivo Fim Relatoria
<select name="tipo_fim_relatoria">
<option value=""> ---------- </option>
{% for t in tipo_fim_relatorias %}
<option value="{{t.id}}" {% if t.id == relatoria.tipo_fim_relatoria_id %} selected {% endif %}>
{{t.descricao}}
</option>
{% endfor %}
</select>
</li>
</ul>
<input type="submit" name="salvar" value="Salvar" class="primary button"/>
<input type="submit" name="excluir" value="Excluir" class="primary button"/>
</form>
</fieldset>
</fieldset>
{% endblock %}
Loading…
Cancel
Save