Browse Source

Add parlamentar cadastro and editar

pull/11/merge
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
905a5da184
  1. 25
      parlamentares/migrations/0008_auto_20151126_1332.py
  2. 22
      parlamentares/migrations/0009_auto_20151126_1334.py
  3. 4
      parlamentares/models.py
  4. 16
      parlamentares/urls.py
  5. 187
      parlamentares/views.py
  6. 7
      templates/parlamentares/parlamentares_cadastro.html
  7. 2
      templates/parlamentares/parlamentares_detail.html

25
parlamentares/migrations/0008_auto_20151126_1332.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('parlamentares', '0007_auto_20151123_1258'),
]
operations = [
migrations.AlterField(
model_name='parlamentar',
name='cod_casa',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Cód. Casa'),
),
migrations.AlterField(
model_name='parlamentar',
name='nome_parlamentar',
field=models.CharField(default=1, verbose_name='Nome Parlamentar', max_length=50),
preserve_default=False,
),
]

22
parlamentares/migrations/0009_auto_20151126_1334.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('parlamentares', '0008_auto_20151126_1332'),
]
operations = [
migrations.RemoveField(
model_name='parlamentar',
name='cod_casa',
),
migrations.RemoveField(
model_name='parlamentar',
name='unidade_deliberativa',
),
]

4
parlamentares/models.py

