From 03235f1db10f2e5922663f71e75468cc05e3fd49 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Mon, 12 Jun 2017 11:39:03 -0300 Subject: [PATCH] Fix #1186 --- sapl/materia/models.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 032ce3253..557273136 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -1,6 +1,5 @@ from datetime import datetime -import reversion from django.contrib.auth.models import Group from django.contrib.contenttypes.fields import GenericRelation from django.contrib.contenttypes.models import ContentType @@ -9,6 +8,7 @@ from django.db import models from django.utils import formats from django.utils.translation import ugettext_lazy as _ from model_utils import Choices +import reversion from sapl.base.models import Autor from sapl.comissoes.models import Comissao @@ -19,9 +19,11 @@ from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, SaplGenericForeignKey, SaplGenericRelation, restringe_tipos_de_arquivo_txt, texto_upload_path) + EM_TRAMITACAO = [(1, 'Sim'), (0, 'Não')] + def grupo_autor(): try: grupo = Group.objects.get(name='Autor') @@ -29,6 +31,7 @@ def grupo_autor(): return None return grupo.id + @reversion.register() class TipoProposicao(models.Model): descricao = models.CharField(max_length=50, verbose_name=_('Descrição')) @@ -118,11 +121,14 @@ class Origem(models.Model): TIPO_APRESENTACAO_CHOICES = Choices(('O', 'oral', _('Oral')), ('E', 'escrita', _('Escrita'))) + def materia_upload_path(instance, filename): - return texto_upload_path(instance, filename, subpath=instance.ano) + return texto_upload_path(instance, filename, subpath=instance.ano) + def anexo_upload_path(instance, filename): - return texto_upload_path(instance, filename, subpath=instance.materia.ano) + return texto_upload_path(instance, filename, subpath=instance.materia.ano) + @reversion.register() class MateriaLegislativa(models.Model): @@ -204,6 +210,9 @@ class MateriaLegislativa(models.Model): texto_articulado = GenericRelation( TextoArticulado, related_query_name='texto_articulado') + proposicao = GenericRelation( + 'Proposicao', related_query_name='proposicao') + autores = models.ManyToManyField( Autor, through='Autoria', @@ -219,7 +228,6 @@ class MateriaLegislativa(models.Model): return _('%(tipo)s nº %(numero)s de %(ano)s') % { 'tipo': self.tipo, 'numero': self.numero, 'ano': self.ano} - def data_entrada_protocolo(self): ''' hack: recuperar a data de entrada do protocolo sem gerar @@ -240,6 +248,12 @@ class MateriaLegislativa(models.Model): if self.texto_original: self.texto_original.delete() + proposicao = self.proposicao.all() + if proposicao: + for p in proposicao: + p.conteudo_gerado_related = None + p.save() + return models.Model.delete( self, using=using, keep_parents=keep_parents) @@ -400,6 +414,9 @@ class DocumentoAcessorio(models.Model): verbose_name=_('Texto Integral'), validators=[restringe_tipos_de_arquivo_txt]) + proposicao = GenericRelation( + 'Proposicao', related_query_name='proposicao') + class Meta: verbose_name = _('Documento Acessório') verbose_name_plural = _('Documentos Acessórios') @@ -415,6 +432,12 @@ class DocumentoAcessorio(models.Model): if self.arquivo: self.arquivo.delete() + proposicao = self.proposicao.all() + if proposicao: + for p in proposicao: + p.conteudo_gerado_related = None + p.save() + return models.Model.delete( self, using=using, keep_parents=keep_parents)