Browse Source

Migra dados de reunião de comissão (do sapl 3.0)

pull/2023/head
Marcio Mazza 7 years ago
parent
commit
6a3f2c77a4
  1. 7
      sapl/comissoes/legacy.yaml
  2. 25
      sapl/comissoes/migrations/0015_auto_20180613_2023.py
  3. 21
      sapl/comissoes/migrations/0016_auto_20180613_2121.py
  4. 11
      sapl/comissoes/models.py
  5. 34
      sapl/comissoes/views.py
  6. 22
      sapl/legacy/migracao_dados.py
  7. 14
      sapl/legacy/models.py

7
sapl/comissoes/legacy.yaml

@ -42,3 +42,10 @@ Participacao (ComposicaoComissao):
observacao: obs_composicao observacao: obs_composicao
parlamentar: cod_parlamentar parlamentar: cod_parlamentar
titular: ind_titular titular: ind_titular
Reuniao (ReuniaoComissao):
comissao: cod_comissao
numero: num_reuniao
data: dat_inicio_reuniao
observacao: txt_observacao

25
sapl/comissoes/migrations/0015_auto_20180613_2023.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2018-06-13 23:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('comissoes', '0014_auto_20180503_1055'),
]
operations = [
migrations.AlterField(
model_name='reuniao',
name='hora_fim',
field=models.TimeField(null=True, verbose_name='Horário de Término (hh:mm)'),
),
migrations.AlterField(
model_name='reuniao',
name='hora_inicio',
field=models.TimeField(null=True, verbose_name='Horário de Início (hh:mm)'),
),
]

21
sapl/comissoes/migrations/0016_auto_20180613_2121.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2018-06-14 00:21
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('comissoes', '0015_auto_20180613_2023'),
]
operations = [
migrations.AlterField(
model_name='reuniao',
name='periodo',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='comissoes.Periodo', verbose_name='Periodo da Composicão da Comissão'),
),
]

11
sapl/comissoes/models.py

@ -184,13 +184,16 @@ class Participacao(models.Model): # ComposicaoComissao
def get_comissao_media_path(instance, subpath, filename): def get_comissao_media_path(instance, subpath, filename):
return './sapl/comissao/%s/%s/%s' % (instance.numero, subpath, filename) return './sapl/comissao/%s/%s/%s' % (instance.numero, subpath, filename)
def pauta_upload_path(instance, filename): def pauta_upload_path(instance, filename):
return texto_upload_path(instance, filename, subpath='pauta', pk_first=True) return texto_upload_path(instance, filename, subpath='pauta', pk_first=True)
def ata_upload_path(instance, filename): def ata_upload_path(instance, filename):
return texto_upload_path(instance, filename, subpath='ata', pk_first=True) return texto_upload_path(instance, filename, subpath='ata', pk_first=True)
def anexo_upload_path(instance, filename): def anexo_upload_path(instance, filename):
return texto_upload_path(instance, filename, subpath='anexo', pk_first=True) return texto_upload_path(instance, filename, subpath='anexo', pk_first=True)
@ -198,6 +201,7 @@ def anexo_upload_path(instance, filename):
class Reuniao(models.Model): class Reuniao(models.Model):
periodo = models. ForeignKey( periodo = models. ForeignKey(
Periodo, Periodo,
null=True,
on_delete=models.PROTECT, on_delete=models.PROTECT,
verbose_name=_('Periodo da Composicão da Comissão')) verbose_name=_('Periodo da Composicão da Comissão'))
comissao = models.ForeignKey( comissao = models.ForeignKey(
@ -211,8 +215,10 @@ class Reuniao(models.Model):
max_length=150, blank=True, verbose_name=_('Tema da Reunião')) max_length=150, blank=True, verbose_name=_('Tema da Reunião'))
data = models.DateField(verbose_name=_('Data')) data = models.DateField(verbose_name=_('Data'))
hora_inicio = models.TimeField( hora_inicio = models.TimeField(
null=True,
verbose_name=_('Horário de Início (hh:mm)')) verbose_name=_('Horário de Início (hh:mm)'))
hora_fim = models.TimeField( hora_fim = models.TimeField(
null=True,
verbose_name=_('Horário de Término (hh:mm)')) verbose_name=_('Horário de Término (hh:mm)'))
local_reuniao = models.CharField( local_reuniao = models.CharField(
max_length=100, blank=True, verbose_name=_('Local da Reunião')) max_length=100, blank=True, verbose_name=_('Local da Reunião'))
@ -287,12 +293,13 @@ class Reuniao(models.Model):
@reversion.register() @reversion.register()
class DocumentoAcessorio(models.Model): class DocumentoAcessorio(models.Model):
reuniao = models.ForeignKey(Reuniao, reuniao = models.ForeignKey(Reuniao,
related_name='documentoacessorio_set', related_name='documentoacessorio_set',
on_delete=models.PROTECT) on_delete=models.PROTECT)
nome = models.CharField(max_length=50, verbose_name=_('Nome')) nome = models.CharField(max_length=50, verbose_name=_('Nome'))
data = models.DateField(blank=True, null=True, default=None, verbose_name=_('Data')) data = models.DateField(blank=True, null=True,
default=None, verbose_name=_('Data'))
autor = models.CharField( autor = models.CharField(
max_length=100, verbose_name=_('Autor')) max_length=100, verbose_name=_('Autor'))
ementa = models.TextField(blank=True, verbose_name=_('Ementa')) ementa = models.TextField(blank=True, verbose_name=_('Ementa'))

