Browse Source

Replace forms.ChoiceField by forms.ModelChoiceField

pull/98/head
Edward Ribeiro 9 years ago
parent
commit
481d0cf7e3
  1. 5
      comissoes/views.py
  2. 146
      materia/views.py
  3. 23
      norma/views.py
  4. 92
      protocoloadm/views.py

5
comissoes/views.py

@ -1,4 +1,3 @@
import sapl
from crispy_forms.helper import FormHelper
from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit
from django import forms
@ -6,9 +5,11 @@ from django.core.urlresolvers import reverse
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormMixin
from vanilla import GenericView
import sapl
from parlamentares.models import Filiacao, Parlamentar
from sapl.crud import build_crud
from vanilla import GenericView
from .models import (CargoComissao, Comissao, Composicao, Participacao,
Periodo, TipoComissao)

146
materia/views.py

@ -224,18 +224,6 @@ 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)
for t in TipoMateriaLegislativa.objects.all()]
def get_range_anos():
return [('', 'Selecione')] \
+ [(year, year) for year in range(date.today().year, 1960, -1)]
@ -465,19 +453,14 @@ class FormularioCadastroView(FormMixin, GenericView):
return reverse('formulario_cadastro')
def get_tipos_documento():
return [('', 'Selecione')] \
+ [(t.id, t.descricao)
for t in TipoDocumento.objects.all()]
class MateriaAnexadaForm(ModelForm):
tipo = forms.ChoiceField(required=True,
tipo = forms.ModelChoiceField(
label='Tipo',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=True,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
)
numero = forms.CharField(label='Número', required=True)
@ -770,19 +753,14 @@ class DespachoInicialEditView(FormMixin, GenericView):
return reverse('despacho_inicial', kwargs={'pk': pk})
def get_tipos_norma():
return [('', 'Selecione')] \
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoNormaJuridica.objects.all()]
class LegislacaoCitadaForm(ModelForm):
tipo = forms.ChoiceField(required=True,
tipo = forms.ModelChoiceField(
label='Tipo Norma',
choices=get_tipos_norma(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=True,
queryset=TipoNormaJuridica.objects.all(),
empty_label='Selecione',
)
numero = forms.CharField(label='Número', required=True)
@ -996,11 +974,12 @@ class LegislacaoCitadaEditView(FormMixin, GenericView):
class NumeracaoForm(ModelForm):
tipo_materia = forms.ChoiceField(required=True,
label='Tipo Matéria',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
tipo_materia = forms.ModelChoiceField(
label='Tipo de Matéria',
required=True,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
)
data_materia = forms.DateField(label='Data',
required=False,
@ -1135,11 +1114,12 @@ class NumeracaoEditView(FormMixin, GenericView):
class DocumentoAcessorioForm(ModelForm):
tipo = forms.ChoiceField(required=True,
tipo = forms.ModelChoiceField(
label='Tipo',
choices=get_tipos_documento(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=True,
queryset=TipoDocumento.objects.all(),
empty_label='Selecione',
)
data = forms.DateField(label='Data',
required=False,
@ -1773,11 +1753,12 @@ class ProposicaoForm(ModelForm):
label='Descrição', required=True,
widget=forms.Textarea())
tipo_materia = forms.ChoiceField(required=False,
tipo_materia = forms.ModelChoiceField(
label='Matéria Vinculada',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
)
numero_materia = forms.CharField(
label='Número', required=False)
@ -1893,30 +1874,6 @@ class ProposicaoListView(ListView):
return context
def get_autores():
return [('', 'Selecione')] \
+ [(a.id, str(a)) for a in Autor.objects.all().order_by('tipo')]
def get_parlamentares():
return [('', 'Selecione')] \
+ [(p.id, str(p.nome_parlamentar,)
) for p in Parlamentar.objects.filter(
ativo=True).order_by('nome_parlamentar')]
def get_localizacao():
return [('', 'Selecione')] \
+ [(u.id, str(u)
) for u in UnidadeTramitacao.objects.all()]
def get_status():
return [('', 'Selecione')] \
+ [(s.id, str(s.descricao)
) for s in StatusTramitacao.objects.all()]
def em_tramitacao():
return [('', 'Tanto Faz'),
(True, 'Sim'),
@ -1924,23 +1881,28 @@ def em_tramitacao():
class MateriaLegislativaPesquisaForm(forms.Form):
autor = forms.ChoiceField(required=False,
autor = forms.ModelChoiceField(
label='Autor',
choices=get_autores(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=Autor.objects.all().order_by('tipo'),
empty_label='Selecione',
)
# relatores são os parlamentares ativos?
relator = forms.ChoiceField(required=False,
relator = forms.ModelChoiceField(
label='Relator',
choices=get_parlamentares(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=Parlamentar.objects.filter(
ativo=True).order_by('nome_parlamentar'),
empty_label='Selecione',
)
tipo = forms.ChoiceField(required=False,
label='Tipo da Matéria',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
tipo = forms.ModelChoiceField(
label='Tipo de Matéria',
required=False,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
)
data_apresentacao = forms.DateField(label=u'Data de Apresentação',
input_formats=['%d/%m/%Y'],
@ -1961,17 +1923,19 @@ class MateriaLegislativaPesquisaForm(forms.Form):
ano = forms.CharField(required=False, label=u'Ano da Matéria')
assunto = forms.CharField(required=False, label=u'Assunto')
localizacao = forms.ChoiceField(required=False,
localizacao = forms.ModelChoiceField(
label='Localização Atual',
choices=get_localizacao(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=UnidadeTramitacao.objects.all(),
empty_label='Selecione',
)
situacao = forms.ChoiceField(required=False,
situacao = forms.ModelChoiceField(
label='Situação',
choices=get_status(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=StatusTramitacao.objects.all(),
empty_label='Selecione',
)
tramitacao = forms.ChoiceField(required=False,
label='Tramitando',
@ -1981,7 +1945,7 @@ class MateriaLegislativaPesquisaForm(forms.Form):
# TODO: Verificar se esses campos estão corretos
# assunto? # -> usado 'ementa' em 'assunto'
# localizacao autal? #
# localizacao atual? #
# situacao? #
# tramitando? #

23
norma/views.py

@ -77,24 +77,12 @@ legislacao_citada_crud = build_crud(
])
def get_tipos_norma():
return [('', 'Selecione')] \
+ [(n.id, n.descricao)
for n in TipoNormaJuridica.objects.all()]
def get_esferas():
return [('E', 'Estadual'),
('F', 'Federal'),
('M', 'Municipal')]
def get_tipos_materia():
return [('', 'Selecione')] \
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoMateriaLegislativa.objects.all()]
class HorizontalRadioRenderer(forms.RadioSelect.renderer):
def render(self):
@ -103,11 +91,12 @@ class HorizontalRadioRenderer(forms.RadioSelect.renderer):
class NormaJuridicaForm(ModelForm):
tipo_materia = forms.ChoiceField(required=False,
label='Materia Legislativa',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
tipo_materia = forms.ModelChoiceField(
label='Matéria Legislativa',
required=False,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione'
)
numero_materia = forms.CharField(label='Número', required=False)

92
protocoloadm/views.py

@ -99,31 +99,11 @@ protocolo_materia_crud = build_crud(
[('observacao', 12)]],
])
# anular_protocolo_crud = build_crud(
# Protocolo, '', [
# [_('Indentificação do Protocolo'),
# [('numero', 6), ('ano', 6)],
# [('justificativa_anulacao', 12)]],
# ])
def get_tipos_materia():
return [('', 'Selecione')] \
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoMateriaLegislativa.objects.all()]
def get_range_anos():
return [('', 'Selecione')] \
+ [(year, year) for year in range(date.today().year, 1960, -1)]
def get_tipos_documento():
return [('', 'Selecione')] \
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoDocumentoAdministrativo.objects.all()]
TIPOS_PROTOCOLO = [('', 'Selecione'),
('0', 'Enviado'),
('1', 'Recebido')]
@ -135,11 +115,6 @@ class HorizontalRadioRenderer(forms.RadioSelect.renderer):
return mark_safe(u' '.join([u'%s ' % w for w in self]))
def get_autores():
return [('', 'Selecione')] \
+ [(a.id, str(a)) for a in Autor.objects.all().order_by('tipo')]
class ProtocoloForm(forms.Form):
YEARS = get_range_anos()
@ -177,24 +152,29 @@ class ProtocoloForm(forms.Form):
renderer=HorizontalRadioRenderer)
)
tipo_documento = forms.ChoiceField(required=False,
tipo_documento = forms.ModelChoiceField(
label='Tipo de Documento',
choices=get_tipos_documento(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=TipoDocumentoAdministrativo.objects.all(),
empty_label='Selecione',
)
interessado = forms.CharField(label='Interessado', required=False)
tipo_materia = forms.ChoiceField(required=False,
label='Tipo Matéria',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
autor = forms.ChoiceField(required=False,
tipo_materia = forms.ModelChoiceField(
label='Tipo de Matéria',
required=False,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
)
autor = forms.ModelChoiceField(
label='Autor',
choices=get_autores(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=Autor.objects.all().order_by('tipo'),
empty_label='Selecione',
)
assunto = forms.CharField(label='Assunto', required=False)
def __init__(self, *args, **kwargs):
@ -427,11 +407,14 @@ class ProtocoloDocumentForm(forms.Form):
choices=TIPOS_PROTOCOLO[1:],
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer))
tipo_documento = forms.ChoiceField(required=True,
tipo_documento = forms.ModelChoiceField(
label='Tipo de Documento',
choices=get_tipos_documento(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=TipoDocumentoAdministrativo.objects.all(),
empty_label='Selecione',
)
num_paginas = forms.CharField(label='Núm. Páginas', required=True)
assunto = forms.CharField(
widget=forms.Textarea, label='Assunto', required=True)
@ -529,19 +512,24 @@ class ProtocoloMateriaForm(forms.Form):
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer))
tipo_materia = forms.ChoiceField(required=False,
label='Tipo Matéria',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
tipo_materia = forms.ModelChoiceField(
label='Tipo de Matéria',
required=False,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
)
num_paginas = forms.CharField(label='Núm. Páginas', required=True)
ementa = forms.CharField(
widget=forms.Textarea, label='Ementa', required=True)
autor = forms.ChoiceField(required=False,
autor = forms.ModelChoiceField(
label='Autor',
choices=get_autores(),
widget=forms.Select(
attrs={'class': 'selector'}))
required=False,
queryset=Autor.objects.all().order_by('tipo'),
empty_label='Selecione',
)
observacao = forms.CharField(required=True,
widget=forms.Textarea,
label='Observação')
@ -717,8 +705,6 @@ class ProposicaoDetailView(DetailView):
context['form'] = ProposicaoSimpleForm
return context
# class PesquisaDocForm(forms.Form):
class PesquisarDocumentoAdministrativo(TemplateView):
template_name = "protocoloadm/pesquisa_doc_adm.html"

Loading…
Cancel
Save