Browse Source

Coloca as 'choices' do formulario no models

pull/250/head
Eduardo Calil 9 years ago
committed by Marcio Mazza
parent
commit
e067abb6e8
  1. 66
      base/forms.py
  2. 36
      base/models.py
  3. 2
      relatorios/views.py

66
base/forms.py

@ -9,68 +9,9 @@ from crispy_layout_mixin import form_actions
from .models import CasaLegislativa from .models import CasaLegislativa
ESTADOS = {"": "",
"AC": "ACRE",
"AL": "ALAGOAS",
"AM": "AMAZONAS",
"AP": "AMAPÁ",
"BA": "BAHIA",
"CE": "CEARÁ",
"DF": "DISTRITO FEDERAL",
"ES": "ESPíRITO SANTO",
"GO": "GOIÁS",
"MA": "MARANHÃO",
"MG": "MINAS GERAIS",
"MS": "MATO GROSSO DO SUL",
"MT": "MATO GROSSO",
"PA": "PARÁ",
"PB": "PARAÍBA",
"PE": "PERNAMBUCO",
"PI": "PIAUÍ",
"PR": "PARANÁ",
"RJ": "RIO DE JANEIRO",
"RN": "RIO GRANDE DO NORTE",
"RO": "RONDÔNIA",
"RR": "RORAIMA",
"RS": "RIO GRANDE DO SUL",
"SC": "SANTA CATARINA",
"SE": "SERGIPE",
"SP": "SÃO PAULO",
"TO": "TOCANTINS"}
class CasaLegislativaTabelaAuxForm(ModelForm): class CasaLegislativaTabelaAuxForm(ModelForm):
uf = forms.ChoiceField(required=True,
label='UF',
choices=[(uf, uf) for uf in ESTADOS.keys()],
widget=forms.Select(
attrs={'class': 'selector'}))
informacao_geral = forms.CharField(widget=forms.Textarea,
label=_('Informação Geral'),
required=False)
telefone = forms.CharField(label='Telefone',
required=False,
widget=forms.TextInput(
attrs={'class': 'telefone'}))
logotipo = forms.ImageField(label='Logotipo',
required=False,
widget=forms.FileInput
)
cep = forms.CharField(label='Cep',
required=True,
widget=forms.TextInput(
attrs={'class': 'cep'}))
fax = forms.CharField(label='Fax',
required=False,
widget=forms.TextInput(
attrs={'class': 'telefone'}))
class Meta: class Meta:
model = CasaLegislativa model = CasaLegislativa
@ -88,6 +29,13 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
'email', 'email',
'informacao_geral'] 'informacao_geral']
widgets = {
'uf': forms.Select(attrs={'class': 'selector'}),
'cep': forms.TextInput(attrs={'class': 'cep'}),
'telefone': forms.TextInput(attrs={'class': 'telefone'}),
'fax': forms.TextInput(attrs={'class': 'telefone'}),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
row1 = crispy_layout_mixin.to_row( row1 = crispy_layout_mixin.to_row(

36
base/models.py

@ -10,6 +10,36 @@ def get_casa_media_path(instance, filename):
return get_sessao_media_path(instance, 'Logotipo', filename) return get_sessao_media_path(instance, 'Logotipo', filename)
ESTADOS = {"": "",
"AC": "ACRE",
"AL": "ALAGOAS",
"AM": "AMAZONAS",
"AP": "AMAPÁ",
"BA": "BAHIA",
"CE": "CEARÁ",
"DF": "DISTRITO FEDERAL",
"ES": "ESPíRITO SANTO",
"GO": "GOIÁS",
"MA": "MARANHÃO",
"MG": "MINAS GERAIS",
"MS": "MATO GROSSO DO SUL",
"MT": "MATO GROSSO",
"PA": "PARÁ",
"PB": "PARAÍBA",
"PE": "PERNAMBUCO",
"PI": "PIAUÍ",
"PR": "PARANÁ",
"RJ": "RIO DE JANEIRO",
"RN": "RIO GRANDE DO NORTE",
"RO": "RONDÔNIA",
"RR": "RORAIMA",
"RS": "RIO GRANDE DO SUL",
"SC": "SANTA CATARINA",
"SE": "SERGIPE",
"SP": "SÃO PAULO",
"TO": "TOCANTINS"}
class CasaLegislativa(models.Model): class CasaLegislativa(models.Model):
# TODO ajustar todos os max_length !!!! # TODO ajustar todos os max_length !!!!
# cod_casa => id (pk) # cod_casa => id (pk)
@ -20,7 +50,9 @@ class CasaLegislativa(models.Model):
endereco = models.CharField(max_length=100, verbose_name=_('Endereço')) endereco = models.CharField(max_length=100, verbose_name=_('Endereço'))
cep = models.CharField(max_length=100, verbose_name=_('CEP')) cep = models.CharField(max_length=100, verbose_name=_('CEP'))
municipio = models.CharField(max_length=100, verbose_name=_('Município')) municipio = models.CharField(max_length=100, verbose_name=_('Município'))
uf = models.CharField(max_length=100, verbose_name=_('UF')) uf = models.CharField(max_length=100,
choices=[(uf, uf) for uf in ESTADOS.keys()],
verbose_name=_('UF'))
telefone = models.CharField( telefone = models.CharField(
max_length=100, blank=True, verbose_name=_('Telefone')) max_length=100, blank=True, verbose_name=_('Telefone'))
fax = models.CharField( fax = models.CharField(
@ -33,7 +65,7 @@ class CasaLegislativa(models.Model):
max_length=100, blank=True, verbose_name=_('HomePage')) max_length=100, blank=True, verbose_name=_('HomePage'))
email = models.EmailField( email = models.EmailField(
max_length=100, blank=True, verbose_name=_('E-mail')) max_length=100, blank=True, verbose_name=_('E-mail'))
informacao_geral = models.CharField( informacao_geral = models.TextField(
max_length=100, max_length=100,
blank=True, blank=True,
verbose_name=_('Informação Geral')) verbose_name=_('Informação Geral'))

2
relatorios/views.py

@ -4,7 +4,7 @@ from bs4 import BeautifulSoup
from django.http import HttpResponse from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from base.forms import ESTADOS from base.models import ESTADOS
from base.models import CasaLegislativa from base.models import CasaLegislativa
from comissoes.models import Comissao from comissoes.models import Comissao
from materia.models import (Autor, Autoria, MateriaLegislativa, Numeracao, from materia.models import (Autor, Autoria, MateriaLegislativa, Numeracao,

Loading…
Cancel
Save