Browse Source

Refactor Preposição Form and Add Preposição List

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
e4d875f711
  1. 7
      materia/urls.py
  2. 67
      materia/views.py
  3. 7
      templates/base.html
  4. 14
      templates/crud/form.html
  5. 35
      templates/materia/proposicao.html
  6. 38
      templates/materia/proposicao_list.html
  7. 62
      templates/paginacao.html

7
materia/urls.py

@ -5,7 +5,8 @@ from materia.views import (AutoriaEditView, AutoriaView,
FormularioCadastroView, FormularioSimplificadoView,
LegislacaoCitadaEditView, LegislacaoCitadaView,
MateriaAnexadaEditView, MateriaAnexadaView,
NumeracaoEditView, NumeracaoView, ProposicaoView,
NumeracaoEditView, NumeracaoView,
ProposicaoListView, ProposicaoView,
RelatoriaEditView, RelatoriaView,
TramitacaoEditView, TramitacaoView, autor_crud,
materia_legislativa_crud, orgao_crud, origem_crud,
@ -72,5 +73,7 @@ urlpatterns = [
url(r'^materia/(?P<pk>\d+)/relatoria/(?P<id>\d+)/edit$',
RelatoriaEditView.as_view(), name='relatoria_edit'),
url(r'^materia/proposicao$',
ProposicaoView.as_view(), name='proposicao'),
ProposicaoView.as_view(), name='adicionar_proposicao'),
url(r'^materia/proposicao_list$',
ProposicaoListView.as_view(), name='list_proposicao'),
]

67
materia/views.py

@ -1,15 +1,20 @@
from datetime import date, datetime
from re import sub
import sapl
from comissoes.models import Comissao, Composicao
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, ButtonHolder, Fieldset, Layout, Submit, Column
from crispy_forms.layout import (HTML, ButtonHolder, Column, Fieldset, Layout,
Submit)
from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.forms import ModelForm
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.edit import FormMixin
from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica
from sapl.crud import build_crud
@ -22,7 +27,6 @@ from .models import (Anexada, Autor, Autoria, DespachoInicial,
TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao,
Tramitacao, UnidadeTramitacao)
origem_crud = build_crud(
Origem, 'origem', [
@ -1764,7 +1768,7 @@ class ProposicaoView(FormMixin, GenericView):
template_name = "materia/proposicao.html"
def get_success_url(self):
return reverse('proposicao')
return reverse('list_proposicao')
def get(self, request, *args, **kwargs):
form = ProposicaoForm()
@ -1774,26 +1778,51 @@ class ProposicaoView(FormMixin, GenericView):
form = ProposicaoForm(request.POST)
if form.is_valid():
proposicao = form.save(commit=False)
if 'texto_original' in request.FILES:
proposicao.texto_original = request.FILES['texto_original']
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:
return self.render_to_response(
{'form': form,
'error': 'Matéria adiconada não existe!'})
else:
proposicao.autor = materia.autoria_set.first().autor
proposicao.materia = materia
proposicao.data_envio = datetime.now()
proposicao.save()
tipo = TipoProposicao.objects.get(
id=int(request.POST['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:
return self.render_to_response(
{'form': form,
'error': 'Matéria adicionada não existe!'})
else:
proposicao.autor = materia.autoria_set.first().autor
proposicao.materia = materia
proposicao.descricao = sub('&nbsp;',
' ',
strip_tags(form.data['descricao']))
# proposicao.data_envio = datetime.now()
proposicao.save()
return self.form_valid(form)
else:
self.render_to_response({'form': form})
return self.render_to_response({'form': form})
class ProposicaoListView(ListView):
template_name = "materia/proposicao_list.html"
paginate_by = 10
model = Proposicao
def get_queryset(self):
return Proposicao.objects.all().order_by('-data_envio')
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'] = sapl.crud.make_pagination(
page_obj.number, paginator.num_pages)
return context

7
templates/base.html

@ -77,7 +77,7 @@
</li>
<li class="nav__item has-dropdown"><a class="nav__link">Atividade Legislativa</a>
<ul class="nav__sub-nav dropdown">
<li class="nav__sub-item"><a class="nav__sub-link" href="{% url 'proposicao' %}">Proposições</a></li>
<li class="nav__sub-item"><a class="nav__sub-link" href="{% url 'list_proposicao' %}">Proposições</a></li>
<li class="nav__sub-item"><a class="nav__sub-link" href="{% url 'materialegislativa:list' %}">Matérias Legislativas</a></li>
<li class="nav__sub-item"><a class="nav__sub-link" href="{% url 'sessaoplenaria:list' %}">Sessões Plenárias</a></li>
<li class="nav__sub-item"><a class="nav__sub-link" href="#">Pautas das Sessões</a></li>
@ -225,6 +225,11 @@
});
});
</script>
{% block extra_js %}
{% endblock %}
{% endblock foot_js %}
</body>
</html>

