diff --git a/sapl/comissoes/legacy.yaml b/sapl/comissoes/legacy.yaml index 66ed8b060..8e1040510 100644 --- a/sapl/comissoes/legacy.yaml +++ b/sapl/comissoes/legacy.yaml @@ -42,3 +42,10 @@ Participacao (ComposicaoComissao): observacao: obs_composicao parlamentar: cod_parlamentar titular: ind_titular + +Reuniao (ReuniaoComissao): + comissao: cod_comissao + numero: num_reuniao + data: dat_inicio_reuniao + observacao: txt_observacao + diff --git a/sapl/comissoes/migrations/0015_auto_20180613_2023.py b/sapl/comissoes/migrations/0015_auto_20180613_2023.py new file mode 100644 index 000000000..b6602cfc3 --- /dev/null +++ b/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)'), + ), + ] diff --git a/sapl/comissoes/migrations/0016_auto_20180613_2121.py b/sapl/comissoes/migrations/0016_auto_20180613_2121.py new file mode 100644 index 000000000..77c1894f8 --- /dev/null +++ b/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'), + ), + ] diff --git a/sapl/comissoes/models.py b/sapl/comissoes/models.py index 0c3240fc6..a2477ef1d 100644 --- a/sapl/comissoes/models.py +++ b/sapl/comissoes/models.py @@ -184,13 +184,16 @@ class Participacao(models.Model): # ComposicaoComissao def get_comissao_media_path(instance, subpath, filename): return './sapl/comissao/%s/%s/%s' % (instance.numero, subpath, filename) + def pauta_upload_path(instance, filename): return texto_upload_path(instance, filename, subpath='pauta', pk_first=True) + def ata_upload_path(instance, filename): return texto_upload_path(instance, filename, subpath='ata', pk_first=True) + def anexo_upload_path(instance, filename): 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): periodo = models. ForeignKey( Periodo, + null=True, on_delete=models.PROTECT, verbose_name=_('Periodo da Composicão da Comissão')) comissao = models.ForeignKey( @@ -211,8 +215,10 @@ class Reuniao(models.Model): max_length=150, blank=True, verbose_name=_('Tema da Reunião')) data = models.DateField(verbose_name=_('Data')) hora_inicio = models.TimeField( + null=True, verbose_name=_('Horário de Início (hh:mm)')) hora_fim = models.TimeField( + null=True, verbose_name=_('Horário de Término (hh:mm)')) local_reuniao = models.CharField( max_length=100, blank=True, verbose_name=_('Local da Reunião')) @@ -287,12 +293,13 @@ class Reuniao(models.Model): @reversion.register() class DocumentoAcessorio(models.Model): - reuniao = models.ForeignKey(Reuniao, + reuniao = models.ForeignKey(Reuniao, related_name='documentoacessorio_set', on_delete=models.PROTECT) 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( max_length=100, verbose_name=_('Autor')) ementa = models.TextField(blank=True, verbose_name=_('Ementa')) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index c5870389e..78e639168 100644 --- a/sapl/comissoes/views.py +++ b/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.edit import FormMixin - from sapl.base.models import AppConfig as AppsAppConfig -from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, - CrudAux, MasterDetailCrud, - PermissionRequiredForAppCrudMixin) -from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm, DocumentoAcessorioCreateForm, - DocumentoAcessorioEditForm, ParticipacaoCreateForm, - ParticipacaoEditForm, ReuniaoForm, PeriodoForm) +from sapl.comissoes.apps import AppConfig +from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm, + DocumentoAcessorioCreateForm, + DocumentoAcessorioEditForm, + ParticipacaoCreateForm, ParticipacaoEditForm, + PeriodoForm, ReuniaoForm) +from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, + MasterDetailCrud, + PermissionRequiredForAppCrudMixin) from sapl.materia.models import MateriaLegislativa, Tramitacao - from .models import (CargoComissao, Comissao, Composicao, DocumentoAcessorio, - Participacao, Periodo, TipoComissao, Reuniao) -from sapl.comissoes.apps import AppConfig + Participacao, Periodo, Reuniao, TipoComissao) def pegar_url_composicao(pk): @@ -30,6 +30,7 @@ def pegar_url_composicao(pk): url = reverse('sapl.comissoes:composicao_detail', kwargs={'pk': comp_pk}) return url + def pegar_url_reuniao(pk): documentoacessorio = DocumentoAcessorio.objects.get(id=pk) r_pk = documentoacessorio.reuniao.pk @@ -42,6 +43,7 @@ TipoComissaoCrud = CrudAux.build( TipoComissao, 'tipo_comissao', list_field_names=[ 'sigla', 'nome', 'natureza', 'dispositivo_regimental']) + class PeriodoComposicaoCrud(CrudAux): model = Periodo @@ -77,6 +79,7 @@ class ParticipacaoCrud(MasterDetailCrud): form_class = ParticipacaoEditForm class DeleteView(MasterDetailCrud.DeleteView): + def get_success_url(self): composicao_comissao_pk = self.object.composicao.comissao.pk composicao_pk = self.object.composicao.pk @@ -93,12 +96,11 @@ class ComposicaoCrud(MasterDetailCrud): class CreateView(MasterDetailCrud.CreateView): form_class = ComposicaoForm - + def get_initial(self): comissao = Comissao.objects.get(id=self.kwargs['pk']) return {'comissao': comissao} - class ListView(MasterDetailCrud.ListView): template_name = "comissoes/composicao_list.html" paginate_by = None @@ -180,6 +182,7 @@ class MateriasTramitacaoListView(ListView): context['object'] = Comissao.objects.get(id=self.kwargs['pk']) return context + class ReuniaoCrud(MasterDetailCrud): model = Reuniao parent_field = 'comissao' @@ -187,7 +190,7 @@ class ReuniaoCrud(MasterDetailCrud): public = [RP_LIST, RP_DETAIL, ] class BaseMixin(MasterDetailCrud.BaseMixin): - list_field_names = [ 'nome', 'tema', 'data'] + list_field_names = ['data', 'nome', 'tema'] class ListView(MasterDetailCrud.ListView): paginate_by = 10 @@ -228,9 +231,9 @@ class ReuniaoCrud(MasterDetailCrud): form_class = ReuniaoForm 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): @@ -256,6 +259,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud): form_class = DocumentoAcessorioEditForm class DeleteView(MasterDetailCrud.DeleteView): + def delete(self, *args, **kwargs): obj = self.get_object() obj.delete() diff --git a/sapl/legacy/migracao_dados.py b/sapl/legacy/migracao_dados.py index c6ca892f0..96bb0905f 100644 --- a/sapl/legacy/migracao_dados.py +++ b/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 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.models import NormaJuridica as OldNormaJuridica from sapl.legacy.models import TipoNumeracaoProtocolo @@ -58,6 +58,8 @@ from .timezonesbrasil import get_timezone appconfs = [apps.get_app_config(n) for n in [ 'parlamentares', 'comissoes', + # base precisa vir depois dos apps parlamentares e comissoes + # pois Autor os referencia 'base', 'materia', 'norma', @@ -99,7 +101,7 @@ def get_renames(): model_name, old_name = match.groups() else: old_name = None - model = getattr(app.models_module, model_name) + model = app.get_model(model_name) if old_name: model_renames[model] = old_name field_renames[model] = renames @@ -212,6 +214,10 @@ class ForeignKeyFaltando(ObjectDoesNotExist): 'Uma FK aponta para um registro inexistente' 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.valor = valor self.old = old @@ -1237,6 +1243,17 @@ def adjust_tiporesultadovotacao(new, old): {'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): if 'style' not in conteudo: return conteudo # atalho que acelera muito os casos sem style @@ -1274,6 +1291,7 @@ AJUSTE_ANTES_SALVAR = { Tramitacao: adjust_tramitacao, TipoResultadoVotacao: adjust_tiporesultadovotacao, ExpedienteSessao: adjust_expediente_sessao, + Reuniao: adjust_reuniao_comissao, } AJUSTE_DEPOIS_SALVAR = { diff --git a/sapl/legacy/models.py b/sapl/legacy/models.py index 7d341624d..cd6d433df 100644 --- a/sapl/legacy/models.py +++ b/sapl/legacy/models.py @@ -779,6 +779,20 @@ class Relatoria(models.Model): 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): cod_sessao_leg = models.AutoField(primary_key=True) num_legislatura = models.IntegerField()