From b8d472ddbcce1ee9700b32a5c29983ab6075bf0b Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Mon, 8 Jun 2015 05:08:37 -0300 Subject: [PATCH] Rearrange models' order due to FKs --- comissoes/models.py | 36 ++++---- materia/models.py | 189 ++++++++++++++++++---------------------- norma/models.py | 28 ++++-- parlamentares/models.py | 52 +++++------ sessao/models.py | 71 ++++++++------- 5 files changed, 186 insertions(+), 190 deletions(-) diff --git a/comissoes/models.py b/comissoes/models.py index f892b0f50..41b886407 100644 --- a/comissoes/models.py +++ b/comissoes/models.py @@ -3,10 +3,12 @@ from django.db import models from parlamentares.models import Parlamentar -class CargoComissao(models.Model): - ### - nome = models.CharField(max_length=50) - ind_unico = models.IntegerField() +class TipoComissao(models.Model): + tip_comissao = models.AutoField(primary_key=True) + nom_tipo_comissao = models.CharField(max_length=50) + sgl_natureza_comissao = models.CharField(max_length=1) + sgl_tipo_comissao = models.CharField(max_length=10) + des_dispositivo_regimental = models.CharField(max_length=50, blank=True, null=True) class Comissao(models.Model): @@ -33,6 +35,18 @@ class Comissao(models.Model): ind_unid_deliberativa = models.IntegerField() +class PeriodoCompComissao(models.Model): + cod_periodo_comp = models.AutoField(primary_key=True) + dat_inicio_periodo = models.DateField() + dat_fim_periodo = models.DateField(blank=True, null=True) + + +class CargoComissao(models.Model): + ### + nome = models.CharField(max_length=50) + ind_unico = models.IntegerField() + + class ComposicaoComissao(models.Model): cod_comp_comissao = models.AutoField(primary_key=True) parlamentar = models.ForeignKey(Parlamentar) @@ -44,17 +58,3 @@ class ComposicaoComissao(models.Model): dat_desligamento = models.DateField(blank=True, null=True) des_motivo_desligamento = models.CharField(max_length=150, blank=True, null=True) obs_composicao = models.CharField(max_length=150, blank=True, null=True) - - -class PeriodoCompComissao(models.Model): - cod_periodo_comp = models.AutoField(primary_key=True) - dat_inicio_periodo = models.DateField() - dat_fim_periodo = models.DateField(blank=True, null=True) - - -class TipoComissao(models.Model): - tip_comissao = models.AutoField(primary_key=True) - nom_tipo_comissao = models.CharField(max_length=50) - sgl_natureza_comissao = models.CharField(max_length=1) - sgl_tipo_comissao = models.CharField(max_length=10) - des_dispositivo_regimental = models.CharField(max_length=50, blank=True, null=True) diff --git a/materia/models.py b/materia/models.py index f4466c057..8b0db11ee 100644 --- a/materia/models.py +++ b/materia/models.py @@ -1,9 +1,54 @@ from django.db import models from comissoes.models import Comissao -from norma.models import NormaJuridica -from parlamentares.models import Parlamentar -from parlamentares.models import Partido +from parlamentares.models import Parlamentar, Partido + + +class TipoMateriaLegislativa(models.Model): + tip_materia = models.AutoField(primary_key=True) + sgl_tipo_materia = models.CharField(max_length=5) + des_tipo_materia = models.CharField(max_length=50) + ind_num_automatica = models.IntegerField() + quorum_minimo_votacao = models.IntegerField() + + +class RegimeTramitacao(models.Model): + cod_regime_tramitacao = models.AutoField(primary_key=True) + des_regime_tramitacao = models.CharField(max_length=50) + + +class Origem(models.Model): + cod_origem = models.AutoField(primary_key=True) + sgl_origem = models.CharField(max_length=10) + nom_origem = models.CharField(max_length=50) + + +class MateriaLegislativa(models.Model): + cod_materia = models.AutoField(primary_key=True) + tip_id_basica = models.ForeignKey(TipoMateriaLegislativa) + num_protocolo = models.IntegerField(blank=True, null=True) + num_ident_basica = models.IntegerField() + ano_ident_basica = models.SmallIntegerField() + dat_apresentacao = models.DateField(blank=True, null=True) + tip_apresentacao = models.CharField(max_length=1, blank=True, null=True) + regime_tramitacao = models.ForeignKey(RegimeTramitacao) + dat_publicacao = models.DateField(blank=True, null=True) + tip_origem_externa = models.ForeignKey(TipoMateriaLegislativa, blank=True, null=True) + num_origem_externa = models.CharField(max_length=5, blank=True, null=True) + ano_origem_externa = models.SmallIntegerField(blank=True, null=True) + dat_origem_externa = models.DateField(blank=True, null=True) + local_origem_externa = models.ForeignKey(Origem, blank=True, null=True) + nom_apelido = models.CharField(max_length=50, blank=True, null=True) + num_dias_prazo = models.IntegerField(blank=True, null=True) + dat_fim_prazo = models.DateField(blank=True, null=True) + ind_tramitacao = models.IntegerField() + ind_polemica = models.IntegerField(blank=True, null=True) + des_objeto = models.CharField(max_length=150, blank=True, null=True) + ind_complementar = models.IntegerField(blank=True, null=True) + txt_ementa = models.TextField() + txt_indexacao = models.TextField(blank=True, null=True) + txt_observacao = models.TextField(blank=True, null=True) + txt_resultado = models.TextField(blank=True, null=True) class AcompMateria(models.Model): @@ -26,6 +71,11 @@ class AssuntoMateria(models.Model): des_dispositivo = models.CharField(max_length=50) +class TipoAutor(models.Model): + tip_autor = models.IntegerField(primary_key=True) + des_tipo_autor = models.CharField(max_length=50) + + class Autor(models.Model): cod_autor = models.AutoField(primary_key=True) partido = models.ForeignKey(Partido, blank=True, null=True) @@ -49,6 +99,11 @@ class DespachoInicial(models.Model): comissao = models.ForeignKey(Comissao) +class TipoDocumento(models.Model): + tip_documento = models.AutoField(primary_key=True) + des_tipo_documento = models.CharField(max_length=50) + + class DocumentoAcessorio(models.Model): cod_documento = models.AutoField(primary_key=True) materia = models.ForeignKey(MateriaLegislativa) @@ -60,57 +115,11 @@ class DocumentoAcessorio(models.Model): txt_indexacao = models.TextField(blank=True, null=True) -class LegislacaoCitada(models.Model): - materia = models.ForeignKey(MateriaLegislativa) - norma = models.ForeignKey(NormaJuridica) - des_disposicoes = models.CharField(max_length=15, blank=True, null=True) - des_parte = models.CharField(max_length=8, blank=True, null=True) - des_livro = models.CharField(max_length=7, blank=True, null=True) - des_titulo = models.CharField(max_length=7, blank=True, null=True) - des_capitulo = models.CharField(max_length=7, blank=True, null=True) - des_secao = models.CharField(max_length=7, blank=True, null=True) - des_subsecao = models.CharField(max_length=7, blank=True, null=True) - des_artigo = models.CharField(max_length=4, blank=True, null=True) - des_paragrafo = models.CharField(max_length=3, blank=True, null=True) - des_inciso = models.CharField(max_length=10, blank=True, null=True) - des_alinea = models.CharField(max_length=3, blank=True, null=True) - des_item = models.CharField(max_length=3, blank=True, null=True) - - class MateriaAssunto(models.Model): assunto = models.ForeignKey(AssuntoMateria) materia = models.ForeignKey(MateriaLegislativa) -class MateriaLegislativa(models.Model): - cod_materia = models.AutoField(primary_key=True) - tip_id_basica = models.ForeignKey(TipoMateriaLegislativa) - num_protocolo = models.IntegerField(blank=True, null=True) - num_ident_basica = models.IntegerField() - ano_ident_basica = models.SmallIntegerField() - dat_apresentacao = models.DateField(blank=True, null=True) - tip_apresentacao = models.CharField(max_length=1, blank=True, null=True) - regime_tramitacao = models.ForeignKey(RegimeTramitacao) - dat_publicacao = models.DateField(blank=True, null=True) - tip_origem_externa = models.ForeignKey(TipoMateriaLegislativa, blank=True, null=True) - num_origem_externa = models.CharField(max_length=5, blank=True, null=True) - ano_origem_externa = models.SmallIntegerField(blank=True, null=True) - dat_origem_externa = models.DateField(blank=True, null=True) - local_origem_externa = models.ForeignKey(Origem, blank=True, null=True) - nom_apelido = models.CharField(max_length=50, blank=True, null=True) - num_dias_prazo = models.IntegerField(blank=True, null=True) - dat_fim_prazo = models.DateField(blank=True, null=True) - ind_tramitacao = models.IntegerField() - ind_polemica = models.IntegerField(blank=True, null=True) - des_objeto = models.CharField(max_length=150, blank=True, null=True) - ind_complementar = models.IntegerField(blank=True, null=True) - txt_ementa = models.TextField() - txt_indexacao = models.TextField(blank=True, null=True) - txt_observacao = models.TextField(blank=True, null=True) - - txt_resultado = models.TextField(blank=True, null=True) - - class Numeracao(models.Model): materia = models.ForeignKey(MateriaLegislativa) num_ordem = models.IntegerField() @@ -129,10 +138,19 @@ class Orgao(models.Model): num_tel_orgao = models.CharField(max_length=50, blank=True, null=True) -class Origem(models.Model): - cod_origem = models.AutoField(primary_key=True) - sgl_origem = models.CharField(max_length=10) - nom_origem = models.CharField(max_length=50) +class TipoFimRelatoria(models.Model): + tip_fim_relatoria = models.AutoField(primary_key=True) + des_fim_relatoria = models.CharField(max_length=50) + + +class Relatoria(models.Model): + cod_relatoria = models.AutoField(primary_key=True) + materia = models.ForeignKey(MateriaLegislativa) + parlamentar = models.ForeignKey(Parlamentar) + tip_fim_relatoria = models.ForeignKey(TipoFimRelatoria, blank=True, null=True) + comissao = models.ForeignKey(Comissao, blank=True, null=True) + dat_desig_relator = models.DateField() + dat_destit_relator = models.DateField(blank=True, null=True) class Parecer(models.Model): @@ -143,6 +161,14 @@ class Parecer(models.Model): txt_parecer = models.TextField(blank=True, null=True) +class TipoProposicao(models.Model): + tip_proposicao = models.AutoField(primary_key=True) + des_tipo_proposicao = models.CharField(max_length=50) + ind_mat_ou_doc = models.CharField(max_length=1) + tip_mat_ou_doc = models.IntegerField() + nom_modelo = models.CharField(max_length=50) + + class Proposicao(models.Model): cod_proposicao = models.AutoField(primary_key=True) materia = models.ForeignKey(MateriaLegislativa, blank=True, null=True) @@ -157,21 +183,6 @@ class Proposicao(models.Model): num_proposicao = models.IntegerField(blank=True, null=True) -class RegimeTramitacao(models.Model): - cod_regime_tramitacao = models.AutoField(primary_key=True) - des_regime_tramitacao = models.CharField(max_length=50) - - -class Relatoria(models.Model): - cod_relatoria = models.AutoField(primary_key=True) - materia = models.ForeignKey(MateriaLegislativa) - parlamentar = models.ForeignKey(Parlamentar) - tip_fim_relatoria = models.ForeignKey(TipoFimRelatoria, blank=True, null=True) - comissao = models.ForeignKey(Comissao, blank=True, null=True) - dat_desig_relator = models.DateField() - dat_destit_relator = models.DateField(blank=True, null=True) - - class StatusTramitacao(models.Model): cod_status = models.AutoField(primary_key=True) sgl_status = models.CharField(max_length=10) @@ -180,35 +191,11 @@ class StatusTramitacao(models.Model): ind_retorno_tramitacao = models.IntegerField() -class TipoAutor(models.Model): - tip_autor = models.IntegerField(primary_key=True) - des_tipo_autor = models.CharField(max_length=50) - - -class TipoDocumento(models.Model): - tip_documento = models.AutoField(primary_key=True) - des_tipo_documento = models.CharField(max_length=50) - - -class TipoFimRelatoria(models.Model): - tip_fim_relatoria = models.AutoField(primary_key=True) - des_fim_relatoria = models.CharField(max_length=50) - - -class TipoMateriaLegislativa(models.Model): - tip_materia = models.AutoField(primary_key=True) - sgl_tipo_materia = models.CharField(max_length=5) - des_tipo_materia = models.CharField(max_length=50) - ind_num_automatica = models.IntegerField() - quorum_minimo_votacao = models.IntegerField() - - -class TipoProposicao(models.Model): - tip_proposicao = models.AutoField(primary_key=True) - des_tipo_proposicao = models.CharField(max_length=50) - ind_mat_ou_doc = models.CharField(max_length=1) - tip_mat_ou_doc = models.IntegerField() - nom_modelo = models.CharField(max_length=50) +class UnidadeTramitacao(models.Model): + cod_unid_tramitacao = models.AutoField(primary_key=True) + comissao = models.ForeignKey(Comissao, blank=True, null=True) + orgao = models.ForeignKey(Orgao, blank=True, null=True) + parlamentar = models.ForeignKey(Parlamentar, blank=True, null=True) class Tramitacao(models.Model): @@ -224,11 +211,3 @@ class Tramitacao(models.Model): sgl_turno = models.CharField(max_length=1, blank=True, null=True) txt_tramitacao = models.TextField(blank=True, null=True) dat_fim_prazo = models.DateField(blank=True, null=True) - - -class UnidadeTramitacao(models.Model): - cod_unid_tramitacao = models.AutoField(primary_key=True) - comissao = models.ForeignKey(Comissao, blank=True, null=True) - orgao = models.ForeignKey(Orgao, blank=True, null=True) - parlamentar = models.ForeignKey(Parlamentar, blank=True, null=True) - diff --git a/norma/models.py b/norma/models.py index 038d55f11..3315215fa 100644 --- a/norma/models.py +++ b/norma/models.py @@ -9,6 +9,13 @@ class AssuntoNorma(models.Model): des_estendida = models.CharField(max_length=250, blank=True, null=True) +class TipoNormaJuridica(models.Model): + tip_norma = models.AutoField(primary_key=True) + voc_lexml = models.CharField(max_length=50, blank=True, null=True) + sgl_tipo_norma = models.CharField(max_length=3) + des_tipo_norma = models.CharField(max_length=50) + + class NormaJuridica(models.Model): cod_norma = models.AutoField(primary_key=True) tip_norma = models.ForeignKey(TipoNormaJuridica) @@ -30,11 +37,22 @@ class NormaJuridica(models.Model): timestamp = models.DateTimeField() -class TipoNormaJuridica(models.Model): - tip_norma = models.AutoField(primary_key=True) - voc_lexml = models.CharField(max_length=50, blank=True, null=True) - sgl_tipo_norma = models.CharField(max_length=3) - des_tipo_norma = models.CharField(max_length=50) +# XXX maybe should be in materia app, but would cause a circular import +class LegislacaoCitada(models.Model): + materia = models.ForeignKey(MateriaLegislativa) + norma = models.ForeignKey(NormaJuridica) + des_disposicoes = models.CharField(max_length=15, blank=True, null=True) + des_parte = models.CharField(max_length=8, blank=True, null=True) + des_livro = models.CharField(max_length=7, blank=True, null=True) + des_titulo = models.CharField(max_length=7, blank=True, null=True) + des_capitulo = models.CharField(max_length=7, blank=True, null=True) + des_secao = models.CharField(max_length=7, blank=True, null=True) + des_subsecao = models.CharField(max_length=7, blank=True, null=True) + des_artigo = models.CharField(max_length=4, blank=True, null=True) + des_paragrafo = models.CharField(max_length=3, blank=True, null=True) + des_inciso = models.CharField(max_length=10, blank=True, null=True) + des_alinea = models.CharField(max_length=3, blank=True, null=True) + des_item = models.CharField(max_length=3, blank=True, null=True) class VinculoNormaJuridica(models.Model): diff --git a/parlamentares/models.py b/parlamentares/models.py index f2d7f0bc6..3da9889d0 100644 --- a/parlamentares/models.py +++ b/parlamentares/models.py @@ -24,6 +24,14 @@ class Coligacao(models.Model): num_votos_coligacao = models.IntegerField(blank=True, null=True) +class Partido(models.Model): + cod_partido = models.AutoField(primary_key=True) + sgl_partido = models.CharField(max_length=9) + nom_partido = models.CharField(max_length=50) + dat_criacao = models.DateField(blank=True, null=True) + dat_extincao = models.DateField(blank=True, null=True) + + class ComposicaoColigacao(models.Model): partido = models.ForeignKey(Partido) coligacao = models.ForeignKey(Coligacao) @@ -42,6 +50,11 @@ class NivelInstrucao(models.Model): nivel_instrucao = models.CharField(max_length=50) +class TipoSituacaoMilitar(models.Model): + tip_situacao_militar = models.IntegerField(primary_key=True) + des_tipo_situacao = models.CharField(max_length=50) + + class Parlamentar(models.Model): ### nivel_instrucao = models.ForeignKey(NivelInstrucao, blank=True, null=True) @@ -71,6 +84,11 @@ class Parlamentar(models.Model): ind_unid_deliberativa = models.IntegerField() +class TipoDependente(models.Model): + tip_dependente = models.AutoField(primary_key=True) + des_tipo_dependente = models.CharField(max_length=50) + + class Dependente(models.Model): cod_dependente = models.AutoField(primary_key=True) tip_dependente = models.ForeignKey(TipoDependente) @@ -90,6 +108,14 @@ class Filiacao(models.Model): dat_desfiliacao = models.DateField(blank=True, null=True) +class TipoAfastamento(models.Model): + tip_afastamento = models.AutoField(primary_key=True) + des_afastamento = models.CharField(max_length=50) + ind_afastamento = models.IntegerField() + ind_fim_mandato = models.IntegerField() + des_dispositivo = models.CharField(max_length=50, blank=True, null=True) + + class Mandato(models.Model): cod_mandato = models.AutoField(primary_key=True) parlamentar = models.ForeignKey(Parlamentar) @@ -103,32 +129,6 @@ class Mandato(models.Model): txt_observacao = models.TextField(blank=True, null=True) -class Partido(models.Model): - cod_partido = models.AutoField(primary_key=True) - sgl_partido = models.CharField(max_length=9) - nom_partido = models.CharField(max_length=50) - dat_criacao = models.DateField(blank=True, null=True) - dat_extincao = models.DateField(blank=True, null=True) - - -class TipoAfastamento(models.Model): - tip_afastamento = models.AutoField(primary_key=True) - des_afastamento = models.CharField(max_length=50) - ind_afastamento = models.IntegerField() - ind_fim_mandato = models.IntegerField() - des_dispositivo = models.CharField(max_length=50, blank=True, null=True) - - -class TipoDependente(models.Model): - tip_dependente = models.AutoField(primary_key=True) - des_tipo_dependente = models.CharField(max_length=50) - - -class TipoSituacaoMilitar(models.Model): - tip_situacao_militar = models.IntegerField(primary_key=True) - des_tipo_situacao = models.CharField(max_length=50) - - class CargoMesa(models.Model): nome = models.CharField(max_length=50) unico = models.BooleanField() diff --git a/sessao/models.py b/sessao/models.py index 99eef6bbc..9cf94ab2a 100644 --- a/sessao/models.py +++ b/sessao/models.py @@ -1,9 +1,7 @@ from django.db import models from materia.models import MateriaLegislativa -from parlamentares.models import CargoMesa -from parlamentares.models import Parlamentar -from parlamentares.models import SessaoLegislativa +from parlamentares.models import CargoMesa, Parlamentar, SessaoLegislativa, Legislatura class ExpedienteMateria(models.Model): @@ -17,6 +15,35 @@ class ExpedienteMateria(models.Model): tip_votacao = models.IntegerField() +class TipoSessaoPlenaria(models.Model): + tip_sessao = models.AutoField(primary_key=True) + nom_sessao = models.CharField(max_length=30) + num_minimo = models.IntegerField() + + +class SessaoPlenaria(models.Model): + cod_sessao_plen = models.AutoField(primary_key=True) + cod_andamento_sessao = models.IntegerField(blank=True, null=True) # TODO lixo??? parece que era FK + # andamento_sessao = models.ForeignKey(AndamentoSessao, blank=True, null=True) + tip_sessao = models.ForeignKey(TipoSessaoPlenaria) + sessao_leg = models.ForeignKey(SessaoLegislativa) + legislatura = models.ForeignKey(Legislatura) + tip_expediente = models.CharField(max_length=10) + dat_inicio_sessao = models.DateField() + dia_sessao = models.CharField(max_length=15) + hr_inicio_sessao = models.CharField(max_length=5) + hr_fim_sessao = models.CharField(max_length=5, blank=True, null=True) + num_sessao_plen = models.IntegerField() + dat_fim_sessao = models.DateField(blank=True, null=True) + url_audio = models.CharField(max_length=150, blank=True, null=True) + url_video = models.CharField(max_length=150, blank=True, null=True) + + +class TipoExpediente(models.Model): + cod_expediente = models.AutoField(primary_key=True) + nom_expediente = models.CharField(max_length=100) + + class ExpedienteSessaoPlenaria(models.Model): sessao_plen = models.ForeignKey(SessaoPlenaria) expediente = models.ForeignKey(TipoExpediente) @@ -63,6 +90,11 @@ class OrdemDiaPresenca(models.Model): dat_ordem = models.DateField() +class TipoResultadoVotacao(models.Model): + tip_resultado_votacao = models.AutoField(primary_key=True) + nom_resultado = models.CharField(max_length=100) + + class RegistroVotacao(models.Model): cod_votacao = models.AutoField(primary_key=True) tip_resultado_votacao = models.ForeignKey(TipoResultadoVotacao) @@ -80,41 +112,8 @@ class RegistroVotacaoParlamentar(models.Model): vot_parlamentar = models.CharField(max_length=10) -class SessaoPlenaria(models.Model): - cod_sessao_plen = models.AutoField(primary_key=True) - andamento_sessao = models.ForeignKey(AndamentoSessao, blank=True, null=True) - tip_sessao = models.ForeignKey(TipoSessaoPlenaria) - sessao_leg = models.ForeignKey(SessaoLegislativa) - legislatura = models.ForeignKey(Legislatura) - tip_expediente = models.CharField(max_length=10) - dat_inicio_sessao = models.DateField() - dia_sessao = models.CharField(max_length=15) - hr_inicio_sessao = models.CharField(max_length=5) - hr_fim_sessao = models.CharField(max_length=5, blank=True, null=True) - num_sessao_plen = models.IntegerField() - dat_fim_sessao = models.DateField(blank=True, null=True) - url_audio = models.CharField(max_length=150, blank=True, null=True) - url_video = models.CharField(max_length=150, blank=True, null=True) - - class SessaoPlenariaPresenca(models.Model): cod_presenca_sessao = models.AutoField(primary_key=True) sessao_plen = models.ForeignKey(SessaoPlenaria) parlamentar = models.ForeignKey(Parlamentar) dat_sessao = models.DateField(blank=True, null=True) - - -class TipoExpediente(models.Model): - cod_expediente = models.AutoField(primary_key=True) - nom_expediente = models.CharField(max_length=100) - - -class TipoResultadoVotacao(models.Model): - tip_resultado_votacao = models.AutoField(primary_key=True) - nom_resultado = models.CharField(max_length=100) - - -class TipoSessaoPlenaria(models.Model): - tip_sessao = models.AutoField(primary_key=True) - nom_sessao = models.CharField(max_length=30) - num_minimo = models.IntegerField()