Browse Source

Corrigindo problema de nomes iguais ao atualizar arquivo FIX #2891 (#2892)

* Corrigindo problema de nomes iguais ao atualizar arquivo FIX #2891

* Subindo Migrations
pull/2758/head
Ulysses Lara 5 years ago
committed by Cesar Carvalho
parent
commit
2f62b1dd06
  1. 37
      sapl/audiencia/migrations/0011_auto_20190712_1053.py
  2. 7
      sapl/audiencia/models.py
  3. 37
      sapl/comissoes/migrations/0020_auto_20190712_1053.py
  4. 7
      sapl/comissoes/models.py
  5. 32
      sapl/materia/migrations/0052_auto_20190712_1053.py
  6. 6
      sapl/materia/models.py
  7. 27
      sapl/norma/migrations/0026_auto_20190712_1053.py
  8. 5
      sapl/norma/models.py
  9. 26
      sapl/protocoloadm/migrations/0022_auto_20190712_1053.py
  10. 5
      sapl/protocoloadm/models.py
  11. 52
      sapl/sessao/migrations/0043_auto_20190712_1053.py
  12. 8
      sapl/sessao/models.py
  13. 14
      sapl/utils.py

37
sapl/audiencia/migrations/0011_auto_20190712_1053.py

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-12 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import sapl.audiencia.models
import sapl.utils
class Migration(migrations.Migration):
dependencies = [
('audiencia', '0010_auto_20190219_1511'),
]
operations = [
migrations.AlterField(
model_name='anexoaudienciapublica',
name='arquivo',
field=models.FileField(storage=sapl.utils.OverwriteStorage(), upload_to=sapl.utils.texto_upload_path, verbose_name='Arquivo'),
),
migrations.AlterField(
model_name='audienciapublica',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.audiencia.models.anexo_upload_path, verbose_name='Anexo da Audiência Pública'),
),
migrations.AlterField(
model_name='audienciapublica',
name='upload_ata',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.audiencia.models.ata_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Ata da Audiência Pública'),
),
migrations.AlterField(
model_name='audienciapublica',
name='upload_pauta',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.audiencia.models.pauta_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Pauta da Audiência Pública'),
),
]

7
sapl/audiencia/models.py

@ -7,7 +7,8 @@ from sapl.materia.models import MateriaLegislativa
from sapl.parlamentares.models import (CargoMesa, Parlamentar) from sapl.parlamentares.models import (CargoMesa, Parlamentar)
from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation, from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation,
restringe_tipos_de_arquivo_txt, texto_upload_path) restringe_tipos_de_arquivo_txt, texto_upload_path,
OverwriteStorage)
def get_audiencia_media_path(instance, subpath, filename): def get_audiencia_media_path(instance, subpath, filename):
@ -89,6 +90,7 @@ class AudienciaPublica(models.Model):
blank=True, blank=True,
null=True, null=True,
upload_to=pauta_upload_path, upload_to=pauta_upload_path,
storage=OverwriteStorage(),
verbose_name=_('Pauta da Audiência Pública'), verbose_name=_('Pauta da Audiência Pública'),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
upload_ata = models.FileField( upload_ata = models.FileField(
@ -96,11 +98,13 @@ class AudienciaPublica(models.Model):
null=True, null=True,
upload_to=ata_upload_path, upload_to=ata_upload_path,
verbose_name=_('Ata da Audiência Pública'), verbose_name=_('Ata da Audiência Pública'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
upload_anexo = models.FileField( upload_anexo = models.FileField(
blank=True, blank=True,
null=True, null=True,
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
storage=OverwriteStorage(),
verbose_name=_('Anexo da Audiência Pública')) verbose_name=_('Anexo da Audiência Pública'))
class Meta: class Meta:
@ -156,6 +160,7 @@ class AnexoAudienciaPublica(models.Model):
on_delete=models.PROTECT) on_delete=models.PROTECT)
arquivo = models.FileField( arquivo = models.FileField(
upload_to=texto_upload_path, upload_to=texto_upload_path,
storage=OverwriteStorage(),
verbose_name=_('Arquivo')) verbose_name=_('Arquivo'))
data = models.DateField( data = models.DateField(
auto_now=timezone.now) auto_now=timezone.now)

37
sapl/comissoes/migrations/0020_auto_20190712_1053.py

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-12 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import sapl.comissoes.models
import sapl.utils
class Migration(migrations.Migration):
dependencies = [
('comissoes', '0019_auto_20181214_1023'),
]
operations = [
migrations.AlterField(
model_name='documentoacessorio',
name='arquivo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.comissoes.models.anexo_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Integral'),
),
migrations.AlterField(
model_name='reuniao',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.comissoes.models.anexo_upload_path, verbose_name='Anexo da Reunião'),
),
migrations.AlterField(
model_name='reuniao',
name='upload_ata',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.comissoes.models.ata_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Ata da Reunião'),
),
migrations.AlterField(
model_name='reuniao',
name='upload_pauta',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.comissoes.models.pauta_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Pauta da Reunião'),
),
]