@ -217,8 +217,6 @@ class Parlamentar(models.Model):
max_length=50, verbose_name=_('Nome Completo'))
nome_parlamentar = models.CharField(
max_length=50,
blank=True,
null=True,
verbose_name=_('Nome Parlamentar'))
sexo = models.CharField(
max_length=1, verbose_name=_('Sexo'), choices=SEXO_CHOICE)
@ -233,7 +231,6 @@ class Parlamentar(models.Model):
blank=True,
null=True,
verbose_name=_('Título de Eleitor'))
cod_casa = models.PositiveIntegerField()
numero_gab_parlamentar = models.CharField(
max_length=10, blank=True, null=True, verbose_name=_('Nº Gabinete'))
telefone = models.CharField(
@ -276,7 +273,6 @@ class Parlamentar(models.Model):
ativo = models.BooleanField(verbose_name=_('Ativo na Casa?'))
biografia = models.TextField(
blank=True, null=True, verbose_name=_('Biografia'))
unidade_deliberativa = models.BooleanField()
fotografia = models.FileField(
blank=True,
null=True,

16
parlamentares/urls.py

@ -1,9 +1,11 @@
from django.conf.urls import include, url
from parlamentares.views import (ParlamentaresView, cargo_mesa_crud,
coligacao_crud, legislatura_crud,
nivel_instrucao_crud, parlamentar_crud,
partido_crud, sessao_legislativa_crud,
from parlamentares.views import (ParlamentaresCadastroView,
ParlamentaresEditarView,
ParlamentaresView,
cargo_mesa_crud, coligacao_crud,
legislatura_crud, nivel_instrucao_crud,
parlamentar_crud, partido_crud,
sessao_legislativa_crud,
tipo_afastamento_crud, tipo_dependente_crud,
tipo_militar_crud)
@ -28,6 +30,10 @@ urlpatterns = [
url(r'^parlamentares/list$',
ParlamentaresView.as_view(), name='parlamentares'),
url(r'^parlamentares/(?P<pk>\d+)/cadastro$',
ParlamentaresCadastroView.as_view(), name='parlamentares_cadastro'),
url(r'^parlamentares/(?P<pk>\d+)/editar$',
ParlamentaresEditarView.as_view(), name='parlamentares_editar'),
url(r'^parlamentares/',
include(parlamentar_crud.urls)),
]

187
parlamentares/views.py

@ -1,8 +1,17 @@
import sapl
from re import sub
from crispy_forms.helper import FormHelper
from crispy_forms.layout import (HTML, ButtonHolder, Column, Fieldset, Layout,
Submit)
from django import forms
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 vanilla import GenericView
from django.views.generic.edit import FormMixin
from sapl.crud import build_crud
from vanilla import GenericView
from .models import (CargoMesa, Coligacao, Dependente, Filiacao, Legislatura,
Mandato, NivelInstrucao, Parlamentar, Partido,
@ -166,3 +175,177 @@ class ParlamentaresView(GenericView):
'mandatos': Mandato.objects.all(),
'form': form,
'filiacao': Filiacao.objects.all()})
class HorizontalRadioRenderer(forms.RadioSelect.renderer):
def render(self):
return mark_safe(u' '.join([u'%s ' % w for w in self]))
class ParlamentaresForm (ModelForm):
ativo = forms.TypedChoiceField(
coerce=lambda x: x == 'True',
choices=((True, 'Sim'), (False, 'Não')),
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer
)
)
class Meta:
model = Parlamentar
fields = ['nome_parlamentar',
'ativo',
'nome_completo',
'nivel_instrucao',
'sexo',
'cpf',
'rg',
'titulo_eleitor',
'data_nascimento',
'situacao_militar',
'profissao',
'endereco_web',
'email',
'numero_gab_parlamentar',
'telefone',
'fax',
'endereco_residencia',
'cep_residencia',
'municipio_residencia',
'telefone_residencia',
'fax_residencia',
'locais_atuacao',
'fotografia',
'biografia']
def __init__(self, *args, **kwargs):
row1 = sapl.layout.to_row(
[('nome_parlamentar', 8), ('ativo', 4)])
row2 = sapl.layout.to_row(
[('nome_completo', 12)])
row3 = sapl.layout.to_row(
[('nivel_instrucao', 4),
('sexo', 4),
('data_nascimento', 4)])
row4 = sapl.layout.to_row(
[('cpf', 4),
('rg', 4),
('titulo_eleitor', 4)])
row5 = sapl.layout.to_row(
[('situacao_militar', 6),
('profissao', 6)])
row6 = sapl.layout.to_row(
[('endereco_web', 12)])
row7 = sapl.layout.to_row(
[('email', 12)])
row8 = sapl.layout.to_row(
[('numero_gab_parlamentar', 4),
('telefone', 4),
('fax', 4)])
row9 = sapl.layout.to_row(
[('endereco_residencia', 6),
('cep_residencia', 6)])
row10 = sapl.layout.to_row(
[('municipio_residencia', 12)])
row11 = sapl.layout.to_row(
[('telefone_residencia', 6),
('fax_residencia', 6)])
row12 = sapl.layout.to_row(
[('locais_atuacao', 12)])
row13 = sapl.layout.to_row(
[('fotografia', 12)])
row14 = sapl.layout.to_row(
[('biografia', 12)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset('Cadastro do Parlamentar',
row1, row2, row3, row4, row5,
row6, row7, row8, row9, row10,
row11, row12, row13, row14,
ButtonHolder(
Submit('sumbmit', 'Salvar',
css_class='button primary')
))
)
super(ParlamentaresForm, self).__init__(
*args, **kwargs)
class ParlamentaresCadastroView(FormMixin, GenericView):
template_name = "parlamentares/parlamentares_cadastro.html"
def get_success_url(self):
return reverse('parlamentares')
def get(self, request, *args, **kwargs):
form = ParlamentaresForm()
pk = kwargs['pk']
return self.render_to_response({'form': form, 'legislatura_id': pk})
def post(self, request, *args, **kwargs):
form = ParlamentaresForm(request.POST)
pk = kwargs['pk']
if form.is_valid():
parlamentar = form.save(commit=False)
if 'fotografia' in request.FILES:
parlamentar.fotografia = request.FILES['fotografia']
parlamentar.biografia = sub('&nbsp;',
' ',
strip_tags(form.data['biografia']))
parlamentar.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form, 'legislatura_id': pk})
class ParlamentaresEditarView(FormMixin, GenericView):
template_name = "parlamentares/parlamentares_cadastro.html"
def get_success_url(self):
return reverse('parlamentares')
def get(self, request, *args, **kwargs):
pk = kwargs['pk']
parlamentar = Parlamentar.objects.get(id=pk)
form = ParlamentaresForm(instance=parlamentar)
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
pk = kwargs['pk']
parlamentar = Parlamentar.objects.get(id=pk)
form = ParlamentaresForm(request.POST, instance=parlamentar)
if form.is_valid():
parlamentar = form.save(commit=False)
if 'fotografia' in request.FILES:
parlamentar.fotografia = request.FILES['fotografia']
parlamentar.biografia = sub('&nbsp;',
' ',
strip_tags(form.data['biografia']))
parlamentar.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form})

7
templates/parlamentares/parlamentares_cadastro.html

@ -0,0 +1,7 @@
{% extends "parlamentares/parlamentares_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
{% crispy form %}
{% endblock %}

2
templates/parlamentares/parlamentares_detail.html

@ -3,6 +3,6 @@
{% block sections_nav %}
<dl class="sub-nav left">
<dd><a href="" class="button secondary">{% trans 'Incluir Parlamentar' %}</a></dd>
<dd><a href="{% url 'parlamentares_cadastro' legislatura_id %}" id="incluir-parlamentar" class="button secondary">{% trans 'Incluir Parlamentar' %}</a></dd>
</dl>
{% endblock sections_nav %}

Loading…
Cancel
Save