Browse Source

Adiciona model ExpedientePautaSessao

pull/3286/head
João Rodrigues 4 years ago
parent
commit
4a6a2edb0a
  1. 53
      sapl/sessao/migrations/0054_popula_expedientepautasessao.py
  2. 24
      sapl/sessao/migrations/0055_expedientepautasessao.py
  3. 30
      sapl/sessao/models.py

53
sapl/sessao/migrations/0054_popula_expedientepautasessao.py

@ -0,0 +1,53 @@
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('sessao', '0053_auto_20200609_1501'),
]
operations = [
migrations.RunSQL(
"""
create or replace view sessao_expedientepauta as
with autoria_materia as (
select ma.materia_id, array_agg(ba.nome) as autores
from materia_autoria ma
join base_autor ba on (ma.autor_id = ba.id)
group by ma.materia_id
order by ma.materia_id, autores
),
tramitacao_numeracao_materia as (
select distinct on (m.id)
m.id as materia_id,
mt.id as tramitacao_id,
mn.id as numeracao_id
from materia_materialegislativa as m
left join materia_tramitacao mt on (m.id = mt.materia_id)
left join materia_numeracao mn on (m.id = mn.materia_id)
order by materia_id, mt.data_tramitacao DESC, mt.id DESC,
mn.id DESC
),
sessao_expedientepauta as (
select ex.id as id,
ex.id as expediente_id,
ex.sessao_plenaria_id as sessao_plenaria_id,
tnm.materia_id as materia_id,
tnm.tramitacao_id as tramitacao_id,
tnm.numeracao_id as numeracao_id,
am.autores as autores
from sessao_expedientemateria ex
join tramitacao_numeracao_materia tnm on (
ex.materia_id = tnm.materia_id
)
left join autoria_materia am on (
ex.materia_id = am.materia_id
)
)
select *
from sessao_expedientepauta
"""
)
]

24
sapl/sessao/migrations/0055_expedientepautasessao.py

@ -0,0 +1,24 @@
# Generated by Django 2.2.13 on 2020-09-24 23:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sessao', '0054_popula_expedientepautasessao'),
]
operations = [
migrations.CreateModel(
name='ExpedientePautaSessao',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('autores', models.CharField(blank=True, max_length=545)),
],
options={
'db_table': 'sessao_expedientepauta',
'managed': False,
},
),
]

30
sapl/sessao/models.py

@ -9,7 +9,7 @@ from model_utils import Choices
import reversion import reversion
from sapl.base.models import Autor from sapl.base.models import Autor
from sapl.materia.models import MateriaLegislativa from sapl.materia.models import MateriaLegislativa, Tramitacao, Numeracao
from sapl.parlamentares.models import (CargoMesa, Legislatura, Parlamentar, from sapl.parlamentares.models import (CargoMesa, Legislatura, Parlamentar,
Partido, SessaoLegislativa) Partido, SessaoLegislativa)
from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation, from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation,
@ -945,3 +945,31 @@ class RegistroLeitura(models.Model):
'RegistroLeitura deve ter exatamente um dos campos ' 'RegistroLeitura deve ter exatamente um dos campos '
'ordem ou expediente preenchido. Ambos estão preenchidos: ' 'ordem ou expediente preenchido. Ambos estão preenchidos: '
'{}, {}'. format(self.ordem, self.expediente)) '{}, {}'. format(self.ordem, self.expediente))
class ExpedientePautaSessao(models.Model):
expediente = models.ForeignKey(
ExpedienteMateria, on_delete=models.DO_NOTHING
)
sessao_plenaria = models.ForeignKey(
SessaoPlenaria, on_delete=models.DO_NOTHING
)
materia = models.ForeignKey(
MateriaLegislativa, on_delete=models.DO_NOTHING
)
tramitacao = models.ForeignKey(
Tramitacao, blank=True, null=True, on_delete=models.DO_NOTHING
)
numeracao = models.ForeignKey(
Numeracao, blank=True, null=True, on_delete=models.DO_NOTHING
)
autores = models.CharField(
max_length=545, blank=True
)
class Meta:
managed = False
db_table = "sessao_expedientepauta"
def __str__(self):
return '{}'.format(self.expediente)

Loading…
Cancel
Save