<commit_before>import datetime

from django.db import models
from django.utils.text import slugify
from django.contrib.contenttypes.fields import GenericRelation

from gestao.models import Diligencia

SITUACAO_CONSELHEIRO = (
    ('1', 'Habilitado'),
    ('0', 'Desabilitado')
    )


def upload_to_componente(instance, filename):
    ext = slugify(filename.split('.').pop(-1))
    new_name = slugify(filename.rsplit('.', 1)[0])
    entefederado = instance.planotrabalho.usuario.municipio.id
    componente = instance._meta.object_name.lower()
    return "{entefederado}/docs/{componente}/{new_name}.{ext}".format(
        entefederado=entefederado,
        componente=componente,
        new_name=new_name,
        ext=ext)


class ArquivoComponente(models.Model):
    arquivo = models.FileField(upload_to=upload_to_componente, null=True, blank=True)
    situacao = models.ForeignKey('SituacoesArquivoPlano', related_name='%(class)s_situacao', default=0)
    data_envio = models.DateField(default=datetime.date.today)

    class Meta:
        abstract = True


class PlanoTrabalho(models.Model):
    criacao_sistema = models.OneToOneField(
        'CriacaoSistema',
        blank=True,
        null=True)
    orgao_gestor = models.OneToOneField(
        'OrgaoGestor',
        blank=True,
        null=True)
    conselho_cultural = models.OneToOneField(
        'ConselhoCultural',
        blank=True,
        null=True)
    fundo_cultura = models.OneToOneField(
        'FundoCultura',
        blank=True,
        null=True)
    plano_cultura = models.OneToOneField(
        'PlanoCultura',
        blank=True,
        null=True)

    def __str__(self):
        return str(self.id)


class CriacaoSistema(ArquivoComponente):
    minuta_projeto_lei = models.FileField(
        upload_to='minuta_lei',
        max_length=255,
        blank=True,
        null=True)
    lei_sistema_cultura = models.FileField(
        upload_to='leis_sistema_cultura',
        max_length=255,
        blank=True,
        null=True)
    diligencias = GenericRelation(Diligencia, content_type_field="componente_type",
                                  object_id_field="componente_id")<commit_msg>[UPDATE] Adiciona relação para diligencias no plano_trabalho<commit_after>import datetime

from django.db import models
from django.utils.text import slugify
from django.contrib.contenttypes.fields import GenericRelation

from gestao.models import Diligencia

SITUACAO_CONSELHEIRO = (
    ('1', 'Habilitado'),
    ('0', 'Desabilitado')
    )


def upload_to_componente(instance, filename):
    ext = slugify(filename.split('.').pop(-1))
    new_name = slugify(filename.rsplit('.', 1)[0])
    entefederado = instance.planotrabalho.usuario.municipio.id
    componente = instance._meta.object_name.lower()
    return "{entefederado}/docs/{componente}/{new_name}.{ext}".format(
        entefederado=entefederado,
        componente=componente,
        new_name=new_name,
        ext=ext)


class ArquivoComponente(models.Model):
    arquivo = models.FileField(upload_to=upload_to_componente, null=True, blank=True)
    situacao = models.ForeignKey('SituacoesArquivoPlano', related_name='%(class)s_situacao', default=0)
    data_envio = models.DateField(default=datetime.date.today)

    class Meta:
        abstract = True


class PlanoTrabalho(models.Model):
    criacao_sistema = models.OneToOneField(
        'CriacaoSistema',
        blank=True,
        null=True)
    orgao_gestor = models.OneToOneField(
        'OrgaoGestor',
        blank=True,
        null=True)
    conselho_cultural = models.OneToOneField(
        'ConselhoCultural',
        blank=True,
        null=True)
    fundo_cultura = models.OneToOneField(
        'FundoCultura',
        blank=True,
        null=True)
    plano_cultura = models.OneToOneField(
        'PlanoCultura',
        blank=True,
        null=True)
    diligencias = GenericRelation(Diligencia, content_type_field="componente_type",
                                  object_id_field="componente_id")

    def __str__(self):
        return str(self.id)


class CriacaoSistema(ArquivoComponente):
    minuta_projeto_lei = models.FileField(
        upload_to='minuta_lei',
        max_length=255,
        blank=True,
        null=True)
    lei_sistema_cultura = models.FileField(
        upload_to='leis_sistema_cultura',
        max_length=255,
        blank=True,
        null=True)
    diligencias = GenericRelation(Diligencia, content_type_field="componente_type",
                                  object_id_field="componente_id")
{'fraction_non_alphanumeric': 0.10351648351648352, 'fraction_numerical': 0.005274725274725275, 'mean_word_length': 3.1222826086956523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4085215', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1517, 'n_words': 221}