34
sapl/comissoes/views.py

@ -8,20 +8,20 @@ from django.views.generic.base import RedirectView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from sapl.base.models import AppConfig as AppsAppConfig from sapl.base.models import AppConfig as AppsAppConfig
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, from sapl.comissoes.apps import AppConfig
CrudAux, MasterDetailCrud, from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm,
PermissionRequiredForAppCrudMixin) DocumentoAcessorioCreateForm,
from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm, DocumentoAcessorioCreateForm, DocumentoAcessorioEditForm,
DocumentoAcessorioEditForm, ParticipacaoCreateForm, ParticipacaoCreateForm, ParticipacaoEditForm,
ParticipacaoEditForm, ReuniaoForm, PeriodoForm) PeriodoForm, ReuniaoForm)
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
MasterDetailCrud,
PermissionRequiredForAppCrudMixin)
from sapl.materia.models import MateriaLegislativa, Tramitacao from sapl.materia.models import MateriaLegislativa, Tramitacao
from .models import (CargoComissao, Comissao, Composicao, DocumentoAcessorio, from .models import (CargoComissao, Comissao, Composicao, DocumentoAcessorio,
Participacao, Periodo, TipoComissao, Reuniao) Participacao, Periodo, Reuniao, TipoComissao)
from sapl.comissoes.apps import AppConfig
def pegar_url_composicao(pk): def pegar_url_composicao(pk):
@ -30,6 +30,7 @@ def pegar_url_composicao(pk):
url = reverse('sapl.comissoes:composicao_detail', kwargs={'pk': comp_pk}) url = reverse('sapl.comissoes:composicao_detail', kwargs={'pk': comp_pk})
return url return url
def pegar_url_reuniao(pk): def pegar_url_reuniao(pk):
documentoacessorio = DocumentoAcessorio.objects.get(id=pk) documentoacessorio = DocumentoAcessorio.objects.get(id=pk)
r_pk = documentoacessorio.reuniao.pk r_pk = documentoacessorio.reuniao.pk
@ -42,6 +43,7 @@ TipoComissaoCrud = CrudAux.build(
TipoComissao, 'tipo_comissao', list_field_names=[ TipoComissao, 'tipo_comissao', list_field_names=[
'sigla', 'nome', 'natureza', 'dispositivo_regimental']) 'sigla', 'nome', 'natureza', 'dispositivo_regimental'])
class PeriodoComposicaoCrud(CrudAux): class PeriodoComposicaoCrud(CrudAux):
model = Periodo model = Periodo
@ -77,6 +79,7 @@ class ParticipacaoCrud(MasterDetailCrud):
form_class = ParticipacaoEditForm form_class = ParticipacaoEditForm
class DeleteView(MasterDetailCrud.DeleteView): class DeleteView(MasterDetailCrud.DeleteView):
def get_success_url(self): def get_success_url(self):
composicao_comissao_pk = self.object.composicao.comissao.pk composicao_comissao_pk = self.object.composicao.comissao.pk
composicao_pk = self.object.composicao.pk composicao_pk = self.object.composicao.pk
@ -93,12 +96,11 @@ class ComposicaoCrud(MasterDetailCrud):
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = ComposicaoForm form_class = ComposicaoForm
def get_initial(self): def get_initial(self):
comissao = Comissao.objects.get(id=self.kwargs['pk']) comissao = Comissao.objects.get(id=self.kwargs['pk'])
return {'comissao': comissao} return {'comissao': comissao}
class ListView(MasterDetailCrud.ListView): class ListView(MasterDetailCrud.ListView):
template_name = "comissoes/composicao_list.html" template_name = "comissoes/composicao_list.html"
paginate_by = None paginate_by = None
@ -180,6 +182,7 @@ class MateriasTramitacaoListView(ListView):
context['object'] = Comissao.objects.get(id=self.kwargs['pk']) context['object'] = Comissao.objects.get(id=self.kwargs['pk'])
return context return context
class ReuniaoCrud(MasterDetailCrud): class ReuniaoCrud(MasterDetailCrud):
model = Reuniao model = Reuniao
parent_field = 'comissao' parent_field = 'comissao'
@ -187,7 +190,7 @@ class ReuniaoCrud(MasterDetailCrud):
public = [RP_LIST, RP_DETAIL, ] public = [RP_LIST, RP_DETAIL, ]
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = [ 'nome', 'tema', 'data'] list_field_names = ['data', 'nome', 'tema']
class ListView(MasterDetailCrud.ListView): class ListView(MasterDetailCrud.ListView):
paginate_by = 10 paginate_by = 10
@ -228,9 +231,9 @@ class ReuniaoCrud(MasterDetailCrud):
form_class = ReuniaoForm form_class = ReuniaoForm
def get_initial(self): def get_initial(self):
comissao = Comissao.objects.get(id=self.kwargs['pk']) comissao = Comissao.objects.get(id=self.kwargs['pk'])
return {'comissao': comissao} return {'comissao': comissao}
class DocumentoAcessorioCrud(MasterDetailCrud): class DocumentoAcessorioCrud(MasterDetailCrud):
@ -256,6 +259,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
form_class = DocumentoAcessorioEditForm form_class = DocumentoAcessorioEditForm
class DeleteView(MasterDetailCrud.DeleteView): class DeleteView(MasterDetailCrud.DeleteView):
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):
obj = self.get_object() obj = self.get_object()
obj.delete() obj.delete()