14
templates/crud/form.html

@ -4,17 +4,3 @@
{% block base_content %}
{% crispy form %}
{% endblock %}
{% block foot_js %}
<script type="text/javascript">
$(function () {
$('.dateinput').fdatepicker({
// TODO localize
format: 'dd/mm/yyyy',
language: 'pt',
endDate: '31/12/2100',
todayBtn: true
});
});
</script>
{% endblock %}

35
templates/materia/proposicao.html

@ -2,7 +2,42 @@
{% load i18n %}
{% load crispy_forms_tags %}
{% block actions %}<!-- Remvoer botões 'Editar' e 'Excluir' -->{% endblock %}
{% block detail_content %}
{% if error %} <h5 align="center"><font color="#FF0000">{{ error }}</font></h5> {% endif %}
{% crispy form %}
{% endblock %}
{% block extra_js %}
<script type="text/javascript">
function disable_fields() {
$("#id_tipo_materia").val("");
$("#id_numero_materia").val("");
$("#id_ano_materia").val("");
$("#id_tipo_materia").attr("disabled", "disabled");
$("#id_numero_materia").attr("disabled", "disabled");
$("#id_ano_materia").attr("disabled", "disabled");
}
function enable_fields() {
$("#id_tipo_materia").removeAttr('disabled');
$("#id_numero_materia").removeAttr('disabled');
$("#id_ano_materia").removeAttr('disabled');
}
$(function () {
disable_fields();
$("#id_tipo").change(function() {
if ($("#id_tipo").val() == 9) { // parecer
enable_fields();
}
else {
disable_fields();
}
});
});
</script>
{% endblock %}

38
templates/materia/proposicao_list.html

@ -0,0 +1,38 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block actions %}<!-- Remvoer botões 'Editar' e 'Excluir' -->{% endblock %}
{% block sections_nav %}
<h2><b>Proposições</b></h2>
<br />
<dl class="sub-nav left">
<dd><a href="{% url 'adicionar_proposicao' %}" class="button secondary">Nova Proposição</a></dd>
</dl>
{% endblock %}
{% block detail_content %}
<table width="100%">
<tr>
<th>Enviada em</th>
<th>Tipo</th>
<th>Descrição</th>
<th>Incorporada?</th>
</tr>
{% for proposicao in page_obj %}
<tr>
{% if proposicao.data_envio %}
<td><a href=""><b>{{ proposicao.data_envio|date:'d/m/Y H:i:s' }}</b></a></td>
{% else %}
<td><a href=""><b>Em elaboração...</b></a></td>
{% endif %}
<td>{{ proposicao.tipo }}</td>
<td>{{ proposicao.descricao|safe }}</td>
<td>{% if proposicao.materia %} Sim {% else %} Não {% endif %}</td>
</tr>
{% endfor %}
</table>
{% include "paginacao.html" %}
{% endblock %}

62
templates/paginacao.html

@ -1,31 +1,35 @@
{% if is_paginated %}
<nav class="pagination-centered">
<ul class="pagination">
{% if page_obj.has_previous %}
<li>
<a href="?page={{ page_obj.previous_page_number }}">
<span class="arrow">&laquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&laquo;</a></li>
{% endif %}
{% if is_paginated %}
<nav class="pagination-centered">
<ul class="pagination">
{% if page_obj.has_previous %}
<li>
<a href="?page={{ page_obj.previous_page_number }}">
<span class="arrow">&laquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&laquo;</a></li>
{% endif %}
{% for page in paginator.page_range %}
<li {% if page == page_obj.number %}class="active current"{% endif %}>
<a href="?page={{ page }}">{{ page }}</a>
</li>
{% endfor %}
{% for page in page_range %}
{% if page == None or page == 'None' %}
...
{% else %}
<li {% if page == page_obj.number %} class="active current" {% endif %}>
<a href="?page={{ page }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li>
<a href="?page={{ page_obj.next_page_number }}">
<span class="arrow">&raquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
{% if page_obj.has_next %}
<li>
<a href="?page={{ page_obj.next_page_number }}">
<span class="arrow">&raquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
Loading…
Cancel
Save