7
sapl/comissoes/models.py

@ -6,7 +6,8 @@ from model_utils import Choices
from sapl.base.models import Autor from sapl.base.models import Autor
from sapl.parlamentares.models import Parlamentar from sapl.parlamentares.models import Parlamentar
from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation, from sapl.utils import (YES_NO_CHOICES, SaplGenericRelation,
restringe_tipos_de_arquivo_txt, texto_upload_path) restringe_tipos_de_arquivo_txt, texto_upload_path,
OverwriteStorage)
@reversion.register() @reversion.register()
@ -238,15 +239,18 @@ class Reuniao(models.Model):
blank=True, null=True, blank=True, null=True,
upload_to=pauta_upload_path, upload_to=pauta_upload_path,
verbose_name=_('Pauta da Reunião'), verbose_name=_('Pauta da Reunião'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
upload_ata = models.FileField( upload_ata = models.FileField(
blank=True, null=True, blank=True, null=True,
upload_to=ata_upload_path, upload_to=ata_upload_path,
verbose_name=_('Ata da Reunião'), verbose_name=_('Ata da Reunião'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
upload_anexo = models.FileField( upload_anexo = models.FileField(
blank=True, null=True, blank=True, null=True,
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
storage=OverwriteStorage(),
verbose_name=_('Anexo da Reunião')) verbose_name=_('Anexo da Reunião'))
class Meta: class Meta:
@ -313,6 +317,7 @@ class DocumentoAcessorio(models.Model):
null=True, null=True,
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
verbose_name=_('Texto Integral'), verbose_name=_('Texto Integral'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
data_ultima_atualizacao = models.DateTimeField( data_ultima_atualizacao = models.DateTimeField(

32
sapl/materia/migrations/0052_auto_20190712_1053.py

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-12 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import sapl.materia.models
import sapl.utils
class Migration(migrations.Migration):
dependencies = [
('materia', '0051_auto_20190703_1414'),
]
operations = [
migrations.AlterField(
model_name='documentoacessorio',
name='arquivo',
field=models.FileField(blank=True, max_length=255, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.materia.models.anexo_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Integral'),
),
migrations.AlterField(
model_name='materialegislativa',
name='texto_original',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.materia.models.materia_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Original'),
),
migrations.AlterField(
model_name='proposicao',
name='texto_original',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.materia.models.materia_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Original'),
),
]

6
sapl/materia/models.py

@ -18,7 +18,8 @@ from sapl.parlamentares.models import Parlamentar
#from sapl.protocoloadm.models import Protocolo #from sapl.protocoloadm.models import Protocolo
from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, SaplGenericForeignKey, from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, SaplGenericForeignKey,
SaplGenericRelation, restringe_tipos_de_arquivo_txt, SaplGenericRelation, restringe_tipos_de_arquivo_txt,
texto_upload_path, get_settings_auth_user_model) texto_upload_path, get_settings_auth_user_model,
OverwriteStorage)
EM_TRAMITACAO = [(1, 'Sim'), EM_TRAMITACAO = [(1, 'Sim'),
@ -260,6 +261,7 @@ class MateriaLegislativa(models.Model):
null=True, null=True,
upload_to=materia_upload_path, upload_to=materia_upload_path,
verbose_name=_('Texto Original'), verbose_name=_('Texto Original'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
texto_articulado = GenericRelation( texto_articulado = GenericRelation(
@ -538,6 +540,7 @@ class DocumentoAcessorio(models.Model):
max_length=255, max_length=255,
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
verbose_name=_('Texto Integral'), verbose_name=_('Texto Integral'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
proposicao = GenericRelation( proposicao = GenericRelation(
@ -801,6 +804,7 @@ class Proposicao(models.Model):
blank=True, blank=True,
null=True, null=True,
verbose_name=_('Texto Original'), verbose_name=_('Texto Original'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
texto_articulado = GenericRelation( texto_articulado = GenericRelation(

27
sapl/norma/migrations/0026_auto_20190712_1053.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-12 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import sapl.norma.models
import sapl.utils
class Migration(migrations.Migration):
dependencies = [
('norma', '0025_auto_20190704_1403'),
]
operations = [
migrations.AlterField(
model_name='anexonormajuridica',
name='anexo_arquivo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.norma.models.norma_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Arquivo Anexo'),
),
migrations.AlterField(
model_name='normajuridica',
name='texto_integral',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.norma.models.norma_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Integral'),
),
]

5
sapl/norma/models.py

@ -12,7 +12,8 @@ from sapl.materia.models import MateriaLegislativa
from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES,
restringe_tipos_de_arquivo_txt, restringe_tipos_de_arquivo_txt,
texto_upload_path, texto_upload_path,
get_settings_auth_user_model) get_settings_auth_user_model,
OverwriteStorage)
@reversion.register() @reversion.register()
@ -82,6 +83,7 @@ class NormaJuridica(models.Model):
null=True, null=True,
upload_to=norma_upload_path, upload_to=norma_upload_path,
verbose_name=_('Texto Integral'), verbose_name=_('Texto Integral'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
tipo = models.ForeignKey( tipo = models.ForeignKey(
TipoNormaJuridica, TipoNormaJuridica,
@ -363,6 +365,7 @@ class AnexoNormaJuridica(models.Model):
null=True, null=True,
upload_to=norma_upload_path, upload_to=norma_upload_path,
verbose_name=_('Arquivo Anexo'), verbose_name=_('Arquivo Anexo'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'), ano = models.PositiveSmallIntegerField(verbose_name=_('Ano'),
choices=RANGE_ANOS) choices=RANGE_ANOS)

26
sapl/protocoloadm/migrations/0022_auto_20190712_1053.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-12 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import sapl.utils
class Migration(migrations.Migration):
dependencies = [
('protocoloadm', '0021_merge_20190429_1531'),
]
operations = [
migrations.AlterField(
model_name='documentoacessorioadministrativo',
name='arquivo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.utils.texto_upload_path, verbose_name='Arquivo'),
),
migrations.AlterField(
model_name='documentoadministrativo',
name='texto_integral',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.utils.texto_upload_path, verbose_name='Texto Integral'),
),
]

5
sapl/protocoloadm/models.py

@ -7,7 +7,8 @@ import reversion
from sapl.base.models import Autor from sapl.base.models import Autor
from sapl.materia.models import TipoMateriaLegislativa, UnidadeTramitacao from sapl.materia.models import TipoMateriaLegislativa, UnidadeTramitacao
from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, texto_upload_path, from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, texto_upload_path,
get_settings_auth_user_model) get_settings_auth_user_model,
OverwriteStorage)
@reversion.register() @reversion.register()
@ -164,6 +165,7 @@ class DocumentoAdministrativo(models.Model):
texto_integral = models.FileField( texto_integral = models.FileField(
blank=True, blank=True,
null=True, null=True,
storage=OverwriteStorage(),
upload_to=texto_upload_path, upload_to=texto_upload_path,
verbose_name=_('Texto Integral')) verbose_name=_('Texto Integral'))
restrito = models.BooleanField(default=False, restrito = models.BooleanField(default=False,
@ -229,6 +231,7 @@ class DocumentoAcessorioAdministrativo(models.Model):
blank=True, blank=True,
null=True, null=True,
upload_to=texto_upload_path, upload_to=texto_upload_path,
storage=OverwriteStorage(),
verbose_name=_('Arquivo')) verbose_name=_('Arquivo'))
data = models.DateField(blank=True, null=True, verbose_name=_('Data')) data = models.DateField(blank=True, null=True, verbose_name=_('Data'))
autor = models.CharField( autor = models.CharField(

52
sapl/sessao/migrations/0043_auto_20190712_1053.py

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-07-12 13:53
from __future__ import unicode_literals
from django.db import migrations, models
import sapl.sessao.models
import sapl.utils
class Migration(migrations.Migration):
dependencies = [
('sessao', '0042_merge_20190612_0925'),
]
operations = [
migrations.AlterField(
model_name='justificativaausencia',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.anexo_upload_path, verbose_name='Anexo de Justificativa'),
),
migrations.AlterField(
model_name='orador',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.anexo_upload_path, verbose_name='Anexo do Orador'),
),
migrations.AlterField(
model_name='oradorexpediente',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.anexo_upload_path, verbose_name='Anexo do Orador'),
),
migrations.AlterField(
model_name='oradorordemdia',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.anexo_upload_path, verbose_name='Anexo do Orador'),
),
migrations.AlterField(
model_name='sessaoplenaria',
name='upload_anexo',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.anexo_upload_path, verbose_name='Anexo da Sessão'),
),
migrations.AlterField(
model_name='sessaoplenaria',
name='upload_ata',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.ata_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Ata da Sessão'),
),
migrations.AlterField(
model_name='sessaoplenaria',
name='upload_pauta',
field=models.FileField(blank=True, null=True, storage=sapl.utils.OverwriteStorage(), upload_to=sapl.sessao.models.pauta_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Pauta da Sessão'),
),
]

8
sapl/sessao/models.py

@ -14,7 +14,8 @@ 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,
get_settings_auth_user_model, get_settings_auth_user_model,
restringe_tipos_de_arquivo_txt, texto_upload_path) restringe_tipos_de_arquivo_txt, texto_upload_path,
OverwriteStorage)
@reversion.register() @reversion.register()
@ -130,16 +131,19 @@ class SessaoPlenaria(models.Model):
null=True, null=True,
upload_to=pauta_upload_path, upload_to=pauta_upload_path,
verbose_name=_('Pauta da Sessão'), verbose_name=_('Pauta da Sessão'),
storage=OverwriteStorage(),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
upload_ata = models.FileField( upload_ata = models.FileField(
blank=True, blank=True,
null=True, null=True,
upload_to=ata_upload_path, upload_to=ata_upload_path,
storage=OverwriteStorage(),
verbose_name=_('Ata da Sessão'), verbose_name=_('Ata da Sessão'),
validators=[restringe_tipos_de_arquivo_txt]) validators=[restringe_tipos_de_arquivo_txt])
upload_anexo = models.FileField( upload_anexo = models.FileField(
blank=True, blank=True,
null=True, null=True,
storage=OverwriteStorage(),
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
verbose_name=_('Anexo da Sessão')) verbose_name=_('Anexo da Sessão'))
iniciada = models.NullBooleanField(blank=True, iniciada = models.NullBooleanField(blank=True,
@ -366,6 +370,7 @@ class AbstractOrador(models.Model): # Oradores
upload_anexo = models.FileField( upload_anexo = models.FileField(
blank=True, blank=True,
null=True, null=True,
storage=OverwriteStorage(),
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
verbose_name=_('Anexo do Orador')) verbose_name=_('Anexo do Orador'))
@ -708,6 +713,7 @@ class JustificativaAusencia(models.Model):
upload_anexo = models.FileField( upload_anexo = models.FileField(
blank=True, blank=True,
null=True, null=True,
storage=OverwriteStorage(),
upload_to=anexo_upload_path, upload_to=anexo_upload_path,
verbose_name=_('Anexo de Justificativa')) verbose_name=_('Anexo de Justificativa'))

14
sapl/utils.py

@ -23,6 +23,7 @@ from django.forms.widgets import SplitDateTimeWidget
from django.utils import six, timezone from django.utils import six, timezone
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.files.storage import FileSystemStorage
import django_filters import django_filters
from easy_thumbnails import source_generators from easy_thumbnails import source_generators
from floppyforms import ClearableFileInput from floppyforms import ClearableFileInput
@ -984,3 +985,16 @@ def lista_anexados(principal, isMateriaLegislativa=True):
if principal in anexados_total: if principal in anexados_total:
anexados_total.remove(principal) anexados_total.remove(principal)
return anexados_total return anexados_total
class OverwriteStorage(FileSystemStorage):
'''
Solução derivada do gist: https://gist.github.com/fabiomontefuscolo/1584462
Muda o comportamento padrão do Django e o faz sobrescrever arquivos de
mesmo nome que foram carregados pelo usuário ao invés de renomeá-los.
'''
def get_available_name(self, name, max_length=None):
if self.exists(name):
os.remove(os.path.join(settings.MEDIA_ROOT, name))
return name
Loading…
Cancel
Save