22
sapl/legacy/migracao_dados.py

@ -29,7 +29,7 @@ from unipath import Path
from sapl.base.models import AppConfig as AppConf from sapl.base.models import AppConfig as AppConf
from sapl.base.models import Autor, TipoAutor, cria_models_tipo_autor from sapl.base.models import Autor, TipoAutor, cria_models_tipo_autor
from sapl.comissoes.models import Comissao, Composicao, Participacao from sapl.comissoes.models import Comissao, Composicao, Participacao, Reuniao
from sapl.legacy import scripts from sapl.legacy import scripts
from sapl.legacy.models import NormaJuridica as OldNormaJuridica from sapl.legacy.models import NormaJuridica as OldNormaJuridica
from sapl.legacy.models import TipoNumeracaoProtocolo from sapl.legacy.models import TipoNumeracaoProtocolo
@ -58,6 +58,8 @@ from .timezonesbrasil import get_timezone
appconfs = [apps.get_app_config(n) for n in [ appconfs = [apps.get_app_config(n) for n in [
'parlamentares', 'parlamentares',
'comissoes', 'comissoes',
# base precisa vir depois dos apps parlamentares e comissoes
# pois Autor os referencia
'base', 'base',
'materia', 'materia',
'norma', 'norma',
@ -99,7 +101,7 @@ def get_renames():
model_name, old_name = match.groups() model_name, old_name = match.groups()
else: else:
old_name = None old_name = None
model = getattr(app.models_module, model_name) model = app.get_model(model_name)
if old_name: if old_name:
model_renames[model] = old_name model_renames[model] = old_name
field_renames[model] = renames field_renames[model] = renames
@ -212,6 +214,10 @@ class ForeignKeyFaltando(ObjectDoesNotExist):
'Uma FK aponta para um registro inexistente' 'Uma FK aponta para um registro inexistente'
def __init__(self, field, valor, old): def __init__(self, field, valor, old):
if (field.related_model.__name__ == 'Comissao'
and old.__class__.__name__ == 'ReuniaoComissao'
and valor == 1):
__import__('pdb').set_trace()
self.field = field self.field = field
self.valor = valor self.valor = valor
self.old = old self.old = old
@ -1237,6 +1243,17 @@ def adjust_tiporesultadovotacao(new, old):
{'pk': new.pk, 'nome': new.nome}) {'pk': new.pk, 'nome': new.nome})
def str_to_time(fonte):
if not fonte.strip():
return None
tempo = datetime.datetime.strptime(fonte, '%H:%M')
return tempo.time() if tempo else None
def adjust_reuniao_comissao(new, old):
new.hora_inicio = str_to_time(old.hr_inicio_reuniao)
def remove_style(conteudo): def remove_style(conteudo):
if 'style' not in conteudo: if 'style' not in conteudo:
return conteudo # atalho que acelera muito os casos sem style return conteudo # atalho que acelera muito os casos sem style
@ -1274,6 +1291,7 @@ AJUSTE_ANTES_SALVAR = {
Tramitacao: adjust_tramitacao, Tramitacao: adjust_tramitacao,
TipoResultadoVotacao: adjust_tiporesultadovotacao, TipoResultadoVotacao: adjust_tiporesultadovotacao,
ExpedienteSessao: adjust_expediente_sessao, ExpedienteSessao: adjust_expediente_sessao,
Reuniao: adjust_reuniao_comissao,
} }
AJUSTE_DEPOIS_SALVAR = { AJUSTE_DEPOIS_SALVAR = {

14
sapl/legacy/models.py

@ -779,6 +779,20 @@ class Relatoria(models.Model):
db_table = 'relatoria' db_table = 'relatoria'
class ReuniaoComissao(models.Model):
cod_reuniao = models.AutoField(primary_key=True)
cod_comissao = models.IntegerField()
num_reuniao = models.IntegerField()
dat_inicio_reuniao = models.DateField()
hr_inicio_reuniao = models.CharField(max_length=5, blank=True, null=True)
txt_observacao = models.TextField(blank=True, null=True)
ind_excluido = models.IntegerField()
class Meta:
managed = False
db_table = 'reuniao_comissao'
class SessaoLegislativa(models.Model): class SessaoLegislativa(models.Model):
cod_sessao_leg = models.AutoField(primary_key=True) cod_sessao_leg = models.AutoField(primary_key=True)
num_legislatura = models.IntegerField() num_legislatura = models.IntegerField()

Loading…
Cancel
Save